Bankimport: Handle thousand seperator

This commit is contained in:
Raphael Michel
2016-09-19 19:23:36 +02:00
parent 8aa1d74609
commit 531d4b0ce9
2 changed files with 23 additions and 1 deletions
+8 -1
View File
@@ -65,7 +65,14 @@ def _get_unknown_transactions(event: Event, job: BankImportJob, data: list):
transactions = []
for row in data:
amount = amount_pattern.sub("", row['amount'].replace(",", "."))
amount = row['amount']
if ',' in amount and '.' in amount:
# Handle thousand-seperator , or .
if amount.find(',') < amount.find('.'):
amount = amount.replace(',', '')
else:
amount = amount.replace('.', '')
amount = amount_pattern.sub("", amount.replace(',', '.'))
try:
amount = Decimal(amount)
except:
@@ -1,4 +1,5 @@
from datetime import timedelta
from decimal import Decimal
import pytest
from bs4 import BeautifulSoup
@@ -133,3 +134,17 @@ def test_autocorrection(env, job):
}])
env[2].refresh_from_db()
assert env[2].status == Order.STATUS_PAID
@pytest.mark.django_db
def test_huge_amount(env, job):
env[2].total = Decimal('23000.00')
env[2].save()
process_banktransfers(env[0].pk, job, [{
'payer': 'Karla Kundin',
'reference': 'Bestellung DUMMY12345',
'amount': '23.000,00',
'date': '2016-01-26',
}])
env[2].refresh_from_db()
assert env[2].status == Order.STATUS_PAID