- def ledger2_as_html(self, db):
- elements_to_write = []
- account_sums = {} ##
- nth_of_same_date = 0
- same_date = ''
- for booking in db.bookings:
- if booking.date_string == same_date:
- nth_of_same_date += 1
- else:
- same_date = booking.date_string
- nth_of_same_date = 0
- booking_end = booking.start_line + len(booking.lines)
- booking_lines = []
- for booking_line in booking.lines[1:]:
- if booking_line == '':
- continue
- account = booking_line[0] ##
- account_toks = account.split(':') ##
- path = '' ##
- for tok in account_toks: ##
- path += tok ##
- if not path in account_sums.keys(): ##
- account_sums[path] = {} ##
- path += ':' ##
- moneys = [] ##
- money = ''
- if booking_line[1] is not None:
- moneys += [(booking_line[1], booking_line[2])] ##
- money = f'{moneys[0][0]} {moneys[0][1]}'
- else: ##
- for currency, amount in booking.sink.items(): ##
- moneys += {(amount, currency)} ##
- money = '[' ##
- for m in moneys: ##
- money += f'{m[0]} {m[1]} ' ##
- money += ']' ##
- balance = '' ##
- for amount, currency in moneys: ##
- path = '' ##
- for tok in account_toks: ##
- path += tok ##
- if not currency in account_sums[path].keys(): ##
- account_sums[path][currency] = 0 ##
- account_sums[path][currency] += amount ##
- path += ':' ##
- balance += f'{account_sums[account][currency]} {currency}' ##
- booking_lines += [{'acc': booking_line[0], 'money':money, 'comment':balance}] ##
- elements_to_write += [self.booking_tmpl.render(
- start=booking.start_line,
- end=booking_end,
- date=booking.date_string,
- desc=booking.description,
- head_comment=db.comments[booking.start_line],
- steps_after_date=nth_of_same_date,
- booking_lines = booking_lines)]
- return '\n'.join(elements_to_write)
-