home · contact · privacy
Add ?cutoff to /balance.
authorChristian Heller <c.heller@plomlompom.de>
Thu, 23 Jan 2025 07:19:16 +0000 (08:19 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Thu, 23 Jan 2025 07:19:16 +0000 (08:19 +0100)
ledger.py
templates/_macros.tmpl

index f4dde03af8ccb066953fde5f2ebd699f01d019fa..413b8fbe7640d706a0efe39e4cec0eb68303cedc 100755 (executable)
--- a/ledger.py
+++ b/ledger.py
@@ -249,7 +249,8 @@ class Handler(PlomHttpHandler):
             ctx['id'] = int(self.path_toks[2])
             ctx['dat_lines'] = self.server.bookings[ctx['id']].dat_lines
         if self.pagename == 'balance':
-            valid, balance_roots = self.server.balance_roots
+            valid, balance_roots = self.server.balance_roots(
+                    int(self.params.first('cutoff') or '0'))
             self.send_rendered(Path('balance.tmpl'),
                                ctx | {'roots': balance_roots, 'valid': valid})
         elif self.pagename == 'booking':
@@ -310,12 +311,12 @@ class Server(PlomHttpServer):
         """Return only those .data_lines with .code or .comment."""
         return [dl for dl in self.dat_lines if not dl.is_empty]
 
-    @property
-    def balance_roots(self) -> tuple[bool, list[Account]]:
-        """Return tree of calculated Accounts over all .bookings."""
+    def balance_roots(self, cutoff: int) -> tuple[bool, list[Account]]:
+        """Return tree of calculated Accounts over .bookings[:cutoff]."""
         account_names = set()
         valid = True
-        for booking in self.bookings:
+        to_balance = self.bookings[:cutoff] if cutoff else self.bookings
+        for booking in to_balance:
             valid = valid if not booking.is_questionable else False
             for account_name in booking.account_changes:
                 account_names.add(account_name)
@@ -331,7 +332,7 @@ class Server(PlomHttpServer):
                         full_names_to_accounts[parent_name] if parent_name
                         else None,
                         step_name)
-        for booking in self.bookings:
+        for booking in to_balance:
             for account_name in booking.account_changes:
                 full_names_to_accounts[account_name].local_wealth +=\
                         booking.account_changes[account_name]
index 85c032ee5c1e6c00491577c8040b7b42b2c006ef..c1a9a40cc1eafc316baa6d689071ad45baef2ffa 100644 (file)
@@ -16,7 +16,7 @@ td.invalid, tr.warning td.invalid { background-color: #ff0000; }
   <tr{% if dat_line.is_questionable %} class="warning"{% endif %}>
   {% if not single %}
     {% if dat_line.is_intro %}
-      <td id="{{dat_line.booking_id}}"><a href="#{{dat_line.booking_id}}">#</a></td>
+      <td id="{{dat_line.booking_id}}"><a href="#{{dat_line.booking_id}}">#</a>/<a href="/balance?cutoff={{dat_line.booking_id+1}}">b</a></td>
     {% else %}
       <td></td>
     {% endif %}