Commit 630695cf authored by Laurent Peuch's avatar Laurent Peuch
Browse files

[enh] ulpoad works in french

parent 29a524cf
......@@ -6,6 +6,22 @@ from django.db import transaction
from .models import Movement
nl_to_fr = {
"Ref. v/d verrichting": "R\xe9f\xe9rence de l'op\xe9ration",
"Datum v. verrichting": "Date d'op\xe9ration",
"Bedrag v/d verrichting": "Montant de l'op\xe9ration",
"Naam v/d tegenpartij :": 'Nom de la contrepartie :',
"Mededeling 1 :": 'Communication 1 :',
"Rekening tegenpartij": 'Compte de contrepartie',
}
def fr_or_nl(entry, key):
if key in entry:
return entry[key]
return entry[nl_to_fr[key]]
def handle_recordbank_csv(csv_file):
for_report = {
"movement_that_might_be_the_same": [],
......@@ -17,9 +33,9 @@ def handle_recordbank_csv(csv_file):
with transaction.atomic():
for entry in csv.DictReader(StringIO("\r\n".join(csv_file.read().split("\n")[1:]) + "\r\n"), delimiter=";"):
movement = Movement()
movement.bank_id = entry["Valutadatum"]
movement.date = datetime.strptime(entry["Datum v. verrichting"], "%d-%m-%Y").date()
movement.amount = float(entry["Bedrag v/d verrichting"].replace(".", "").replace(",", ".")) + (int(entry["Munt"]) * 0.01)
movement.bank_id = fr_or_nl(entry, "Ref. v/d verrichting")
movement.date = datetime.strptime(fr_or_nl(entry, "Datum v. verrichting"), "%d-%m-%Y").date()
movement.amount = float(fr_or_nl(entry, "Bedrag v/d verrichting").replace(".", "").replace(",", "."))
if movement.amount < 0:
movement.kind = "debit"
......@@ -31,13 +47,13 @@ def handle_recordbank_csv(csv_file):
else:
movement.kind = "credit"
movement.comment = "From: %s\nCommunication: '%s'" % (entry["Naam v/d tegenpartij :"], entry["Mededeling 1 :"])
movement.comment = "From: %s\nCommunication: '%s'" % (fr_or_nl(entry, "Naam v/d tegenpartij :"), fr_or_nl(entry, "Mededeling 1 :"))
movement.title = "FIXME"
# I've already imported this movement, don't do anything
if Movement.objects.filter(bank_id=entry["Ref. v/d verrichting"]).exists():
for_report["skip_because_already_imported"].append(Movement.objects.get(bank_id=entry["Ref. v/d verrichting"]))
if Movement.objects.filter(bank_id=fr_or_nl(entry, "Ref. v/d verrichting")).exists():
for_report["skip_because_already_imported"].append(Movement.objects.get(bank_id=fr_or_nl(entry, "Ref. v/d verrichting")))
continue
movement_that_might_be_the_same = Movement.objects.filter(date=movement.date, amount=movement.amount, kind=movement.kind, bank_id__isnull=True)
......@@ -52,7 +68,7 @@ def handle_recordbank_csv(csv_file):
for_report["need_title"].append(movement)
else:
movement.title = title
for_report["guessed_title"].append((movement, entry["Mededeling 1 :"], entry["Naam v/d tegenpartij :"]))
for_report["guessed_title"].append((movement, fr_or_nl(entry, "Mededeling 1 :"), fr_or_nl(entry, "Naam v/d tegenpartij :")))
movement.save()
......@@ -60,10 +76,10 @@ def handle_recordbank_csv(csv_file):
def guess_title(movement, entry):
if movement.kind == "debit" and entry["Rekening tegenpartij"] == "BE52 6528 3497 8409":
if movement.kind == "debit" and fr_or_nl(entry, "Rekening tegenpartij") == "BE52 6528 3497 8409":
return "Frais Bancaires"
if movement.kind == "debit" and entry["Rekening tegenpartij"] == "GB24 MIDL 4005 1570 5243 70":
if movement.kind == "debit" and fr_or_nl(entry, "Rekening tegenpartij") == "GB24 MIDL 4005 1570 5243 70":
return "Commande Olimex UK"
if movement.kind == "debit":
......@@ -71,7 +87,7 @@ def guess_title(movement, entry):
# everything is a credit starting from here
title = entry["Mededeling 1 :"]
title = fr_or_nl(entry, "Mededeling 1 :")
if movement.amount in (6, 8, 10):
return "Redevance VPN"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment