Skip to content

Commit

Permalink
Merge pull request #66 from Dr-Nuke/fix_revolut
Browse files Browse the repository at this point in the history
fixed new revolut csv export format
  • Loading branch information
tarioch authored May 29, 2022
2 parents 8a69655 + ecbc016 commit 24c5b86
Showing 1 changed file with 27 additions and 34 deletions.
61 changes: 27 additions & 34 deletions src/tariochbctools/importers/revolut/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,47 +26,39 @@ def file_account(self, file):

def extract(self, file, existing_entries):
entries = []
has_balance = False

with StringIO(file.contents()) as csvfile:
reader = csv.DictReader(
csvfile,
[
"Date",
"Reference",
"PaidOut",
"PaidIn",
"ExchangeOut",
"ExchangeIn",
"Balance",
"Category",
"Type",
"Product",
"Started Date",
"Completed Date",
"Description",
"Amount",
"Fee",
"Currency",
"State",
"Balance",

],

delimiter=",",
skipinitialspace=True,
)
next(reader)
for row in reader:
metakv = {
"category": row["Category"].strip(),
}
exchangeIn = row["ExchangeIn"].strip()
exchangeOut = row["ExchangeOut"].strip()
if exchangeIn and exchangeOut:
metakv["originalIn"] = exchangeIn
metakv["originalOut"] = exchangeOut
elif exchangeIn:
metakv["original"] = exchangeIn
elif exchangeOut:
metakv["original"] = exchangeOut
metakv = {}

book_date = parse(row["Date"].strip()).date()


try:
credit = D(row["PaidIn"].replace("'", "").strip())
debit = D(row["PaidOut"].replace("'", "").strip())
bal = D(row["Balance"].replace("'", "").strip())
amt = amount.Amount(credit - debit, self.currency)
amount_raw = D(row["Amount"].replace("'", "").strip())
amt = amount.Amount(amount_raw, row["Currency"])
balance = amount.Amount(bal, self.currency)
book_date = parse(row["Completed Date"].strip()).date()
except Exception as e:
logging.warning(e)
continue
Expand All @@ -77,7 +69,7 @@ def extract(self, file, existing_entries):
book_date,
"*",
"",
row["Reference"].strip(),
row["Description"].strip(),
data.EMPTY_SET,
data.EMPTY_SET,
[
Expand All @@ -86,13 +78,14 @@ def extract(self, file, existing_entries):
)
entries.append(entry)

# only add balance after the top (newest) transaction
if not has_balance:
book_date = book_date + timedelta(days=1)
entry = data.Balance(
meta, book_date, self.account, balance, None, None
)
entries.append(entry)
has_balance = True
# only add balance after the last (newest) transaction
try:
book_date = book_date + timedelta(days=1)
entry = data.Balance(
meta, book_date, self.account, balance, None, None
)
entries.append(entry)
except NameError:
pass

return entries

0 comments on commit 24c5b86

Please sign in to comment.