X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/d96e1d2348113e3fc0c7961d83d278933d090a6d..d25e1c6ed14aa17a3fb5e8147355ee63ed5c5c3d:/src/pz/bank.py diff --git a/src/pz/bank.py b/src/pz/bank.py index 683767281..40b985a13 100644 --- a/src/pz/bank.py +++ b/src/pz/bank.py @@ -48,13 +48,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.') @@ -64,8 +65,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: ' @@ -85,6 +88,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: