Skip to content

Commit

Permalink
[Revolut] Import the fees from the CSV
Browse files Browse the repository at this point in the history
This work uses #105 by Dr-Nuke
  • Loading branch information
alvarogarcia7 committed Jul 27, 2024
1 parent 6d8f1a6 commit 928b84d
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/tariochbctools/importers/revolut/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
class Importer(identifier.IdentifyMixin, importer.ImporterProtocol):
"""An importer for Revolut CSV files."""

def __init__(self, regexps, account, currency):
def __init__(self, regexps, account, currency, fee=None):
identifier.IdentifyMixin.__init__(self, matchers=[("filename", regexps)])
self.account = account
self.currency = currency
self._fee = fee

def name(self):
return super().name() + self.account
Expand Down Expand Up @@ -53,10 +54,25 @@ def extract(self, file, existing_entries):
amt = amount.Amount(amount_raw, row["Currency"])
balance = amount.Amount(bal, self.currency)
book_date = parse(row["Completed Date"].strip()).date()
fee_amt_raw = D(row["Fee"].replace("'", "").strip())
fee = amount.Amount(-fee_amt_raw, row["Currency"])
except Exception as e:
logging.warning(e)
continue

postings = [
data.Posting(self.account, amt, None, None, None, None),
]
if self._fee is not None and self.is_non_zero(fee_amt_raw):
postings.extend(
[
data.Posting(self.account, fee, None, None, None, None),
data.Posting(
self._fee["account"], -fee, None, None, None, None
),
]
)

entry = data.Transaction(
data.new_metadata(file.name, 0, {}),
book_date,
Expand All @@ -65,9 +81,7 @@ def extract(self, file, existing_entries):
row["Description"].strip(),
data.EMPTY_SET,
data.EMPTY_SET,
[
data.Posting(self.account, amt, None, None, None, None),
],
postings,
)
entries.append(entry)

Expand All @@ -87,3 +101,7 @@ def extract(self, file, existing_entries):
pass

return entries

@staticmethod
def _is_non_zero(raw):
return abs(float(raw) - 0.00) > 1e-9

0 comments on commit 928b84d

Please sign in to comment.