From 3cb0a5349e83e2d948d0478853febdd5c9674795 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Wed, 22 Jan 2025 20:00:58 +0100 Subject: [PATCH] Improve balance table layout, color warning if bad Bookings. --- ledger.py | 12 ++++++++---- templates/_base.tmpl | 2 ++ templates/_macros.tmpl | 2 -- templates/balance.tmpl | 4 ++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/ledger.py b/ledger.py index 89cf94f..89d5ca2 100755 --- a/ledger.py +++ b/ledger.py @@ -226,8 +226,9 @@ class Handler(PlomHttpHandler): def do_GET(self) -> None: # pylint: disable=invalid-name,missing-function-docstring if self.pagename == 'balance': - self.send_rendered(Path('balance.tmpl'), - {'roots': self.server.balance_roots}) + valid, balance_roots = self.server.balance_roots + self.send_rendered(Path('balance.tmpl'), {'roots': balance_roots, + 'valid': valid}) elif self.pagename == 'booking': self.send_rendered( Path('booking.tmpl'), @@ -270,10 +271,12 @@ class Server(PlomHttpServer): return [dl for dl in self.dat_lines if not dl.is_empty] @property - def balance_roots(self) -> list[Account]: + def balance_roots(self) -> tuple[bool, list[Account]]: """Return tree of calculated Accounts over all .bookings.""" account_names = set() + valid = True for booking in self.bookings: + valid = valid if not booking.is_questionable else False for account_name in booking.account_changes: account_names.add(account_name) full_names_to_accounts: dict[str, Account] = {} @@ -292,7 +295,8 @@ class Server(PlomHttpServer): for account_name in booking.account_changes: full_names_to_accounts[account_name].local_wealth +=\ booking.account_changes[account_name] - return [ac for ac in full_names_to_accounts.values() if not ac.parent] + return valid, [ac for ac in full_names_to_accounts.values() + if not ac.parent] if __name__ == "__main__": diff --git a/templates/_base.tmpl b/templates/_base.tmpl index 8b8dccf..268fb64 100644 --- a/templates/_base.tmpl +++ b/templates/_base.tmpl @@ -6,6 +6,8 @@ diff --git a/templates/_macros.tmpl b/templates/_macros.tmpl index 2342215..85c032e 100644 --- a/templates/_macros.tmpl +++ b/templates/_macros.tmpl @@ -1,11 +1,9 @@ {% macro css_td_money() %} td.amt { text-align: right } td.amt, td.curr { font-family: monospace; font-size: 1.3em; } -td.curr { text-align: left; } {% endmacro %} {% macro css_errors() %} -tr.warning td { background-color: #ff8888; } td.invalid, tr.warning td.invalid { background-color: #ff0000; } {% endmacro %} diff --git a/templates/balance.tmpl b/templates/balance.tmpl index 856b555..783e748 100644 --- a/templates/balance.tmpl +++ b/templates/balance.tmpl @@ -8,7 +8,7 @@ {{curr|truncate(4,true,"…")}} {% endif %} {% endfor %} -{% for _ in range(indent) %}     {% endfor %}{{account.basename}} +{% for _ in range(indent) %}     {% endfor %}{{account.basename}} {% for curr, amt in account.wealth.moneys.items() %} {% if 1 < loop.index %} @@ -29,7 +29,7 @@ {% endblock css %} {% block content %} - + {% for root in roots %} {{ account_with_children(root, indent=0) }} {% endfor %} -- 2.30.2