+ booking = self.server.bookings[id_]
+ acc_names = Account.names_over_bookings(self.server.bookings)
+ to_balance = self.server.bookings[:id_ + 1]
+ accounts_after = Account.by_paths(acc_names)
+ accounts_before = Account.by_paths(acc_names)
+ for b in to_balance:
+ if b != booking:
+ b.apply_to_account_dict(accounts_before)
+ b.apply_to_account_dict(accounts_after)
+ observed_tree: list[dict[str, Any]] = []
+ for full_name in sorted(booking.account_changes.keys()):
+ parent_children: list[dict[str, Any]] = observed_tree
+ path = ''
+ for step_name in full_name.split(':'):
+ path = ':'.join([path, step_name]) if path else step_name
+ for child in [n for n in parent_children if path == n['name']]:
+ parent_children = child['children']
+ continue
+ wealth_before = accounts_before[path].wealth
+ wealth_after = accounts_after[path].wealth
+ diff = {c: a for c, a in (wealth_after - wealth_before
+ ).moneys.items()
+ if a != 0}
+ if diff:
+ displayed_currencies = set(diff.keys())
+ for wealth in wealth_before, wealth_after:
+ wealth.ensure_currencies(displayed_currencies)
+ wealth.purge_currencies_except(displayed_currencies)
+ node: dict[str, Any] = {
+ 'name': path,
+ 'wealth_before': wealth_before.moneys,
+ 'wealth_diff': diff,
+ 'wealth_after': wealth_after.moneys,
+ 'children': []}
+ parent_children += [node]
+ parent_children = node['children']