return '; '.join(self.booking_line.errors) if self.booking_line else ''
@property
- def questionable(self) -> bool:
+ def is_questionable(self) -> bool:
"""Return whether line be questionable per associated Booking."""
- return (self.booking_line.booking.questionable if self.booking_line
+ return (self.booking_line.booking.is_questionable if self.booking_line
else False)
@property
self.errors += ['illegal number of tokens']
if len(toks) < 1:
return
+ self.date = '#'
try:
dt_date.fromisoformat(toks[0])
except ValueError:
self.errors += [f'not properly formatted legal date: {toks[0]}']
+ else:
+ self.date = toks[0]
class TransferLine(BookingLine):
# pylint: disable=too-few-public-methods
def __init__(self, id_: int, dat_lines: list[DatLine]) -> None:
- dat_lines[0].booking_line = IntroLine(self, dat_lines[0].code)
- intro_line = dat_lines[0].booking_line
- transfer_lines = []
+ self.intro_line = IntroLine(self, dat_lines[0].code)
+ dat_lines[0].booking_line = self.intro_line
+ self._transfer_lines = []
for dat_line in dat_lines[1:]:
dat_line.booking_line = TransferLine(self, dat_line.code)
- transfer_lines += [dat_line.booking_line]
+ self._transfer_lines += [dat_line.booking_line]
changes = Wealth()
self.account_changes: dict[str, Wealth] = {}
self.sink_account = None
- for transfer_line in [tl for tl in transfer_lines if not tl.errors]:
+ for transfer_line in [tl for tl in self._transfer_lines
+ if not tl.errors]:
if transfer_line.account not in self.account_changes:
self.account_changes[transfer_line.account] = Wealth()
if transfer_line.amount is None:
if self.sink_account:
self.account_changes[self.sink_account] += changes.as_sink
elif not changes.sink_empty:
- transfer_lines[-1].errors += ['needed sink missing']
- self.questionable = False
- for _ in [bl for bl in [intro_line] + transfer_lines if bl.errors]:
- self.questionable = True
- break
+ self._transfer_lines[-1].errors += ['needed sink missing']
self.id_ = id_
self.dat_lines = dat_lines
+ @property
+ def is_questionable(self) -> bool:
+ """Whether lines count any errors."""
+ for _ in [bl for bl in [self.intro_line] + self._transfer_lines
+ if bl.errors]:
+ return True
+ return False
+
class Handler(PlomHttpHandler):
# pylint: disable=missing-class-docstring
for line in path_dat.read_text(encoding='utf8').splitlines()]
self.bookings: list[Booking] = []
booking_lines: list[DatLine] = []
+ last_date = ''
for dat_line in self.dat_lines + [DatLine('')]:
if dat_line.code:
booking_lines += [dat_line]
elif booking_lines:
- self.bookings += [Booking(len(self.bookings), booking_lines)]
+ booking = Booking(len(self.bookings), booking_lines)
+ if last_date > booking.intro_line.date:
+ booking.intro_line.errors += ['date < previous valid date']
+ else:
+ last_date = booking.intro_line.date
+ self.bookings += [booking]
booking_lines = []
@property