home · contact · privacy
Allow in-body Booking comments.
authorChristian Heller <c.heller@plomlompom.de>
Sun, 8 Feb 2026 17:56:56 +0000 (18:56 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Sun, 8 Feb 2026 17:56:56 +0000 (18:56 +0100)
src/ledgplom/ledger.py
src/templates/ledger_structured.html
src/tests/full.dat
src/tests/full.edit_raw.0
src/tests/full.edit_structured.0
src/tests/full.ledger_raw
src/tests/full.ledger_structured

index e84fabc1a7c8cf6b1e08cba24ad9605637f982a6..d92e01f2713446165d4eb97d423cc575184d5f1b 100644 (file)
@@ -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()
index 26318f0afa9414ce6911b263e040ddca9dcbe969..dae16b0bd9f42370d2c5cee0f3ae02a54c351737 100644 (file)
@@ -29,8 +29,9 @@
         </td>
         <td>{{ block.booking.intro_line.comment }}</td>
     </tr>
-{####}{% for line in block.booking.transfer_lines %}
+{####}{% for line in block.booking.body_lines %}
     <tr>
+{######}{% if line.account %}
         <td class="amount{{ ' critical' if line.errors }}">
             {{- line.amount_short -}}
         </td>
@@ -41,6 +42,9 @@
             {{- line.account -}}
         </td>
         <td>{{ line.comment }}</td>
+{######}{% else %}
+        <td colspan=4>{{ line.comment }}</td>
+{######}{% endif %}
     </tr>
 {####}{% endfor %}
 {##}{% endif %}
index 324edada9b373e5e074d79c2cf0ef78af46ec7ba..92619657ec7168a5e9bca4866ea38d90043bd51c 100644 (file)
@@ -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
index 7b98e5048c7069410467f083b69e0c2acd89c69e..af3835cc3c4e16e0e7f568c8ed7794051f5e2431 100644 (file)
@@ -82,11 +82,14 @@ td.direct_target {
 </span>
 <hr>
 
-<textarea name="raw_lines" class="tainter" cols="100" rows="6">; #def bar:x bla bla bla
+<textarea name="raw_lines" class="tainter" cols="100" rows="9">; #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
 </textarea>
 </form>
 <table class="alternating">
index 5519d394b9f812303052011258b99dfaabc2a250..535286a3a2bf70472c3d38eb23508046c507f39d 100644 (file)
@@ -131,16 +131,16 @@ to
             <input name="line_1_len_indent" size="1" value="4" type="number" min="1" step="1">
         </td>
         <td colspan="1">
-            <input name="line_1_account" size="30" value="foo" list="all_accounts" autocomplete="off">
+            <input name="line_1_account" size="30" value="" list="all_accounts" autocomplete="off">
         </td>
         <td colspan="1">
-            <input name="line_1_amount" size="12" value="10" pattern="^-?[0-9]+(.[0-9]+)?$" class="amount">
+            <input name="line_1_amount" size="12" value="" pattern="^-?[0-9]+(.[0-9]+)?$" class="amount">
         </td>
         <td colspan="1">
-            <input name="line_1_currency" size="3" value="" placeholder="€">
+            <input name="line_1_currency" size="3" value="" placeholder="€">
         </td>
         <td colspan="1">
-            <input name="line_1_comment" size="40" value="">
+            <input name="line_1_comment" size="40" value="in-body comment 1">
         </td>
         <td colspan="1">
             <button type="button">add new</button>
@@ -156,10 +156,10 @@ to
             <input name="line_2_len_indent" size="1" value="4" type="number" min="1" step="1">
         </td>
         <td colspan="1">
-            <input name="line_2_account" size="30" value="bar" list="all_accounts" autocomplete="off">
+            <input name="line_2_account" size="30" value="foo" list="all_accounts" autocomplete="off">
         </td>
         <td colspan="1">
-            <input name="line_2_amount" size="12" value="-10" pattern="^-?[0-9]+(.[0-9]+)?$" class="amount">
+            <input name="line_2_amount" size="12" value="10" pattern="^-?[0-9]+(.[0-9]+)?$" class="amount">
         </td>
         <td colspan="1">
             <input name="line_2_currency" size="3" value="€" placeholder="€">
@@ -172,6 +172,81 @@ to
             <button type="button">delete</button>
         </td>
     </tr>
+    <tr>
+        <td colspan="1">
+            <button type="button">^</button>
+            <button type="button">v</button>
+        </td>
+        <td colspan="1">
+            <input name="line_3_len_indent" size="1" value="4" type="number" min="1" step="1">
+        </td>
+        <td colspan="1">
+            <input name="line_3_account" size="30" value="" list="all_accounts" autocomplete="off">
+        </td>
+        <td colspan="1">
+            <input name="line_3_amount" size="12" value="" pattern="^-?[0-9]+(.[0-9]+)?$" class="amount">
+        </td>
+        <td colspan="1">
+            <input name="line_3_currency" size="3" value="" placeholder="€">
+        </td>
+        <td colspan="1">
+            <input name="line_3_comment" size="40" value="in-body comment 2">
+        </td>
+        <td colspan="1">
+            <button type="button">add new</button>
+            <button type="button">delete</button>
+        </td>
+    </tr>
+    <tr>
+        <td colspan="1">
+            <button type="button">^</button>
+            <button type="button">v</button>
+        </td>
+        <td colspan="1">
+            <input name="line_4_len_indent" size="1" value="4" type="number" min="1" step="1">
+        </td>
+        <td colspan="1">
+            <input name="line_4_account" size="30" value="bar" list="all_accounts" autocomplete="off">
+        </td>
+        <td colspan="1">
+            <input name="line_4_amount" size="12" value="-10" pattern="^-?[0-9]+(.[0-9]+)?$" class="amount">
+        </td>
+        <td colspan="1">
+            <input name="line_4_currency" size="3" value="€" placeholder="€">
+        </td>
+        <td colspan="1">
+            <input name="line_4_comment" size="40" value="">
+        </td>
+        <td colspan="1">
+            <button type="button">add new</button>
+            <button type="button">delete</button>
+        </td>
+    </tr>
+    <tr>
+        <td colspan="1">
+            <button type="button">^</button>
+            <button type="button">v</button>
+        </td>
+        <td colspan="1">
+            <input name="line_5_len_indent" size="1" value="4" type="number" min="1" step="1">
+        </td>
+        <td colspan="1">
+            <input name="line_5_account" size="30" value="" list="all_accounts" autocomplete="off">
+        </td>
+        <td colspan="1">
+            <input name="line_5_amount" size="12" value="" pattern="^-?[0-9]+(.[0-9]+)?$" class="amount">
+        </td>
+        <td colspan="1">
+            <input name="line_5_currency" size="3" value="" placeholder="€">
+        </td>
+        <td colspan="1">
+            <input name="line_5_comment" size="40" value="in-body comment 3">
+        </td>
+        <td colspan="1">
+            <button type="button">add new</button>
+            <button type="button">delete</button>
+        </td>
+    </tr>
 </table>
 </EXPANDED>
 </form>
index 3de28c950b415b3b51b9c7ca8666ced5224469e1..ab212b2ad401120032f0158f48354d8095da4d85 100644 (file)
@@ -57,14 +57,14 @@ Detected redundant empty lines in gaps, <input type="submit" name="remove_redund
 <tbody>
     <tr></tr><!-- keep the background-color alternation in proper order -->
     <tr id="block_0">
-        <td rowspan="6" class="block_column">
+        <td rowspan="9" class="block_column">
             <input type="submit" name="ledger_moveup_0" value="^" disabled="">
             <br>
             <input type="submit" name="ledger_movedown_0" value="v" disabled="">
             <br>
             <input type="submit" name="ledger_copy_0" value="C">
         </td>
-        <td rowspan="6" class="block_column">
+        <td rowspan="9" class="block_column">
             [<a href="#block_0">#</a>]<br>
             [<a href="/balance/0">b</a>]<br>
             [<a href="/edit_raw/0">e</a>]
@@ -73,8 +73,11 @@ Detected redundant empty lines in gaps, <input type="submit" name="remove_redund
     <tr><td>; #def bar:x bla bla bla&nbsp;</td></tr>
     <tr><td>&nbsp;</td></tr>
     <tr><td>2001-01-01 test  ; foo&nbsp;</td></tr>
+    <tr><td>    ; in-body comment 1&nbsp;</td></tr>
     <tr><td>    foo    10 €&nbsp;</td></tr>
+    <tr><td>    ; in-body comment 2&nbsp;</td></tr>
     <tr><td>    bar   -10 €&nbsp;</td></tr>
+    <tr><td>    ; in-body comment 3&nbsp;</td></tr>
     <tr></tr><!-- keep the background-color alternation in proper order -->
     <tr id="block_1">
         <td rowspan="5" class="block_column">
index cc46c9927309a5e25ad4403fc49c65b32a13c7f7..7325363bfadb435c7d643d22db0e3096d88aafcd 100644 (file)
@@ -62,14 +62,14 @@ Detected redundant empty lines in gaps, <input type="submit" name="remove_redund
 <tbody>
     <tr></tr><!-- keep the background-color alternation in proper order -->
     <tr id="block_0">
-        <td rowspan="6" class="block_column">
+        <td rowspan="9" class="block_column">
             <input type="submit" name="ledger_moveup_0" value="^" disabled="">
             <br>
             <input type="submit" name="ledger_movedown_0" value="v" disabled="">
             <br>
             <input type="submit" name="ledger_copy_0" value="C">
         </td>
-        <td rowspan="6" class="block_column">
+        <td rowspan="9" class="block_column">
             [<a href="#block_0">#</a>]<br>
             [<a href="/balance/0">b</a>]<br>
             [<a href="/edit_structured/0">e</a>]
@@ -85,18 +85,27 @@ Detected redundant empty lines in gaps, <input type="submit" name="remove_redund
         <td colspan="3">2001-01-01 test</td>
         <td>foo</td>
     </tr>
+    <tr>
+        <td colspan="4">in-body comment 1</td>
+    </tr>
     <tr>
         <td class="amount">10.00</td>
         <td class="currency">€</td>
         <td>foo</td>
         <td></td>
     </tr>
+    <tr>
+        <td colspan="4">in-body comment 2</td>
+    </tr>
     <tr>
         <td class="amount">-10.00</td>
         <td class="currency">€</td>
         <td>bar</td>
         <td></td>
     </tr>
+    <tr>
+        <td colspan="4">in-body comment 3</td>
+    </tr>
     <tr></tr><!-- keep the background-color alternation in proper order -->
     <tr id="block_1">
         <td rowspan="5" class="block_column">