From: Christian Heller 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%7Bdb.prefix%7D%7D/static/%7B%7Bprefix%7D%7D/%7B%7B%20web_path%20%7D%7D/tasks?a=commitdiff_plain;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 @@