Fix: Update pax if changed
Fix: Tax was associated with inventory, not just tax_id so that if along with adding an inventory, the bill is printed then it can be used to get regime information. Chore: Refactored checking for nil inventory and kots.
This commit is contained in:
parent
1297a4e7d2
commit
7a8017087b
@ -56,11 +56,11 @@ def update_route(
|
||||
voucher_type = VoucherType(p)
|
||||
guest_book = get_guest_book(g, db)
|
||||
need_to_print_kot = False
|
||||
|
||||
item: Voucher = db.execute(select(Voucher).where(Voucher.id == id_)).scalar_one()
|
||||
|
||||
check_permissions(item, voucher_type, user.permissions)
|
||||
|
||||
item.pax = data.pax
|
||||
if guest_book is not None:
|
||||
item.pax = guest_book.pax
|
||||
item.food_table_id = data.table.id_
|
||||
@ -91,6 +91,11 @@ def update_route(
|
||||
iki.discount = next(
|
||||
round(inv.discount, 5) for ko in data.kots for inv in ko.inventories if inv.id_ == iki.id
|
||||
)
|
||||
for dk in data.kots:
|
||||
# Filter out nil inventories
|
||||
dk.inventories = [dki for dki in dk.inventories if round(dki.quantity, 2) != 0]
|
||||
# Filter out nil kots
|
||||
data.kots = [k for k in data.kots if len(k.inventories) > 0]
|
||||
for dk in data.kots:
|
||||
if happy_hour_has_discount(dk.inventories):
|
||||
raise HTTPException(
|
||||
@ -102,19 +107,15 @@ def update_route(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
detail="Happy hour products are not balanced.",
|
||||
)
|
||||
for nk in (
|
||||
dk
|
||||
for dk in data.kots
|
||||
if dk.id_ is None and len([dki for dki in dk.inventories if round(dki.quantity, 2) != 0]) > 0
|
||||
):
|
||||
for nk in data.kots:
|
||||
if nk.id_ is not None:
|
||||
continue
|
||||
need_to_print_kot = True
|
||||
code = db.execute(select(func.coalesce(func.max(Kot.code), 0) + 1)).scalar_one()
|
||||
kot = Kot(item.id, code, item.food_table_id, now, item.user_id)
|
||||
item.kots.append(kot)
|
||||
db.add(kot)
|
||||
for index, nki in enumerate(nk.inventories):
|
||||
if round(nki.quantity, 2) == 0:
|
||||
continue
|
||||
product: ProductVersion = db.execute(
|
||||
select(ProductVersion).where(
|
||||
and_(
|
||||
@ -156,15 +157,15 @@ def update_route(
|
||||
)
|
||||
tax_rate = get_tax(product.sale_category.tax.rate, voucher_type)
|
||||
inv = Inventory(
|
||||
kot.id,
|
||||
product.product_id,
|
||||
round(nki.quantity, 2),
|
||||
product.price,
|
||||
round(min(nki.discount, product.sale_category.discount_limit), 5),
|
||||
nki.is_happy_hour,
|
||||
product.sale_category.tax_id,
|
||||
tax_rate,
|
||||
index,
|
||||
kot_id=kot.id,
|
||||
product_id=product.product_id,
|
||||
quantity=round(nki.quantity, 2),
|
||||
price=product.price,
|
||||
discount=round(min(nki.discount, product.sale_category.discount_limit), 5),
|
||||
is_hh=nki.is_happy_hour,
|
||||
tax_rate=tax_rate,
|
||||
sort_order=index,
|
||||
tax=product.sale_category.tax,
|
||||
)
|
||||
kot.inventories.append(inv)
|
||||
db.add(inv)
|
||||
|
Loading…
Reference in New Issue
Block a user