+ self.get_ledger(ctx, False)
+
+ def get_balance(self, ctx) -> None:
+ """Display tree of calculated Accounts over .bookings[:up_incl+1]."""
+ id_ = int(self.params.first('up_incl') or '-1')
+ valid = True
+ account_names = set()
+ to_balance = (self.server.bookings[:id_ + 1] if id_ >= 0
+ else self.server.bookings)
+ for booking in to_balance:
+ 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] = {}
+ for full_name in sorted(list(account_names)):
+ step_names = full_name.split(':')
+ path = ''
+ for step_name in step_names:
+ parent_name = path[:]
+ path = ':'.join([path, step_name]) if path else step_name
+ if path not in full_names_to_accounts:
+ full_names_to_accounts[path] = Account(
+ full_names_to_accounts[parent_name] if parent_name
+ else None,
+ step_name)
+ for booking in to_balance:
+ for account_name in booking.account_changes:
+ full_names_to_accounts[account_name].local_wealth +=\
+ booking.account_changes[account_name]
+ ctx['roots'] = [ac for ac in full_names_to_accounts.values()
+ if not ac.parent]
+ ctx['valid'] = valid
+ ctx['booking'] = self.server.bookings[id_]
+ self._send_rendered('balance', ctx)
+
+ def get_edit(self, ctx, raw: bool) -> None:
+ """Display edit form for individual Booking."""
+ id_ = int(self.path_toks[2])
+ ctx['id'] = id_
+ ctx['dat_lines'] = [dl if raw else dl.as_dict for dl
+ in self.server.bookings[id_].booked_lines]
+ self._send_rendered(EDIT_RAW if raw else EDIT_STRUCT, ctx)
+
+ def get_ledger(self, ctx: dict[str, Any], raw: bool) -> None:
+ """Display ledger of all Bookings."""
+ ctx['dat_lines'] = [dl for dl in self.server.dat_lines
+ if raw or not dl.is_empty]
+ self._send_rendered(LEDGER_RAW if raw else LEDGER_STRUCT, ctx)