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)
|
voucher_type = VoucherType(p)
|
||||||
guest_book = get_guest_book(g, db)
|
guest_book = get_guest_book(g, db)
|
||||||
need_to_print_kot = False
|
need_to_print_kot = False
|
||||||
|
|
||||||
item: Voucher = db.execute(select(Voucher).where(Voucher.id == id_)).scalar_one()
|
item: Voucher = db.execute(select(Voucher).where(Voucher.id == id_)).scalar_one()
|
||||||
|
|
||||||
check_permissions(item, voucher_type, user.permissions)
|
check_permissions(item, voucher_type, user.permissions)
|
||||||
|
|
||||||
|
item.pax = data.pax
|
||||||
if guest_book is not None:
|
if guest_book is not None:
|
||||||
item.pax = guest_book.pax
|
item.pax = guest_book.pax
|
||||||
item.food_table_id = data.table.id_
|
item.food_table_id = data.table.id_
|
||||||
|
@ -91,6 +91,11 @@ def update_route(
|
||||||
iki.discount = next(
|
iki.discount = next(
|
||||||
round(inv.discount, 5) for ko in data.kots for inv in ko.inventories if inv.id_ == iki.id
|
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:
|
for dk in data.kots:
|
||||||
if happy_hour_has_discount(dk.inventories):
|
if happy_hour_has_discount(dk.inventories):
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
@ -102,19 +107,15 @@ def update_route(
|
||||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||||
detail="Happy hour products are not balanced.",
|
detail="Happy hour products are not balanced.",
|
||||||
)
|
)
|
||||||
for nk in (
|
for nk in data.kots:
|
||||||
dk
|
if nk.id_ is not None:
|
||||||
for dk in data.kots
|
continue
|
||||||
if dk.id_ is None and len([dki for dki in dk.inventories if round(dki.quantity, 2) != 0]) > 0
|
|
||||||
):
|
|
||||||
need_to_print_kot = True
|
need_to_print_kot = True
|
||||||
code = db.execute(select(func.coalesce(func.max(Kot.code), 0) + 1)).scalar_one()
|
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)
|
kot = Kot(item.id, code, item.food_table_id, now, item.user_id)
|
||||||
item.kots.append(kot)
|
item.kots.append(kot)
|
||||||
db.add(kot)
|
db.add(kot)
|
||||||
for index, nki in enumerate(nk.inventories):
|
for index, nki in enumerate(nk.inventories):
|
||||||
if round(nki.quantity, 2) == 0:
|
|
||||||
continue
|
|
||||||
product: ProductVersion = db.execute(
|
product: ProductVersion = db.execute(
|
||||||
select(ProductVersion).where(
|
select(ProductVersion).where(
|
||||||
and_(
|
and_(
|
||||||
|
@ -156,15 +157,15 @@ def update_route(
|
||||||
)
|
)
|
||||||
tax_rate = get_tax(product.sale_category.tax.rate, voucher_type)
|
tax_rate = get_tax(product.sale_category.tax.rate, voucher_type)
|
||||||
inv = Inventory(
|
inv = Inventory(
|
||||||
kot.id,
|
kot_id=kot.id,
|
||||||
product.product_id,
|
product_id=product.product_id,
|
||||||
round(nki.quantity, 2),
|
quantity=round(nki.quantity, 2),
|
||||||
product.price,
|
price=product.price,
|
||||||
round(min(nki.discount, product.sale_category.discount_limit), 5),
|
discount=round(min(nki.discount, product.sale_category.discount_limit), 5),
|
||||||
nki.is_happy_hour,
|
is_hh=nki.is_happy_hour,
|
||||||
product.sale_category.tax_id,
|
tax_rate=tax_rate,
|
||||||
tax_rate,
|
sort_order=index,
|
||||||
index,
|
tax=product.sale_category.tax,
|
||||||
)
|
)
|
||||||
kot.inventories.append(inv)
|
kot.inventories.append(inv)
|
||||||
db.add(inv)
|
db.add(inv)
|
||||||
|
|
Loading…
Reference in New Issue