X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/d25e1c6ed14aa17a3fb5e8147355ee63ed5c5c3d..b8c235267a6345ebe3891f49c16ad3fc5f1d3f25:/src/pz/bank.py diff --git a/src/pz/bank.py b/src/pz/bank.py index 40b985a13..de22ac0c8 100644 --- a/src/pz/bank.py +++ b/src/pz/bank.py @@ -1,4 +1,5 @@ import csv +from datetime import datetime from io import StringIO from django.conf import settings from django.http import HttpResponse @@ -10,19 +11,6 @@ def bank_export(modeladmin, request, queryset): response = HttpResponse(content_type='text/csv; charset=cp1250') response['Content-Disposition'] = 'attachment; filename=export.csv' writer = csv.writer(response) - writer.writerow([ - 'Identyfikator płatności (IDP)', - 'Nazwa Płatnika', - '', - 'Adres Płatnika Ulica + numer domu', - 'Adres Płatnika kod+miejscowość', - 'Numer kierunkowy banku Płatnika', - 'Numer rachunku bankowego Płatnika', - 'Identyfikator Odbiorcy (NIP Odbiorcy)', - 'Osobowość prawna Płatnika (Osoba fizyczna)' - ]) - - # TODO: ansi encoding for obj in queryset: writer.writerow([ @@ -39,7 +27,27 @@ def bank_export(modeladmin, request, queryset): return response +def parse_payment_feedback(f): + lines = csv.reader(StringIO(f.read().decode('cp1250'))) + for line in lines: + print(line) + assert line[0] in ('1', '2') + if line[0] == '1': + # Totals line. + continue + booking_date = line[3] + booking_date = datetime.strptime(booking_date, '%Y%m%d') + payment_id = line[7] + is_dd = line[16] == 'DD' + realised = line[17] == '1' + reject_code = line[18] + yield payment_id, booking_date, is_dd, realised, reject_code + + + + def parse_export_feedback(f): + # The AU file. lines = csv.reader(StringIO(f.read().decode('cp1250'))) for line in lines: payment_id = line[0] @@ -48,6 +56,8 @@ def parse_export_feedback(f): yield payment_id, status, comment + + def bank_order(date, sent_at, queryset): response = HttpResponse(content_type='application/octet-stream') response['Content-Disposition'] = 'attachment; filename=order.PLD'