Skip to content

Commit

Permalink
CHANGE handle merging operations across several files as warning inst…
Browse files Browse the repository at this point in the history
…ead of error; ignore operations with special remarks
  • Loading branch information
provinzio committed Dec 14, 2024
1 parent da9f5b2 commit 38b8435
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions src/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,6 @@ def identical_to(self, op: Operation) -> bool:
identical_to = all(
getattr(self, i) == getattr(op, i) for i in self.identical_columns
)

if identical_to:
assert (
self.file_path == op.file_path
), "Identical operations should also be in the same file."

return identical_to

@staticmethod
Expand All @@ -129,6 +123,33 @@ def merge(*operations: Operation) -> Operation:
op1.identical_to(op2) for op1, op2 in itertools.combinations(operations, 2)
), "Operations have to be identical to be merged"

# Warn when mergeing across multiple files.
# Ignore `Korrekturbuchung.`
if (
len(
set(
[
op.file_path
for op in operations
if not op.remark.startswith("Korrekturbuchung.")
]
)
)
> 1
):
log.warning(
"Identical operations will be merged across several files. "
"This normally only happens if a transaction occurs incorrectly "
"in several files. Please check if you have duplicate transactions "
"in your files:\n"
+ (
"\n".join(
f" - {op.utc_time} {op.coin} {op.change} {op.file_path} [{op.line}] "
for op in operations
)
)
)

# Select arbitray operation from list.
o = copy(operations[0])
# Update this operation with merged entries.
Expand Down

0 comments on commit 38b8435

Please # to comment.