Skip to content

Commit

Permalink
Prevent crash when stocktype has a negative sale price
Browse files Browse the repository at this point in the history
Related issue: #281 on github.

We may want to support stock with a negative price in the future (for
example, where the "stock" is a limited number of discounts) but for now
let's just pop up an error when someone attempts to sell stock that has
a negative price.
  • Loading branch information
sde1000 committed Apr 19, 2024
1 parent ded75d5 commit 87c6a74
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions quicktill/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -1347,6 +1347,14 @@ def _sell_stocktype(self, stocktype, mod):
if explicitprice:
sale.price = explicitprice

if sale.price < zero:
log.info("_sell_stocktype: negative price for %s", st.format())
ui.infopopup(
[f"{st} has a negative sale price, which is not "
f"currently supported."],
title=f"{st} has negative price")
return

total_qty = items * sale.qty
sell, unallocated, remaining = st.calculate_sale(total_qty)

Expand Down Expand Up @@ -1535,6 +1543,15 @@ def _sell_stockline(self, stockline, mod):
if explicitprice:
sale.price = explicitprice

if sale.price < zero:
log.info("_sell_stockline: negative price for %s",
sale.stocktype.format())
ui.infopopup(
[f"{sale.stocktype} has a negative sale price, which is not "
f"currently supported."],
title=f"{sale.stocktype} has negative price")
return

total_qty = items * sale.qty
sell, unallocated, remaining = stockline.calculate_sale(
total_qty)
Expand Down

0 comments on commit 87c6a74

Please sign in to comment.