Fix: Edge cases where rounding due to changed quantities in printing was altering the final amount in decimals, at times resulted in final rounding to change up or down.
This commit is contained in:
parent
8c5d941850
commit
c2483ae321
@ -52,16 +52,24 @@ class Inventory(Base):
|
||||
tax_id,
|
||||
tax_rate,
|
||||
sort_order,
|
||||
product=None,
|
||||
tax=None,
|
||||
):
|
||||
self.kot_id = kot_id
|
||||
self.product_id = product_id
|
||||
if product_id is not None:
|
||||
self.product_id = product_id
|
||||
self.quantity = quantity
|
||||
self.price = price
|
||||
self.discount = discount
|
||||
self.is_happy_hour = is_hh
|
||||
self.tax_id = tax_id
|
||||
if tax_id is not None:
|
||||
self.tax_id = tax_id
|
||||
self.tax_rate = tax_rate
|
||||
self.sort_order = sort_order
|
||||
if product is not None:
|
||||
self.product = product
|
||||
if tax is not None:
|
||||
self.tax = tax
|
||||
|
||||
@hybrid_property
|
||||
def effective_price(self):
|
||||
|
@ -45,9 +45,20 @@ def print_bill(voucher_id: uuid.UUID, db: Session):
|
||||
)
|
||||
if key in items_dict:
|
||||
items_dict[key].quantity += i.quantity
|
||||
i.quantity = 0
|
||||
else:
|
||||
items_dict[key] = i
|
||||
items_dict[key] = Inventory(
|
||||
None,
|
||||
i.product_id,
|
||||
i.quantity,
|
||||
i.price,
|
||||
i.discount,
|
||||
i.is_happy_hour,
|
||||
None,
|
||||
i.tax_rate,
|
||||
0,
|
||||
i.product,
|
||||
i.tax,
|
||||
)
|
||||
|
||||
for i in [it for it in items_dict.values() if it.quantity != 0]:
|
||||
get_tax_item(i.tax.id, i.tax.name, i.tax_amount, tax)
|
||||
@ -132,14 +143,14 @@ def design_bill(
|
||||
s += "\n\r" + "------------------------------------------"
|
||||
|
||||
# Totals
|
||||
amount = sum(i.quantity * i.price for i in items)
|
||||
amount = sum(round(i.quantity * i.price, 2) for i in items)
|
||||
s += f"\n\r{'Subtotal :': >32} {currency_format(amount): >9}"
|
||||
|
||||
amount = sum(i.quantity * i.price for i in items if i.is_happy_hour)
|
||||
amount = sum(round(i.quantity * i.price, 2) for i in items if i.is_happy_hour)
|
||||
if amount != 0:
|
||||
s += f"\n\r{'Happy Hour Discount :': >32} {currency_format(amount): >9}"
|
||||
|
||||
amount = sum(i.quantity * i.effective_price * i.discount for i in items)
|
||||
amount = sum(round(i.quantity * i.effective_price * i.discount, 2) for i in items)
|
||||
if amount != 0:
|
||||
s += f"\n\r{'Discount :': >32} {currency_format(amount): >9}"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user