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)',
17 'Adres Płatnika Ulica + numer domu',
18 'Adres Płatnika kod+miejscowość',
19 'Numer kierunkowy banku Płatnika',
20 'Numer rachunku bankowego Płatnika',
21 'Identyfikator Odbiorcy (NIP Odbiorcy)',
22 'Osobowość prawna Płatnika (Osoba fizyczna)'
33 ' '.join([obj.postal_code, obj.town]).strip(),
42 def parse_export_feedback(f):
43 lines = csv.reader(StringIO(f.read().decode('cp1250')))
48 yield payment_id, status, comment
51 def bank_order(date, queryset):
52 response = HttpResponse(content_type='application/octet-stream')
53 response['Content-Disposition'] = 'attachment; filename=order.PLD'
60 raise ValueError('Payment date not set yet.')
62 for debit in queryset:
63 if debit.bank_acceptance_date is None:
64 no_dates.append(debit)
65 if debit.amount is None:
66 no_amounts.append(debit)
68 if no_dates or no_amounts:
71 t += 'Bank acceptance not received for: '
73 '<a href="/admin/pz/directdebit/{}/change">{}</a>'.format(
80 t += 'Amount not set for: '
82 '<a href="/admin/pz/directdebit/{}/change">{}</a>'.format(
85 for debit in no_amounts
88 raise ValueError(mark_safe(t))
90 for debit in queryset:
92 '{order_code},{date},{amount},{dest_bank_id},0,"{dest_iban}","{user_iban}",'
93 '"{dest_addr}","{user_addr}",0,{user_bank_id},'
94 '"/NIP/{dest_nip}/IDP/{payment_id}|/TXT/{payment_desc}||",'
97 date=date.strftime('%Y%m%d'),
99 amount=debit.amount * 100,
100 dest_bank_id=settings.PZ_IBAN[2:10],
101 dest_iban=settings.PZ_IBAN,
102 user_iban=debit.iban,
103 dest_addr=settings.PZ_ADDRESS_STRING,
104 user_bank_id=debit.iban[2:10],
105 dest_nip=settings.PZ_NIP,
106 payment_id=debit.payment_id,
107 payment_desc=settings.PZ_PAYMENT_DESCRIPTION,
108 user_addr = '|'.join((
111 debit.street_address,
112 ' '.join((debit.postal_code, debit.town))
116 response.write('\r\n'.join(rows).encode('cp1250'))