Add count to specify how often a mapping is used

This commit is contained in:
2025-03-02 13:44:43 -05:00
parent 078bf07d0f
commit 35e1c1039e
3 changed files with 22 additions and 42 deletions

View File

@@ -67,19 +67,21 @@ def write_meta(config: Config):
def write_mappings(transactions: List[Transaction], mappings_file: Path):
"""Write transactions to the mappings file."""
mappings = {}
for t in transactions:
mapping = Mapping(
**{
"account2": t.account2.strip(),
}
)
if t.narration:
mapping.narration = t.narration
if t.payee:
mapping.payee = t.payee
mappings[t.row] = mapping.dict()
mappings = read_mappings(mappings_file)
for t in transactions:
if t.row in mappings:
pass
else:
mapping = Mapping(
**{
"account2": t.account2.strip(),
"narration": t.description,
}
)
mappings[t.row] = mapping
mappings = {k: v.dict() for k, v in mappings.items()}
with open(mappings_file, "w") as f:
json.dump(mappings, f, indent=4)