2 from io import StringIO
3 from django.conf import settings
4 from django.http import HttpResponse
5 from django.utils.safestring import mark_safe
6 from django.utils.translation import ugettext_lazy as _
9 def bank_export(modeladmin, request, queryset):
10 response = HttpResponse(content_type='text/csv; charset=cp1250')
11 response['Content-Disposition'] = 'attachment; filename=export.csv'
12 writer = csv.writer(response)
14 'Identyfikator płatności (IDP)',
16 'Adres Płatnika Ulica + numer domu',
17 'Adres Płatnika kod+miejscowość',
18 'Numer kierunkowy banku Płatnika',
19 'Numer rachunku bankowego Płatnika',
20 'Identyfikator Odbiorcy (NIP Odbiorcy)',
21 'Osobowość prawna Płatnika (Osoba fizyczna)'
31 ' '.join([obj.postal_code, obj.town]).strip(),
40 def parse_export_feedback(f):
41 lines = csv.reader(StringIO(f.read().decode('cp1250')))
46 yield payment_id, status, comment
49 def bank_order(date, queryset):
50 response = HttpResponse(content_type='application/octet-stream')
51 response['Content-Disposition'] = 'attachment; filename=order.PLD'
58 raise ValueError('Payment date not set yet.')
60 for debit in queryset:
61 if debit.bank_acceptance_date is None:
62 no_dates.append(debit)
63 if debit.amount is None:
64 no_amounts.append(debit)
66 if no_dates or no_amounts:
69 t += 'Bank acceptance not received for: '
71 '<a href="/admin/pz/directdebit/{}/change">{}</a>'.format(
78 t += 'Amount not set for: '
80 '<a href="/admin/pz/directdebit/{}/change">{}</a>'.format(
83 for debit in no_amounts
86 raise ValueError(mark_safe(t))
88 for debit in queryset:
90 '{order_code},{date},{amount},{dest_bank_id},0,"{dest_iban}","{user_iban}",'
91 '"{dest_addr}","{user_addr}",0,{user_bank_id},'
92 '"/NIP/{dest_nip}/IDP/{payment_id}|/TXT/{payment_desc}||",'
95 date=date.strftime('%Y%m%d'),
97 amount=debit.amount * 100,
98 dest_bank_id=settings.PZ_IBAN[2:10],
99 dest_iban=settings.PZ_IBAN,
100 user_iban=debit.iban,
101 dest_addr=settings.PZ_ADDRESS_STRING,
102 user_bank_id=debit.iban[2:10],
103 dest_nip=settings.PZ_NIP,
104 payment_id=debit.payment_id,
105 payment_desc=settings.PZ_PAYMENT_DESCRIPTION,
106 user_addr = '|'.join((
109 debit.street_address,
110 ' '.join((debit.postal_code, debit.town))
114 response.write('\r\n'.join(rows).encode('cp1250'))