From 53368e49ac90b65cffe9951e2d434e29e4c4bf72 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Wed, 19 Oct 2011 20:32:17 +0200 Subject: [PATCH] client-barcode: Commit 6 deposits of 1.00 Euro as one deposit of 6.00 Euro (bug #203) --- client-barcode/freitagskasse.py | 15 +++++++++++++++ client-barcode/freitagslib/commands.py | 4 ++++ 2 files changed, 19 insertions(+) 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)