diff options
| -rw-r--r-- | ledger_process.py | 21 | 
1 files changed, 12 insertions, 9 deletions
diff --git a/ledger_process.py b/ledger_process.py index d6b31fa..8b7a614 100644 --- a/ledger_process.py +++ b/ledger_process.py @@ -21,14 +21,11 @@ class LedgerProcess:          # don't make any assumtptions about ledger sorting          # groupby requires sorted inputs          actions_sorted = sorted(read_actions, key=lambda a: (a.refid, a.timestamp)) -        _grouped_actions = groupby(actions_sorted, lambda a: a.refid) -        _list_tuple_actions = [(k, list(v)) for k, v in _grouped_actions] -        # finally, sort groupy by first available timestamp -        sorted_grouped_actions = sorted( -            _list_tuple_actions, key=lambda a: a[1][0].timestamp -        ) +        grouped_actions = groupby(actions_sorted, lambda a: a.refid) + +        process_after: List[LedgerAction] = [] -        for refid, actions in sorted_grouped_actions: +        for refid, actions in grouped_actions:              actions = list(actions)              if len(actions) == 0: @@ -40,12 +37,18 @@ class LedgerProcess:              if action.type == "trade":                  self._process_trade(refid, actions) -            elif action.type == "deposit" and action.asset != "EUR": +            elif action.asset == "EUR": +                continue + +            elif action.type == "deposit" or action.type == "withdrawal":                  assert len(actions) == 1 +                process_after.append(action) + +        for action in sorted(process_after, key=lambda a: a.timestamp): +            if action.type == "deposit" and action.asset != "EUR":                  self._process_deposit(action)              elif action.type == "withdrawal" and action.asset != "EUR": -                assert len(actions) == 1                  self._process_withdrawal(action)      def _process_deposit(self, action: LedgerAction):  | 
