home · contact · privacy
Improve balance layout, ensure € always displayed first, show full Account paths. master
authorChristian Heller <c.heller@plomlompom.de>
Mon, 27 Jan 2025 06:08:39 +0000 (07:08 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Mon, 27 Jan 2025 06:08:39 +0000 (07:08 +0100)
ledger.py
templates/_base.tmpl
templates/balance.tmpl

index a998b974bd4f3a4a3db41b7b1cc96245efe36468..8968a4d5a701b45727c18c519bdb47ae0ad74a5b 100755 (executable)
--- a/ledger.py
+++ b/ledger.py
@@ -20,12 +20,21 @@ class Wealth:
 
     def __init__(self, moneys: Optional[dict[str, Decimal]] = None) -> None:
         self.moneys = moneys if moneys else {}
+        self._move_euro_up()
+
+    def _move_euro_up(self) -> None:
+        if '€' in self.moneys:
+            temp = {'€': self.moneys['€']}
+            for curr in [c for c in self.moneys if c != '€']:
+                temp[curr] = self.moneys[curr]
+            self.moneys = temp
 
     def _inc_by(self, other: Self, add=True) -> Self:
         for currency, amount in other.moneys.items():
             if currency not in self.moneys:
                 self.moneys[currency] = Decimal(0)
             self.moneys[currency] += amount if add else -amount
+        self._move_euro_up()
         return self
 
     def __iadd__(self, other: Self) -> Self:
@@ -59,6 +68,13 @@ class Account:
         if self.parent:
             self.parent.children += [self]
 
+    @property
+    def full_name(self) -> str:
+        """Return full account path."""
+        if self.parent:
+            return f'{self.parent.full_name}:{self.basename}'
+        return self.basename
+
     @property
     def wealth(self) -> Wealth:
         """Total of .local_wealth with that of .children."""
@@ -245,7 +261,7 @@ class Handler(PlomHttpHandler):
         redir_path = Path('/')
         if self.pagename.startswith('edit_'):
             id_ = int(self.path_toks[2])
-            redir_path = Path('/').joinpath(self.pagename).joinpath(str(id_))
+            redir_path = redir_path.joinpath(self.pagename).joinpath(str(id_))
         if self.pagename == 'file':
             if 'reload' in self.postvars.as_dict:
                 self.server.load()
index c90f1aba17bd1e802b60e27dc2b5ae67e908dfce..034c58d66e05622b44b40b2949c4a8d4303675af 100644 (file)
@@ -9,6 +9,7 @@
 <style>
 body { background-color: white; font-family: sans-serif; }
 tr:nth-child(odd) { background-color: #dcdcdc; }
+tr:nth-child(even) { background-color: #ffffff; }
 td { text-align: left; vertical-align: top; }
 span.warning, table.warning tbody tr td, tr.warning td { background-color: #ff8888; }
 {% block css %}{% endblock %}
index 6d5e9d481ab2627c84a5f5037e5db39f21d19838..bcb595131a0a0105c0292724a96cd753d57079fa 100644 (file)
@@ -1,27 +1,36 @@
 {% extends '_base.tmpl' %}
 
 {% macro account_with_children(account, indent) %}
-<tr>
-{% for curr, amt in account.wealth.moneys.items() %}
-{% if 1 == loop.index %}
-<td class="amt">{{amt}}</td>
-<td class="curr">{{curr|truncate(4,true,"…")}}</td>
-{% endif %}
-{% endfor %}
-<td>{% for _ in range(indent) %}[…]:{% endfor %}{{account.basename}}{% if account.children %}:–{% endif %}</td>
-</tr>
-{% for curr, amt in account.wealth.moneys.items() %}
-{% if 1 < loop.index %}
-<tr>
-<td class="amt">{{amt}}</td>
-<td class="curr">{{curr|truncate(4,true,"…")}}</td>
-<td>#</td>
-</tr>
-{% endif %}
-{% endfor %}
-{% for child in account.children %}
-{{ account_with_children(child, indent=indent+1) }}
-{% endfor %}
+  <tr>
+  {% for curr, amt in account.wealth.moneys.items() %}
+    {% if 1 == loop.index %}
+      <td class="amt">{{amt}}</td>
+      <td class="curr">{{curr|truncate(4,true,"…")}}</td>
+    {% endif %}
+  {% endfor %}
+  <td>{{account.full_name}}{% if account.children %}:…{% endif %}</td>
+  </tr>
+  {% if account.wealth.moneys|length > 1 %}
+  <tr>
+  <td colspan=2>
+  <details><summary>other currencies</summary>
+  <table>
+  {% for curr, amt in account.wealth.moneys.items() %}
+    {% if 1 < loop.index %}
+      <tr>
+      <td class="amt">{{amt}}</td>
+      <td class="curr">{{curr|truncate(4,true,"…")}}</td>
+      </tr>
+    {% endif %}
+  {% endfor %}
+  </table>
+  </details>
+  <td>
+  </tr>
+  {% endif %}
+  {% for child in account.children %}
+    {{ account_with_children(child, indent=indent+1) }}
+  {% endfor %}
 {% endmacro %}