]> git.walde.dev - beanbeanbean/commitdiff
Fix repeated txn to not share meta/postings dicts
authorDustin Walde <redacted>
Mon, 13 Nov 2023 01:17:51 +0000 (17:17 -0800)
committerDustin Walde <redacted>
Mon, 13 Nov 2023 01:17:51 +0000 (17:17 -0800)
src/beanbeanbean/recurring.py

index 22061127e0ce0f78e1124b4287a393c056b82e5b..adca9e631abd85e7e265c4a1770b9d60ad1492ff 100644 (file)
@@ -113,6 +113,7 @@ def handle_recurring_transaction(txn: Transaction, format_token: str) -> Union[L
             balances = {}
             for j, posting in enumerate(txn.postings):
                 post_dict = posting._asdict()
+                post_dict["meta"] = dict(posting.meta)
                 remaining = post_vals[j]
 
                 amortized_cost = None
@@ -158,16 +159,18 @@ def handle_recurring_transaction(txn: Transaction, format_token: str) -> Union[L
                                 post['units'] = amount.sub(post['units'], remainder)
                                 break
 
-            for pd in new_txn_dict["postings"]:
+            for j, pd in enumerate(new_txn_dict["postings"]):
                 if pd['cost'] is not None:
                     pd['cost'] = position.Cost(pd['cost'].number, pd['cost'].currency, txn.date, 'amortized')
                 for k, v in pd["meta"].items():
                     if type(v) is str:
                         pd["meta"][k] = new_txn_dict["date"].strftime(v)
-                new_txn_dict["postings"].append(Posting(**pd))
+                new_txn_dict["postings"][j] = Posting(**pd)
         else:
             for posting in txn.postings:
-                new_txn_dict["postings"].append(posting)
+                pd = posting._asdict()
+                pd["meta"] = dict(posting.meta)
+                new_txn_dict["postings"].append(Posting(**pd))
 
         new_date = new_txn_dict["date"]
         new_meta = new_txn_dict["meta"]