home · contact · privacy
On TransferLine input, default currency to '€' if amount provided.
authorChristian Heller <c.heller@plomlompom.de>
Tue, 28 Jan 2025 10:54:34 +0000 (11:54 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Tue, 28 Jan 2025 10:54:34 +0000 (11:54 +0100)
ledger.py
templates/edit_structured.tmpl

index 26272373982c92523d331f697fe3732261e34426..a553fc2a46791cd6e1d0705c7d9cceea80d86160 100755 (executable)
--- 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
index a3200886d43ceba14cb35c09ff0c114e555a32fd..6e31d91632ba04999d3c2101f7564183d754e4a8 100644 (file)
@@ -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)
     }