diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index 939c14f..9958f60 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -261,6 +261,21 @@ class Status: def commit(self): assert(self.logged_in()) + # Compress DepositCommands + dummy, initial_balance = self.transfers[0] + balance_before = initial_balance + compressed_deposit = DepositCommand(Decimal('0')) + others = list() + for (command, dummy) in list(self.transfers): + if isinstance(command, DepositCommand): + compressed_deposit.add(command) + else: + others.append((command, balance_before)) + balance_before += command.difference() + if compressed_deposit.difference() != 0: + others.append((compressed_deposit, balance_before)) + self.transfers = others + # Process command queue for (command, balance_backup) in list(self.transfers): try: diff --git a/client-barcode/freitagslib/commands.py b/client-barcode/freitagslib/commands.py index 1782118..69a27ab 100644 --- a/client-barcode/freitagslib/commands.py +++ b/client-barcode/freitagslib/commands.py @@ -15,6 +15,10 @@ class DepositCommand(object): def difference(self): return self._difference + def add(self, deposit_command): + assert(isinstance(deposit_command, DepositCommand)) + self._difference += deposit_command._difference + def run(self, user_name): net.deposit(self._difference, net.DEPOSIT_CASH, user_name)