From: Christian Heller <c.heller@plomlompom.de>
Date: Wed, 22 Jan 2025 19:00:58 +0000 (+0100)
Subject: Improve balance table layout, color warning if bad Bookings.
X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/static/template?a=commitdiff_plain;h=3cb0a5349e83e2d948d0478853febdd5c9674795;p=ledgplom

Improve balance table layout, color warning if bad Bookings.
---

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 @@
 <style>
 body { background-color: white; font-family: sans-serif; }
 tr:nth-child(odd) { background-color: #dcdcdc; }
+td { text-align: left; vertical-align: top; }
+table.warning tbody tr td, tr.warning td { background-color: #ff8888; }
 {% block css %}{% endblock %}
 </style>
 </head>
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 @@
 <td class="curr">{{curr|truncate(4,true,"…")}}</td>
 {% endif %}
 {% endfor %}
-<td>{% for _ in range(indent) %}&nbsp; &nbsp; &nbsp;{% endfor %}{{account.basename}}</td>
+<td rowspan={{ account.wealth.moneys|length }}>{% for _ in range(indent) %}&nbsp; &nbsp; &nbsp;{% endfor %}{{account.basename}}</td>
 </tr>
 {% for curr, amt in account.wealth.moneys.items() %}
 {% if 1 < loop.index %}
@@ -29,7 +29,7 @@
 {% endblock css %}
 
 {% block content %}
-<table>
+<table{% if not valid %} class="warning"{% endif %}>
 {% for root in roots %}
 {{ account_with_children(root, indent=0) }}
 {% endfor %}