From: Christian Heller Date: Tue, 28 Jan 2025 10:54:34 +0000 (+0100) Subject: On TransferLine input, default currency to '€' if amount provided. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/static/%7B%7B%20web_path%20%7D%7D/%7B%7Bprefix%7D%7D/todos?a=commitdiff_plain;h=09b254d307fddf44b7410e2b73a10ef0e151fd7c;p=plomledger On TransferLine input, default currency to '€' if amount provided. --- 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) }