From: Christian Heller Date: Thu, 23 Jan 2025 07:19:16 +0000 (+0100) Subject: Add ?cutoff to /balance. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/%7B%7B%20web_path%20%7D%7D/static/do_tasks?a=commitdiff_plain;h=c1ff9550705d92cdc04c26ab6ec3aeef655c82ce;p=plomledger Add ?cutoff to /balance. --- diff --git a/ledger.py b/ledger.py index f4dde03..413b8fb 100755 --- 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] diff --git a/templates/_macros.tmpl b/templates/_macros.tmpl index 85c032e..c1a9a40 100644 --- a/templates/_macros.tmpl +++ b/templates/_macros.tmpl @@ -16,7 +16,7 @@ td.invalid, tr.warning td.invalid { background-color: #ff0000; } {% if not single %} {% if dat_line.is_intro %} - # + #/b {% else %} {% endif %}