Fix CSV processing

This commit is contained in:
Tobias Kunze 2018-01-11 20:20:05 +01:00
parent 71c4b7e42f
commit 17c70e03a6

View File

@ -4,15 +4,17 @@ from datetime import date, datetime, timedelta
from decimal import Decimal from decimal import Decimal
from django.db import transaction from django.db import transaction
from django.dispatch import receiver
from django.utils.timezone import now from django.utils.timezone import now
from byro.bookkeeping.models import RealTransaction, TransactionChannel from byro.bookkeeping.models import RealTransaction, TransactionChannel
from byro.bookkeeping.signals import derive_virtual_transactions
from byro.members.models import Member from byro.members.models import Member
@transaction.atomic @transaction.atomic
def process_bank_csv(self, source): def process_bank_csv(source):
reader = csv.DictReader(source.source_file.name, encoding='iso-8859-1', delimiter=';', quotechar='"') reader = csv.DictReader(open(source.source_file.name, encoding='iso-8859-1'), delimiter=';', quotechar='"')
booking_timestamp = now() booking_timestamp = now()
for line in reader: for line in reader:
@ -21,7 +23,7 @@ def process_bank_csv(self, source):
reference = '' reference = ''
for key in line.keys(): for key in line.keys():
if key.startswith('VWZ'): if key.startswith('VWZ'):
reference += d[key] + ' ' reference += line[key] + ' '
RealTransaction.objects.create( RealTransaction.objects.create(
channel=TransactionChannel.BANK, channel=TransactionChannel.BANK,
@ -29,7 +31,7 @@ def process_bank_csv(self, source):
value_datetime=datetime.strptime(line.get('Buchungstag'), '%d.%m.%Y'), value_datetime=datetime.strptime(line.get('Buchungstag'), '%d.%m.%Y'),
amount=Decimal(line.get('Betrag').replace('.', '').replace(',', '.')), amount=Decimal(line.get('Betrag').replace('.', '').replace(',', '.')),
purpose=reference, purpose=reference,
originator=line.get('Auftraggeber/Empfänger'), originator=line.get('Auftraggeber/Empfänger', '<leer>'),
importer='shack_bank_csv_importer', importer='shack_bank_csv_importer',
source=source, source=source,
data=line, data=line,