|
|
|
@ -35,6 +35,7 @@ def clear():
|
|
|
|
|
os.system('clear')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TO_GO_ONLY = 2
|
|
|
|
|
TO_GO_ALL = 1
|
|
|
|
|
TO_GO_NONE = 0
|
|
|
|
|
TO_GO_PREV = -1
|
|
|
|
@ -46,6 +47,7 @@ CODES = {
|
|
|
|
|
'TO GO ALL':('to_go', TO_GO_ALL),
|
|
|
|
|
'TO GO NONE':('to_go', TO_GO_NONE),
|
|
|
|
|
'TO GO PREV':('to_go', TO_GO_PREV),
|
|
|
|
|
'TO GO ONLY':('to_go', TO_GO_ONLY),
|
|
|
|
|
|
|
|
|
|
'DEPOSIT 0.01':('deposit', Decimal('0.01')),
|
|
|
|
|
'DEPOSIT 0.05':('deposit', Decimal('0.05')),
|
|
|
|
@ -212,6 +214,9 @@ class Status:
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
if scope == TO_GO_ALL:
|
|
|
|
|
"""
|
|
|
|
|
Adds a ToGoCommands for each BuyCommands with deposit > 0 lacking a pair
|
|
|
|
|
"""
|
|
|
|
|
after = list()
|
|
|
|
|
dummy, initial_balance = self.transfers[0]
|
|
|
|
|
balance_before = initial_balance
|
|
|
|
@ -219,8 +224,10 @@ class Status:
|
|
|
|
|
def body(prev, command, balance_before):
|
|
|
|
|
if isinstance(prev, BuyCommand) \
|
|
|
|
|
and prev.deposit() > 0 \
|
|
|
|
|
and not isinstance(command, ToGoCommand):
|
|
|
|
|
to_go = ToGoCommand(prev)
|
|
|
|
|
and (not isinstance(command, ToGoCommand) \
|
|
|
|
|
or (isinstance(command, ToGoCommand) \
|
|
|
|
|
and prev.item() != command.item())):
|
|
|
|
|
to_go = ToGoCommand(prev.item())
|
|
|
|
|
prev.set_to_go(True)
|
|
|
|
|
after.append((to_go, balance_before))
|
|
|
|
|
balance_before += to_go.difference()
|
|
|
|
@ -238,6 +245,9 @@ class Status:
|
|
|
|
|
self.balance = balance_before
|
|
|
|
|
self.transfers = after
|
|
|
|
|
elif scope == TO_GO_NONE:
|
|
|
|
|
"""
|
|
|
|
|
Deletes all ToGoCommands
|
|
|
|
|
"""
|
|
|
|
|
after = list()
|
|
|
|
|
first_command, initial_balance = self.transfers[0]
|
|
|
|
|
balance_before = initial_balance
|
|
|
|
@ -254,14 +264,50 @@ class Status:
|
|
|
|
|
self.balance = balance_before
|
|
|
|
|
self.transfers = after
|
|
|
|
|
elif scope == TO_GO_PREV:
|
|
|
|
|
"""
|
|
|
|
|
Adds a ToGoCommand after previous BuyCommand
|
|
|
|
|
"""
|
|
|
|
|
prev, balance_backup = self.transfers[-1]
|
|
|
|
|
if not isinstance(prev, BuyCommand):
|
|
|
|
|
error_page(_PRODUCT_FIRST)
|
|
|
|
|
return
|
|
|
|
|
to_go = ToGoCommand(prev)
|
|
|
|
|
to_go = ToGoCommand(prev.item())
|
|
|
|
|
prev.set_to_go(True)
|
|
|
|
|
self.transfers.append((to_go, self.balance))
|
|
|
|
|
self.balance += to_go.difference()
|
|
|
|
|
elif scope == TO_GO_ONLY:
|
|
|
|
|
"""
|
|
|
|
|
Replace all BuyCommands with deposit > 0 by
|
|
|
|
|
a ToGoCommand. Resolve ToGoCommand duplicates.
|
|
|
|
|
"""
|
|
|
|
|
after = list()
|
|
|
|
|
first_command, initial_balance = self.transfers[0]
|
|
|
|
|
balance_before = initial_balance
|
|
|
|
|
|
|
|
|
|
for command, dummy in list(self.transfers):
|
|
|
|
|
if isinstance(command, ToGoCommand) \
|
|
|
|
|
and prev_item is not None \
|
|
|
|
|
and command.item() == prev_item:
|
|
|
|
|
"""
|
|
|
|
|
Skip this very duplicate
|
|
|
|
|
"""
|
|
|
|
|
prev_item = None
|
|
|
|
|
continue
|
|
|
|
|
elif isinstance(command, BuyCommand) \
|
|
|
|
|
and command.deposit() > 0:
|
|
|
|
|
"""
|
|
|
|
|
Replace by ToGoCommand
|
|
|
|
|
"""
|
|
|
|
|
item = command.item()
|
|
|
|
|
command = ToGoCommand(item)
|
|
|
|
|
prev_item = item
|
|
|
|
|
else:
|
|
|
|
|
prev_item = None
|
|
|
|
|
after.append((command, balance_before))
|
|
|
|
|
balance_before += command.difference()
|
|
|
|
|
|
|
|
|
|
self.balance = balance_before
|
|
|
|
|
self.transfers = after
|
|
|
|
|
|
|
|
|
|
def undo(self):
|
|
|
|
|
assert(self.logged_in())
|
|
|
|
|