home · contact · privacy
Fix breakage of block copying.
authorChristian Heller <c.heller@plomlompom.de>
Wed, 16 Apr 2025 02:39:35 +0000 (04:39 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 16 Apr 2025 02:39:35 +0000 (04:39 +0200)
src/ledgplom/ledger.py

index f7f70e786db1e6bae78dba4c1e11a571c8417839..00db77da3afc87f9715fb9e5caf610b30f6af9bd 100644 (file)
@@ -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