class _DatLine:
"""Line of .dat file parsed into comments and machine-readable data."""
+ to_copy = ['code', 'comment']
def __init__(
self,
return self.code + ' ; '.join([''] + [s for s in [self.comment] if s])
def copy(self) -> Self:
- """Create new _DatLine of same .code and .comment."""
- return self.__class__(self.code, self.comment)
+ """Create new instance copying the fields named in .to_copy."""
+ kwargs = {fieldname: getattr(self, fieldname)
+ for fieldname in self.to_copy}
+ return self.__class__(**kwargs)
@classmethod
def from_raw(cls, line: str) -> Self:
class _IntroLine(_BookingLine):
"""First line of a _Booking, expected to carry date etc."""
+ to_copy = ['date', 'target', 'comment']
dictables = {'date', 'target'} | _BookingLine.dictables
def __init__(
class _TransferLine(_BookingLine):
"""Non-first _Booking line, expected to carry value movement."""
+ to_copy = ['account', 'amount', 'currency', 'comment']
dictables = {'amount', 'account', 'currency'} | _BookingLine.dictables
def __init__(
self,
account: str,
- amount_str: str,
+ amount: str,
currency: str,
comment: str = '',
errors: Optional[list[str]] = None
) -> None:
super().__init__(comment, errors)
self.account = account
- self._amount_str = amount_str
+ self._amount_str = amount
self.currency = currency
@property