From: Christian Heller <c.heller@plomlompom.de> Date: Mon, 27 Jan 2025 06:08:39 +0000 (+0100) Subject: Improve balance layout, ensure € always displayed first, show full Account paths. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/decks/day?a=commitdiff_plain;h=2b06fc5e8cfad9a07c5bc9f014e9849ba48fe6e1;p=plomledger Improve balance layout, ensure € always displayed first, show full Account paths. --- diff --git a/ledger.py b/ledger.py index a998b97..8968a4d 100755 --- 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() diff --git a/templates/_base.tmpl b/templates/_base.tmpl index c90f1ab..034c58d 100644 --- a/templates/_base.tmpl +++ b/templates/_base.tmpl @@ -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 %} diff --git a/templates/balance.tmpl b/templates/balance.tmpl index 6d5e9d4..bcb5951 100644 --- a/templates/balance.tmpl +++ b/templates/balance.tmpl @@ -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 %}