Skip to content

Commit

Permalink
Enable negative price PLUs to sell negative number of items
Browse files Browse the repository at this point in the history
PLUs can have negative prices. Spot this, and sell a negative number of
items at a positive price instead.

Also, add a register hook to enable plugins to veto PLU sales.

Related issue: #281 on github.
  • Loading branch information
sde1000 committed Apr 19, 2024
1 parent cc7e28a commit ded75d5
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion quicktill/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ class RegisterPlugin(metaclass=plugins.InstancePluginMount):
transaction
- canceltrans(trans) - trans may be open or closed
- cancelempty(trans) - cash/enter on an empty transaction
- sell_plu(trans, plu, items, current_transline) - add or update PLU
on open transaction
- cancelline(l)
- cancelpayment(p)
- markkey()
Expand Down Expand Up @@ -1181,7 +1183,10 @@ def _sell_plu(self, plu, mod):
if may_repeat and len(self.dl) > 0 and \
self.dl[-1].age() < max_transline_modify_age():
otl = td.s.query(Transline).get(self.dl[-1].transline)
otl.items = otl.items + 1
new_items = otl.items + 1 if otl.items >= 0 else otl.items - 1
if self.hook("sell_plu", trans, plu, new_items, otl):
return
otl.items = new_items
self.dl[-1].update()
td.s.flush()
td.s.expire(trans, ['total'])
Expand Down Expand Up @@ -1246,6 +1251,15 @@ def _sell_plu(self, plu, mod):
self.transaction_lock_popup()
return

# If sale.price is negative, make it positive and make the
# number of items be negative instead
if sale.price < zero:
sale.price = -sale.price
items = -items

if self.hook("sell_plu", trans, plu, items, None):
return

tl = Transline(transaction=trans, items=items, amount=sale.price,
department=plu.department, user=self.user.dbuser,
transcode='S', text=sale.description,
Expand Down

0 comments on commit ded75d5

Please sign in to comment.