From: Christian Heller Date: Mon, 2 Feb 2026 05:08:14 +0000 (+0100) Subject: Reasonably auto-indent amount and currency. X-Git-Url: https://plomlompom.com/repos/booking/%7B%7B%20web_path%20%7D%7D/%7B%7Bdb.prefix%7D%7D/%7B%7Bprefix%7D%7D/static/do_todos?a=commitdiff_plain;p=ledgplom Reasonably auto-indent amount and currency. --- diff --git a/src/ledgplom/http.py b/src/ledgplom/http.py index 480ff51..2198a94 100644 --- a/src/ledgplom/http.py +++ b/src/ledgplom/http.py @@ -68,18 +68,47 @@ class _Handler(PlomHttpHandler): if lineno not in lineno_to_inputs: lineno_to_inputs[lineno] = [] lineno_to_inputs[lineno] += [toks[2]] + booking_comments: list[str] = [] + booking_lines_items: list[tuple[int, int, int, str, str, str]] = [] + idx_amt_dot_max = 0 + len_from_dot_max = 0 for lineno, input_names in lineno_to_inputs.items(): inputs = {key: self.postvars.first(f'line_{lineno}_{key}') for key in input_names} if 0 == lineno: - line_raw = inputs['date'] + SPACE + inputs['target'] + intro_line_items = inputs['date'], inputs['target'] else: - line_raw = ( - SPACE * int(inputs['len_indent']) - + inputs['account'] + SPACE * 2 - + inputs['amount'] + SPACE + inputs['currency']) - if (comment := inputs['comment']): - line_raw += f'{SPACE}{SEP_COMMENTS}{SPACE}{comment}' + len_indent = int(inputs['len_indent']) + idx_amt_dot = (len_indent + + len(inputs['account']) + + len(inputs['amount'].split('.')[0]) + + 1) + len_from_dot = ((len(inputs['amount'].split('.')[1]) + 1) + if '.' in inputs['amount'] else 0) + idx_amt_dot_max = max(idx_amt_dot_max, idx_amt_dot) + len_from_dot_max = max(len_from_dot_max, len_from_dot) + booking_lines_items += [( + len_indent, + idx_amt_dot, + len_from_dot, + inputs['account'], + inputs['amount'], + inputs['currency'])] + booking_comments += [inputs['comment']] + for idx, comment in enumerate(booking_comments): + if 0 == idx: + line_raw = SPACE.join(intro_line_items) + else: + line_items = booking_lines_items[idx - 1] + line_raw = SPACE * line_items[0] # indent + line_raw += line_items[3] # account + line_raw += SPACE * (idx_amt_dot_max - line_items[1]) + line_raw += 2*SPACE + line_items[4] # amount + line_raw += SPACE * (len_from_dot_max - line_items[2]) + line_raw += SPACE + line_items[5] # currency + line_raw = line_raw.rstrip() + if comment: + line_raw = SPACE.join((line_raw, SEP_COMMENTS, comment)) new_lines += [line_raw] new_lines += self.postvars.first('raw_lines').splitlines() new_id = self.server.ledger.rewrite_block(old_id, new_lines) diff --git a/src/ledgplom/ledger.py b/src/ledgplom/ledger.py index c9bc62e..2a1ee59 100644 --- a/src/ledgplom/ledger.py +++ b/src/ledgplom/ledger.py @@ -531,9 +531,9 @@ class _DatBlock(_LinesBlock): copy = self.__class__() copy.add(tuple(_DatLine(line.raw) for line in self.gap_lines)) if self.booking: - copy.add((_DatLine(' '.join((dt_date.today().isoformat(), - self.booking.intro_line.target, - self.booking.intro_line.comment))), + copy.add((_DatLine(SPACE.join((dt_date.today().isoformat(), + self.booking.intro_line.target, + self.booking.intro_line.comment))), ), at_end=False) copy.add(tuple(_DatLine(line.raw)