generated from felixm/defaultpy
Add count to specify how often a mapping is used
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user