From: Christian Heller Date: Sun, 4 Jan 2026 00:11:07 +0000 (+0100) Subject: In /balance view, sort node children by € amount. X-Git-Url: https://plomlompom.com/repos/booking/%7B%7B%20web_path%20%7D%7D/%7B%7Bdb.prefix%7D%7D/%7B%7Bprefix%7D%7D/%7B%7Btodo.date%7D%7D?a=commitdiff_plain;ds=inline;p=ledgplom In /balance view, sort node children by € amount. --- diff --git a/src/ledgplom/ledger.py b/src/ledgplom/ledger.py index 3a07f35..bc7323b 100644 --- a/src/ledgplom/ledger.py +++ b/src/ledgplom/ledger.py @@ -79,6 +79,12 @@ class Account: if self.parent: self.parent.children += [self] + def children_euro_sorted_at(self, up_incl: int) -> list[Self]: + 'Sorted .children, by .get_wealth_at(up_incl).' + return sorted(self.children, + key=lambda c: + c.get_wealth_at(up_incl).moneys.get('€', Decimal(0))) + def get_wealth_at_excl_incl(self, up_incl: int) -> tuple[_Wealth, _Wealth]: 'Total, with .children wealths, of wealth until Bookings of up_incl.' total_excl = _Wealth() diff --git a/src/templates/balance.tmpl b/src/templates/balance.tmpl index 3b2d9a9..f9eece8 100644 --- a/src/templates/balance.tmpl +++ b/src/templates/balance.tmpl @@ -77,7 +77,7 @@ span.indent { {{account.desc}} - {% for child in account.children %} + {% for child in account.children_euro_sorted_at(block_id) %} {{account_with_children(block_id, child, indent=indent+1)}} {% endfor %} {% endif %}