From 09b254d307fddf44b7410e2b73a10ef0e151fd7c Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Tue, 28 Jan 2025 11:54:34 +0100 Subject: [PATCH] =?utf8?q?On=20TransferLine=20input,=20default=20currency?= =?utf8?q?=20to=20'=E2=82=AC'=20if=20amount=20provided.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- ledger.py | 8 ++++---- templates/edit_structured.tmpl | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ledger.py b/ledger.py index 2627237..a553fc2 100755 --- a/ledger.py +++ b/ledger.py @@ -173,18 +173,18 @@ class TransferLine(BookingLine): def __init__(self, booking: 'Booking', code: str) -> None: super().__init__(booking) self.currency = '' + self.amount: Optional[Decimal] = None if not code[0].isspace(): self.errors += ['transfer line not indented'] toks = code.lstrip().split() self.account = toks[0] - self.amount: Optional[Decimal] = None - if 3 <= len(toks): - self.currency = toks[2] + if len(toks) > 1: + self.currency = toks[2] if 3 == len(toks) else '€' try: self.amount = Decimal(toks[1]) except DecimalInvalidOperation: self.errors += [f'improper amount value: {toks[1]}'] - if len(toks) not in {1, 3}: + if len(toks) > 3: self.errors += ['illegal number of tokens'] @property diff --git a/templates/edit_structured.tmpl b/templates/edit_structured.tmpl index a320088..6e31d91 100644 --- a/templates/edit_structured.tmpl +++ b/templates/edit_structured.tmpl @@ -33,12 +33,13 @@ function update_form() { const dat_line = dat_lines[i]; const tr = document.createElement("tr"); table.appendChild(tr); - function add_input(name, value, colspan=1) { + function add_input(name, value, colspan=1, placeholder='') { const td = add_td(tr, colspan); const input = document.createElement("input"); td.appendChild(input); input.name = `line_${i}_${name}` input.value = value.trim(); + input.placeholder = placeholder; input.onchange = taint; if (dat_line.error) { td.classList.add("invalid"); @@ -50,7 +51,7 @@ function update_form() { } else if (!dat_line.error) { add_input('account', dat_line.booking_line.account); add_input('amount', dat_line.booking_line.amount == 'None' ? '' : dat_line.booking_line.amount); - add_input('currency', dat_line.booking_line.currency); + add_input('currency', dat_line.booking_line.currency, 1, '€'); } else { add_input('error', dat_line.code, 3) } -- 2.30.2