From: Christian Heller Date: Tue, 10 Feb 2026 17:37:22 +0000 (+0100) Subject: Calculate comment instructions only until point of retrieval. X-Git-Url: https://plomlompom.com/repos/processes?a=commitdiff_plain;p=ledgplom Calculate comment instructions only until point of retrieval. --- diff --git a/src/ledgplom/ledger.py b/src/ledgplom/ledger.py index d92e01f..7cc1abb 100644 --- a/src/ledgplom/ledger.py +++ b/src/ledgplom/ledger.py @@ -633,8 +633,8 @@ class Ledger: lines += list(block.lines) return tuple(lines) - def _calc_accounts(self) -> dict[str, _Account]: - 'Build mapping of account names to _Accounts.' + def _calc_accounts(self, id_: int) -> dict[str, _Account]: + 'Map account names to _Accounts, their details only defined until id_.' accounts: dict[str, _Account] = {} def ensure_accounts(full_path: str) -> None: @@ -646,15 +646,18 @@ class Ledger: step_name) parent_path = path - for dat_line in self._dat_lines: - for acc_name, desc in dat_line.comment_instructions.items(): - ensure_accounts(acc_name) - accounts[acc_name].desc = desc - for block in [b for b in self.blocks if b.booking]: - assert block.booking is not None - for acc_name, wealth in block.booking.diffs_targeted.items(): - ensure_accounts(acc_name) - accounts[acc_name].add_wealth_diff(block.id_, wealth) + for block in self.blocks: + collect_more_than_names = id_ < 0 or block.id_ <= id_ + for line in block.lines: + for acc_name, desc in line.comment_instructions.items(): + ensure_accounts(acc_name) + if collect_more_than_names: + accounts[acc_name].desc = desc + if block.booking: + for acc_name, wealth in block.booking.diffs_targeted.items(): + ensure_accounts(acc_name) + if collect_more_than_names: + accounts[acc_name].add_wealth_diff(block.id_, wealth) return accounts def save(self) -> None: @@ -719,7 +722,7 @@ class Ledger: id_ = len(self.blocks) - 1 return {'valid': self._blocks_valid_up_incl(id_), 'block': self.blocks[id_], - 'roots': sorted([ac for ac in self._calc_accounts().values() + 'roots': sorted([ac for ac in self._calc_accounts(id_).values() if not ac.parent], key=lambda root: root.basename)} @@ -731,7 +734,7 @@ class Ledger: 'booking_lines': ([line.as_dict for line in block.booking.booking_lines] if block.booking else tuple())} - accounts = self._calc_accounts() + accounts = self._calc_accounts(id_) roots: list[dict[str, Any]] = [] for full_path in sorted(block.booking.diffs_targeted.keys() if block.booking else []): diff --git a/src/tests/full.balance b/src/tests/full.balance index d5684a1..49cc991 100644 --- a/src/tests/full.balance +++ b/src/tests/full.balance @@ -127,7 +127,7 @@ span.indent {  :x: - bla bla bla + bla foo bla diff --git a/src/tests/full.dat b/src/tests/full.dat index 9261965..91c537d 100644 --- a/src/tests/full.dat +++ b/src/tests/full.dat @@ -22,6 +22,8 @@ bar:x:y -10 € bar:z -1 USD +; #def bar:x bla foo bla + 2001-01-03 test foo:x 10 € foo:x 3 USD diff --git a/src/tests/full.edit_structured.4 b/src/tests/full.edit_structured.4 index 020d4d9..6ad51b0 100644 --- a/src/tests/full.edit_structured.4 +++ b/src/tests/full.edit_structured.4 @@ -109,7 +109,9 @@ to
Gap:
- diff --git a/src/tests/full.ledger_raw b/src/tests/full.ledger_raw index ab212b2..49e154e 100644 --- a/src/tests/full.ledger_raw +++ b/src/tests/full.ledger_raw @@ -140,20 +140,22 @@ Detected redundant empty lines in gaps, - - + + diff --git a/src/tests/full.ledger_structured b/src/tests/full.ledger_structured index 7325363..2d73385 100644 --- a/src/tests/full.ledger_structured +++ b/src/tests/full.ledger_structured @@ -225,14 +225,14 @@ Detected redundant empty lines in gaps, - - + + + + + +
+

+ [#]
[b]
[e]
 
; #def bar:x bla foo bla 
 
2001-01-03 test 
foo:x 10 € 
foo:x 3 USD 
+

+ [#]
[b]
[e] @@ -241,6 +241,12 @@ Detected redundant empty lines in gaps,  
; #def bar:x bla foo bla 
 
2001-01-03 test