From: Christian Heller Date: Sun, 8 Feb 2026 17:56:56 +0000 (+0100) Subject: Allow in-body Booking comments. X-Git-Url: https://plomlompom.com/repos/booking/%22https:/validator.w3.org/blog?a=commitdiff_plain;h=a71ece8986226833b1a022b90ee966b8f51d913f;p=ledgplom Allow in-body Booking comments. --- diff --git a/src/ledgplom/ledger.py b/src/ledgplom/ledger.py index e84fabc..d92e01f 100644 --- a/src/ledgplom/ledger.py +++ b/src/ledgplom/ledger.py @@ -233,8 +233,8 @@ class _IntroLine(_BookingLine): return tuple(errors) -class _TransferLine(_BookingLine): - 'Non-first _Booking line, expected to carry value movement.' +class _BookingBodyLine(_BookingLine): + 'Non-first _Booking line, expected to carry value movement and/or comment.' _field_names = {'account', 'amount', 'currency', 'len_indent'} @property @@ -261,14 +261,11 @@ class _TransferLine(_BookingLine): @property def errors(self) -> tuple[str, ...]: errors = [] - # if not self.len_indent: - # errors += ['transfer line not indented'] - if not self.account: - errors += ['account missing'] - if isinstance(self.amount, str): - errors += [f'improper amount value: {self.amount}'] - if len(self.currency.split()) > 1: - errors += ['improper number of tokens'] + if self.account: + if isinstance(self.amount, str): + errors += [f'improper amount value: {self.amount}'] + if len(self.currency.split()) > 1: + errors += ['improper number of tokens'] return tuple(errors) @property @@ -332,8 +329,13 @@ class _Booking(_LinesBlock): @property def booking_lines(self) -> tuple[_BookingLine, ...]: - 'Sequence of .intro_line and .transfer_lines.' - return (self.intro_line, ) + self.transfer_lines + 'Sequence of .intro_line and .body_lines.' + return (self.intro_line, ) + self.body_lines + + @property + def body_lines(self) -> tuple[_BookingBodyLine, ...]: + 'Any lines past the first one (which would be .intro_line).' + return tuple(_BookingBodyLine(line.raw) for line in self.lines[1:]) @property def _diffs_targeted(self) -> dict[str, _Wealth]: @@ -386,10 +388,9 @@ class _Booking(_LinesBlock): @property @_LinesBlock._cache('transfer_lines') - def transfer_lines(self) -> tuple[_TransferLine, ...]: - 'Any lines past the first with .code.' - return tuple(_TransferLine(line.raw) for line in self.lines[1:] - if line.code) + def transfer_lines(self) -> tuple[_BookingBodyLine, ...]: + 'Any lines past the first with .account.' + return tuple(line for line in self.body_lines if line.account) @property def date(self) -> str: @@ -488,7 +489,7 @@ class _DatBlock(_LinesBlock, _LedgerNode): def booking(self) -> Optional[_Booking]: 'Booking made from lines indented or with code.' booking_lines = tuple(_DatLine(line.raw) for line in self.lines - if line.len_indent or line.code) + if line.code or line.len_indent) if not booking_lines: return None booking = _Booking() diff --git a/src/templates/ledger_structured.html b/src/templates/ledger_structured.html index 26318f0..dae16b0 100644 --- a/src/templates/ledger_structured.html +++ b/src/templates/ledger_structured.html @@ -29,8 +29,9 @@ {{ block.booking.intro_line.comment }} -{####}{% for line in block.booking.transfer_lines %} +{####}{% for line in block.booking.body_lines %} +{######}{% if line.account %} {{- line.amount_short -}} @@ -41,6 +42,9 @@ {{- line.account -}} {{ line.comment }} +{######}{% else %} + {{ line.comment }} +{######}{% endif %} {####}{% endfor %} {##}{% endif %} diff --git a/src/tests/full.dat b/src/tests/full.dat index 324edad..9261965 100644 --- a/src/tests/full.dat +++ b/src/tests/full.dat @@ -1,8 +1,11 @@ ; #def bar:x bla bla bla 2001-01-01 test ; foo + ; in-body comment 1 foo 10 € + ; in-body comment 2 bar -10 € + ; in-body comment 3 2001-01-02 test test bar -10 € ; bar diff --git a/src/tests/full.edit_raw.0 b/src/tests/full.edit_raw.0 index 7b98e50..af3835c 100644 --- a/src/tests/full.edit_raw.0 +++ b/src/tests/full.edit_raw.0 @@ -82,11 +82,14 @@ td.direct_target {
- diff --git a/src/tests/full.edit_structured.0 b/src/tests/full.edit_structured.0 index 5519d39..535286a 100644 --- a/src/tests/full.edit_structured.0 +++ b/src/tests/full.edit_structured.0 @@ -131,16 +131,16 @@ to + + + + + + + + + + + + + + + + + + + + + + + + + + +
- + - + - + - + @@ -156,10 +156,10 @@ to - + - + @@ -172,6 +172,81 @@ to
+ + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
diff --git a/src/tests/full.ledger_raw b/src/tests/full.ledger_raw index 3de28c9..ab212b2 100644 --- a/src/tests/full.ledger_raw +++ b/src/tests/full.ledger_raw @@ -57,14 +57,14 @@ Detected redundant empty lines in gaps, - +

- + [#]
[b]
[e] @@ -73,8 +73,11 @@ Detected redundant empty lines in gaps, diff --git a/src/tests/full.ledger_structured b/src/tests/full.ledger_structured index cc46c99..7325363 100644 --- a/src/tests/full.ledger_structured +++ b/src/tests/full.ledger_structured @@ -62,14 +62,14 @@ Detected redundant empty lines in gaps, - +

- + [#]
[b]
[e] @@ -85,18 +85,27 @@ Detected redundant empty lines in gaps, 2001-01-01 test foo + + in-body comment 1 + 10.00 € foo + + in-body comment 2 + -10.00 € bar + + in-body comment 3 +