home · contact · privacy
Calculate /balance up-and-incl. rather than up-and-excl, name last included Booking...
authorChristian Heller <c.heller@plomlompom.de>
Tue, 28 Jan 2025 12:39:20 +0000 (13:39 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Tue, 28 Jan 2025 12:39:20 +0000 (13:39 +0100)
ledger.py
templates/_macros.tmpl
templates/balance.tmpl

index d25462867d42d4f7a11bc4c627130e2e7cbc97c5..a4a94bd7b8e61cbe50634e0201ab1e161ef7f88f 100755 (executable)
--- a/ledger.py
+++ b/ledger.py
@@ -304,10 +304,12 @@ class Handler(PlomHttpHandler):
             if self.pagename.startswith('edit_'):
                 ctx['id'] = id_
         if self.pagename == 'balance':
-            valid, balance_roots = self.server.balance_roots(
-                    int(self.params.first('cutoff') or '0'))
+            id_ = int(self.params.first('up_incl') or '-1')
+            valid, balance_roots = self.server.balance_roots(id_)
             self.send_rendered(Path('balance.tmpl'),
-                               ctx | {'roots': balance_roots, 'valid': valid})
+                               ctx | {'roots': balance_roots,
+                                      'valid': valid,
+                                      'booking': self.server.bookings[id_]})
         elif self.pagename == 'booking':
             self.redirect(
                     Path('/').joinpath('edit_structured').joinpath(str(id_)))
@@ -390,11 +392,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]
 
-    def balance_roots(self, cutoff: int) -> tuple[bool, list[Account]]:
-        """Return tree of calculated Accounts over .bookings[:cutoff]."""
+    def balance_roots(self, up_incl: int) -> tuple[bool, list[Account]]:
+        """Return tree of calculated Accounts over .bookings[:up_incl+1]."""
         account_names = set()
         valid = True
-        to_balance = self.bookings[:cutoff] if cutoff else self.bookings
+        to_balance = (self.bookings[:up_incl + 1] if up_incl >= 0
+                      else self.bookings)
         for booking in to_balance:
             valid = valid if not booking.is_questionable else False
             for account_name in booking.account_changes:
index 0dfd2fc742ea8f5d79796c82197a1822e34d1f94..7ae7845eb26db0c9089f00560a19252ff798b7e2 100644 (file)
@@ -15,7 +15,7 @@ td.invalid, tr.warning td.invalid { background-color: #ff0000; }
   {% endif %}
   <tr class="alternating{% if dat_line.is_questionable %} warning{% endif %}">
   {% if dat_line.is_intro %}
-    <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>
+    <td id="{{dat_line.booking_id}}"><a href="#{{dat_line.booking_id}}">#</a>/<a href="/balance?up_incl={{dat_line.booking_id}}">b</a></td>
   {% else %}
     <td></td>
   {% endif %}
index 14878c9bcfa88cc0cf95019beba6b6543ecc0e87..15ebf833a0ff669fa152146abf94c8a26db1f7fb 100644 (file)
@@ -62,6 +62,7 @@ span.indent { letter-spacing: 3em; }
 {% endblock css %}
 
 {% block content %}
+<p>balance after <a href="/booking/{{booking.id_}}">booking {{booking.id_}} ({{booking.intro_line.date}}: {{booking.intro_line.target}})</a></p>
 <table{% if not valid %} class="warning"{% endif %}>
 {% for root in roots %}
 {{ account_with_children(root, indent=0) }}