From 706f069fb4d4a79366160c6e4547ca61f5b37379 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Wed, 16 Apr 2025 04:39:35 +0200 Subject: [PATCH] Fix breakage of block copying. --- src/ledgplom/ledger.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/ledgplom/ledger.py b/src/ledgplom/ledger.py index f7f70e7..00db77d 100644 --- a/src/ledgplom/ledger.py +++ b/src/ledgplom/ledger.py @@ -114,6 +114,7 @@ class Account: class _DatLine: """Line of .dat file parsed into comments and machine-readable data.""" + to_copy = ['code', 'comment'] def __init__( self, @@ -134,8 +135,10 @@ class _DatLine: 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: @@ -211,6 +214,7 @@ class _BookingLine(_DatLineSubclass): 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__( @@ -251,19 +255,20 @@ class _IntroLine(_BookingLine): 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 -- 2.30.2