Fix: Batch autocomplete would bork on empty string as it would try to split Null
v8.0.1
This commit is contained in:
@ -1 +1 @@
|
||||
__version__ = "8.0.0"
|
||||
__version__ = "8.0.1"
|
||||
|
||||
@ -109,15 +109,15 @@ class Product(Base):
|
||||
|
||||
@classmethod
|
||||
def query(cls, q, is_purchased=None, active=None, db=None):
|
||||
query_ = db.query(Product)
|
||||
query_ = db.query(cls)
|
||||
if active is not None:
|
||||
query_ = query_.filter(Product.is_active == active)
|
||||
query_ = query_.filter(cls.is_active == active)
|
||||
if is_purchased is not None:
|
||||
query_ = query_.filter(Product.is_purchased == is_purchased)
|
||||
query_ = query_.filter(cls.is_purchased == is_purchased)
|
||||
if q is not None:
|
||||
for item in q.split():
|
||||
if item.strip() != "":
|
||||
query_ = query_.filter(Product.name.ilike("%" + item + "%"))
|
||||
query_ = query_.filter(cls.name.ilike(f"%{item}%"))
|
||||
return query_
|
||||
|
||||
@classmethod
|
||||
@ -326,7 +326,7 @@ class AccountBase(Base):
|
||||
query_ = query_.filter(cls.is_active == active)
|
||||
if q is not None:
|
||||
for item in q.split():
|
||||
query_ = query_.filter(cls.name.ilike("%" + item + "%"))
|
||||
query_ = query_.filter(cls.name.ilike(f"%{item}%"))
|
||||
return query_.order_by(cls.name)
|
||||
|
||||
def create(self, db: Session):
|
||||
|
||||
@ -391,14 +391,15 @@ class Batch(Base):
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def list(cls, name, include_nil, date, db: Session):
|
||||
query = db.query(Batch).join(Batch.product)
|
||||
def list(cls, q, include_nil, date, db: Session):
|
||||
query = db.query(cls).join(cls.product)
|
||||
if not include_nil:
|
||||
query = query.filter(cls.quantity_remaining > 0)
|
||||
if date is not None:
|
||||
query = query.filter(cls.name <= date)
|
||||
for item in name.split():
|
||||
query = query.filter(Product.name.ilike(f"%{item}%"))
|
||||
if q is not None:
|
||||
for item in q.split():
|
||||
query = query.filter(cls.name.ilike(f"%{item}%"))
|
||||
return query.order_by(Product.name).order_by(cls.name).all()
|
||||
|
||||
@classmethod
|
||||
|
||||
@ -152,7 +152,6 @@ async def show_term(
|
||||
current_user: UserToken = Depends(get_user),
|
||||
):
|
||||
count = c
|
||||
|
||||
list_ = []
|
||||
for index, item in enumerate(AccountBase.query(q, t, r, a, db)):
|
||||
list_.append({"id": item.id, "name": item.name})
|
||||
|
||||
@ -29,12 +29,9 @@ def batch_term(
|
||||
db: Session = Depends(get_db),
|
||||
current_user: UserToken = Depends(get_user),
|
||||
):
|
||||
filter_ = q if q is not None and q.strip() != "" else None
|
||||
date = None if not d else datetime.datetime.strptime(d, "%d-%b-%Y")
|
||||
list_ = []
|
||||
for index, item in enumerate(
|
||||
Batch.list(filter_, include_nil=False, date=date, db=db)
|
||||
):
|
||||
for index, item in enumerate(Batch.list(q, include_nil=False, date=date, db=db)):
|
||||
text = f"{item.product.name} ({item.product.units}) {item.quantity_remaining:.2f}@{item.rate:.2f} from {item.name.strftime('%d-%b-%Y')}"
|
||||
list_.append(
|
||||
{
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
[tool.poetry]
|
||||
name = "brewman"
|
||||
version = "8.0.0"
|
||||
version = "8.0.1"
|
||||
description = "Accounting plus inventory management for a restaurant."
|
||||
authors = ["tanshu <git@tanshu.com>"]
|
||||
|
||||
@ -41,7 +41,6 @@ skip_glob = ["*/setup.py"]
|
||||
filter_files = true
|
||||
known_first_party = "poetry"
|
||||
|
||||
|
||||
[tool.black]
|
||||
line-length = 88
|
||||
include = '\.pyi?$'
|
||||
|
||||
Reference in New Issue
Block a user