X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/5fb53c16b8de6efee032dea734dd9047f33d3d54..df60910b2d457f031cbe0a153e51e7378c0165d8:/src/pz/bank.py?ds=sidebyside diff --git a/src/pz/bank.py b/src/pz/bank.py index e7788cdbd..0c75c7b53 100644 --- a/src/pz/bank.py +++ b/src/pz/bank.py @@ -10,23 +10,12 @@ 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([ obj.payment_id, obj.full_name, + '', obj.street_address, ' '.join([obj.postal_code, obj.town]).strip(), obj.iban[2:10], @@ -46,13 +35,14 @@ def parse_export_feedback(f): yield payment_id, status, comment -def bank_order(date, queryset): +def bank_order(date, sent_at, queryset): response = HttpResponse(content_type='application/octet-stream') response['Content-Disposition'] = 'attachment; filename=order.PLD' rows = [] no_dates = [] no_amounts = [] + cancelled = [] if date is None: raise ValueError('Payment date not set yet.') @@ -62,8 +52,10 @@ def bank_order(date, queryset): no_dates.append(debit) if debit.amount is None: no_amounts.append(debit) + if debit.cancelled_at and debit.cancelled_at.date() <= date and (sent_at is None or debit.cancelled_at < sent_at): + cancelled.append(debit) - if no_dates or no_amounts: + if no_dates or no_amounts or cancelled: t = '' if no_dates: t += 'Bank acceptance not received for: ' @@ -83,6 +75,15 @@ def bank_order(date, queryset): for debit in no_amounts ) t += '. ' + if cancelled: + t += 'Debits have been cancelled: ' + t += ', '.join( + '{}'.format( + debit.pk, debit + ) + for debit in cancelled + ) + t += '. ' raise ValueError(mark_safe(t)) for debit in queryset: