self.error = 'not starting with properly formatted legal date'
-class TransactionLine(BookingLine):
+class TransferLine(BookingLine):
"""Non-first Booking line, expected to carry value movement."""
def __init__(self, booking_id: int, code: str) -> None:
super().__init__(booking_id)
- self.acc, self.amt, self.curr = '', '', ''
+ self.account, self.currency = '', ''
+ self.amount: Optional[Decimal] = None
if not code[0].isspace():
self.error = 'non-intro line not indented'
return
toks = code.lstrip().split()
- self.acc = toks[0]
+ self.account = toks[0]
if len(toks) not in {1, 3}:
self.error = 'illegal number of tokens'
return
if 3 == len(toks):
+ self.currency = toks[2]
try:
- amt_dec = Decimal(toks[1])
+ self.amount = Decimal(toks[1])
except DecimalInvalidOperation:
self.error = 'improper amount value'
return
- exp = amt_dec.as_tuple().exponent
+
+ @property
+ def amount_short(self) -> str:
+ """If no .amount, '', else printed – but if too long, ellipsized."""
+ if self.amount:
+ exp = self.amount.as_tuple().exponent
assert isinstance(exp, int)
- self.amt = (f'{amt_dec:.1f}…' if exp < -2
- else f'{amt_dec:.2f}')
- self.curr = toks[2]
+ return f'{self.amount:.1f}…' if exp < -2 else f'{self.amount:.2f}'
+ return ''
class Booking:
self.dat_lines[0].booking_line = IntroLine(self.id_,
self.dat_lines[0].code)
for dat_line in self.dat_lines[1:]:
- dat_line.booking_line = TransactionLine(self.id_, dat_line.code)
+ dat_line.booking_line = TransferLine(self.id_, dat_line.code)
class Handler(PlomHttpHandler):
{% if dat_line.is_intro %}
<td class="code{% if dat_line.error %} invalid{% endif %}" colspan=3><a href="/booking/{{dat_line.booking_id}}">{{dat_line.code}}</a></td>
{% elif not dat_line.error %}
- <td class="amt">{{dat_line.booking_line.amt}}</td>
- <td class="curr">{{dat_line.booking_line.curr|truncate(4,true,"…")}}</td>
- <td>{{dat_line.booking_line.acc}}</td>
+ <td class="amt">{{dat_line.booking_line.amount_short}}</td>
+ <td class="curr">{{dat_line.booking_line.currency|truncate(4,true,"…")}}</td>
+ <td>{{dat_line.booking_line.account}}</td>
{% else %}
<td class="invalid" colspan=3>{{dat_line.code}}</td>
{% endif %}