X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/6753452b63d937fd05ad485edc650565f5fa064e..9d763695198b109f00b5d88a5cfe0190871271aa:/src/pz/bank.py?ds=inline diff --git a/src/pz/bank.py b/src/pz/bank.py index 0c75c7b53..d5eef931f 100644 --- a/src/pz/bank.py +++ b/src/pz/bank.py @@ -1,9 +1,10 @@ import csv +from datetime import datetime from io import StringIO from django.conf import settings from django.http import HttpResponse from django.utils.safestring import mark_safe -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ def bank_export(modeladmin, request, queryset): @@ -26,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] @@ -35,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'