client-barcode: Split Status.commit() up into sub-functions
This commit is contained in:
parent
27962ad107
commit
156a0df88d
|
@ -267,63 +267,68 @@ class Status:
|
||||||
def commit(self):
|
def commit(self):
|
||||||
assert(self.logged_in())
|
assert(self.logged_in())
|
||||||
|
|
||||||
# Compress DepositCommands
|
def compress_deposit_commands():
|
||||||
dummy, initial_balance = self.transfers[0]
|
dummy, initial_balance = self.transfers[0]
|
||||||
balance_before = initial_balance
|
balance_before = initial_balance
|
||||||
compressed_deposit = DepositCommand(Decimal('0'))
|
compressed_deposit = DepositCommand(Decimal('0'))
|
||||||
others = list()
|
others = list()
|
||||||
for (command, dummy) in list(self.transfers):
|
for (command, dummy) in list(self.transfers):
|
||||||
if isinstance(command, DepositCommand):
|
if isinstance(command, DepositCommand):
|
||||||
compressed_deposit.add(command)
|
compressed_deposit.add(command)
|
||||||
else:
|
else:
|
||||||
others.append((command, balance_before))
|
others.append((command, balance_before))
|
||||||
balance_before += command.difference()
|
balance_before += command.difference()
|
||||||
if compressed_deposit.difference() != 0:
|
if compressed_deposit.difference() != 0:
|
||||||
others.append((compressed_deposit, balance_before))
|
others.append((compressed_deposit, balance_before))
|
||||||
self.transfers = others
|
self.transfers = others
|
||||||
|
|
||||||
# Compress BuyCommands, use a single bulkbuy
|
def process_buy_commands_combined():
|
||||||
dummy, initial_balance = self.transfers[0]
|
# Compress BuyCommands, use a single bulkbuy
|
||||||
balance_before = initial_balance
|
dummy, initial_balance = self.transfers[0]
|
||||||
|
balance_before = initial_balance
|
||||||
|
buy_commands = list()
|
||||||
|
non_buy_commands = list()
|
||||||
|
total_buy_diff = 0
|
||||||
|
|
||||||
buy_commands = list()
|
for command, dummy in self.transfers:
|
||||||
non_buy_commands = list()
|
if isinstance(command, BuyCommand):
|
||||||
total_buy_diff = 0
|
buy_commands.append(command)
|
||||||
|
else:
|
||||||
|
balance_before += command.difference()
|
||||||
|
non_buy_commands.append((command, balance_before))
|
||||||
|
|
||||||
for command, dummy in self.transfers:
|
|
||||||
if isinstance(command, BuyCommand):
|
|
||||||
buy_commands.append(command)
|
|
||||||
else:
|
|
||||||
balance_before += command.difference()
|
|
||||||
non_buy_commands.append((command, balance_before))
|
|
||||||
|
|
||||||
try:
|
|
||||||
net.bulk_buy(buy_commands, self.login_name)
|
|
||||||
except urllib2.HTTPError as e:
|
|
||||||
myDisplay.display_screen("Server error",'Server Error: %s' % str(e))
|
|
||||||
error_page('FEHLER bei Kommunikation mit Server "%s"' % str(e))
|
|
||||||
else:
|
|
||||||
self.transfers = non_buy_commands
|
|
||||||
|
|
||||||
# Process remaining command queue
|
|
||||||
for (command, balance_backup) in list(self.transfers):
|
|
||||||
try:
|
try:
|
||||||
command.run(self.login_name)
|
net.bulk_buy(buy_commands, self.login_name)
|
||||||
except urllib2.HTTPError as e:
|
except urllib2.HTTPError as e:
|
||||||
myDisplay.display_screen("Server error",'Server Error: %s' % str(e))
|
myDisplay.display_screen("Server error",'Server Error: %s' % str(e))
|
||||||
error_page('FEHLER bei Kommunikation mit Server "%s"' % str(e))
|
error_page('FEHLER bei Kommunikation mit Server "%s"' % str(e))
|
||||||
break
|
|
||||||
else:
|
else:
|
||||||
self.transfers.pop(0)
|
self.transfers = non_buy_commands
|
||||||
|
|
||||||
if not self.transfers:
|
def process_commands():
|
||||||
# Show final balance for some time
|
for (command, balance_backup) in list(self.transfers):
|
||||||
clear()
|
try:
|
||||||
self.dump()
|
command.run(self.login_name)
|
||||||
delay('Logout', 3)
|
except urllib2.HTTPError as e:
|
||||||
|
myDisplay.display_screen("Server error",'Server Error: %s' % str(e))
|
||||||
|
error_page('FEHLER bei Kommunikation mit Server "%s"' % str(e))
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
self.transfers.pop(0)
|
||||||
|
|
||||||
self.logout()
|
def finish():
|
||||||
|
if not self.transfers:
|
||||||
|
# Show final balance for some time
|
||||||
|
clear()
|
||||||
|
self.dump()
|
||||||
|
delay('Logout', 3)
|
||||||
|
|
||||||
|
self.logout()
|
||||||
|
|
||||||
|
compress_deposit_commands()
|
||||||
|
process_buy_commands_combined()
|
||||||
|
process_commands()
|
||||||
|
finish()
|
||||||
|
|
||||||
def find(self, barcode):
|
def find(self, barcode):
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue