+
+
+@admin.register(models.BankExportFeedback)
+class BankExportFeedbackAdmin(admin.ModelAdmin):
+ inlines = [BankExportFeedbackLineInline]
+
+
+
+@admin.register(models.BankOrder)
+class BankOrderAdmin(admin.ModelAdmin):
+ fields = ['payment_date', 'debits', 'sent', 'download']
+ filter_horizontal = ['debits']
+
+ def get_readonly_fields(self, request, obj=None):
+ fields = ['download']
+ if obj is not None and obj.sent:
+ fields += ['debits', 'payment_date']
+ return fields
+
+ def download(self, obj):
+ return mark_safe('<a href="{}">Download</a>'.format(
+ reverse('admin:pz_bankorder_download', args=[obj.pk])
+ ))
+
+ def get_urls(self):
+ urls = super().get_urls()
+ my_urls = [
+ path(
+ '<int:pk>/download/',
+ self.admin_site.admin_view(self.download_view),
+ name='pz_bankorder_download',
+ ),
+ ]
+ return my_urls + urls
+
+ def download_view(self, request, pk):
+ order = get_object_or_404(
+ models.BankOrder, pk=pk)
+ try:
+ return bank.bank_order(order.payment_date, order.debits.all())
+ except Exception as e:
+ messages.error(request, str(e))
+ return redirect('admin:pz_bankorder_change', pk)