Skip to content

Commit

Permalink
Merge pull request #121 from tarioch/feature/include_duplicate
Browse files Browse the repository at this point in the history
Implement deduplication based on references for the importers that ha…
  • Loading branch information
tarioch authored Jan 3, 2025
2 parents fd09e6f + a1d9982 commit 3a466cb
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/tariochbctools/importers/bitst/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from dateutil.parser import parse
from dateutil.relativedelta import relativedelta

from tariochbctools.importers.general.deduplication import ReferenceDuplicatesComparator
from tariochbctools.importers.general.priceLookup import PriceLookup


Expand Down Expand Up @@ -166,3 +167,5 @@ def fetchSingle(self, trx: dict[str, Any]) -> data.Transaction:
return data.Transaction(
meta, date, "*", "", narration, data.EMPTY_SET, data.EMPTY_SET, postings
)

cmp = ReferenceDuplicatesComparator()
3 changes: 3 additions & 0 deletions src/tariochbctools/importers/blockchain/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from beancount.core import amount, data
from beancount.core.number import D

from tariochbctools.importers.general.deduplication import ReferenceDuplicatesComparator
from tariochbctools.importers.general.priceLookup import PriceLookup


Expand Down Expand Up @@ -66,3 +67,5 @@ def extract(self, filepath: str, existing: data.Entries) -> data.Entries:
entries.append(entry)

return entries

cmp = ReferenceDuplicatesComparator()
14 changes: 14 additions & 0 deletions src/tariochbctools/importers/general/deduplication.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class ReferenceDuplicatesComparator:
def __init__(self, refs=["ref"]):
self.refs = refs

def __call__(self, entry1, entry2):
entry1Refs = set()
entry2Refs = set()
for ref in self.refs:
if ref in entry1.meta:
entry1Refs.add(entry1.meta[ref])
if ref in entry2.meta:
entry2Refs.add(entry2.meta[ref])

return entry1Refs & entry2Refs
4 changes: 4 additions & 0 deletions src/tariochbctools/importers/general/mt940importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from beancount.core import amount, data
from beancount.core.number import D

from tariochbctools.importers.general.deduplication import ReferenceDuplicatesComparator


class Importer(beangulp.Importer):
"""An importer for MT940 files."""
Expand Down Expand Up @@ -60,6 +62,8 @@ def extract(self, filepath: str, existing: data.Entries) -> data.Entries:

return entries

cmp = ReferenceDuplicatesComparator()

def prepare_payee(self, trxdata: dict[str, Any]) -> str:
return ""

Expand Down
4 changes: 4 additions & 0 deletions src/tariochbctools/importers/nordigen/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from beancount.core import amount, data
from beancount.core.number import D

from tariochbctools.importers.general.deduplication import ReferenceDuplicatesComparator


class HttpServiceException(Exception):
pass
Expand Down Expand Up @@ -105,3 +107,5 @@ def extract(self, filepath: str, existing: data.Entries) -> data.Entries:
entries.append(entry)

return entries

cmp = ReferenceDuplicatesComparator(["nordref"])
4 changes: 4 additions & 0 deletions src/tariochbctools/importers/transferwise/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from beancount.core.number import D
from dateutil.relativedelta import relativedelta

from tariochbctools.importers.general.deduplication import ReferenceDuplicatesComparator

http = urllib3.PoolManager()


Expand Down Expand Up @@ -183,3 +185,5 @@ def extract(self, filepath, existing):
entries.append(entry)

return entries

cmp = ReferenceDuplicatesComparator()
4 changes: 4 additions & 0 deletions src/tariochbctools/importers/zak/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from beancount.core.number import D
from dateutil.parser import parse

from tariochbctools.importers.general.deduplication import ReferenceDuplicatesComparator


class Importer(beangulp.Importer):
"""An importer for Bank Cler ZAK PDF files files."""
Expand Down Expand Up @@ -127,3 +129,5 @@ def extract(self, filepath: str, existing: data.Entries) -> data.Entries:
entries.append(self.createBalanceEntry(filepath, date, saldo))

return entries

cmp = ReferenceDuplicatesComparator(["zakref"])

0 comments on commit 3a466cb

Please sign in to comment.