add qr code
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
from django.contrib import admin, messages
|
||||
from django.utils.html import format_html
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.utils.translation import ngettext
|
||||
|
||||
from segno import helpers
|
||||
|
||||
from .forms import (
|
||||
BankDataAdminForm,
|
||||
BillAdminForm,
|
||||
@@ -67,6 +70,7 @@ class BillAdmin(admin.ModelAdmin):
|
||||
"status_colored",
|
||||
"bill_creator",
|
||||
"affiliation",
|
||||
"get_qrcode",
|
||||
]
|
||||
|
||||
actions = ["make_cleared", "make_finished"]
|
||||
@@ -171,6 +175,27 @@ class BillAdmin(admin.ModelAdmin):
|
||||
|
||||
return f"{ tmp.bic }"
|
||||
|
||||
@admin.display(description="QR Code")
|
||||
def get_qrcode(self, obj):
|
||||
if obj.status != "C":
|
||||
return "-"
|
||||
|
||||
try:
|
||||
tmp = BankData.objects.get(id=obj.bankdata.id)
|
||||
except Exception:
|
||||
return "-"
|
||||
|
||||
qrcode = helpers.make_epc_qr(
|
||||
name=tmp.name,
|
||||
iban=tmp.iban,
|
||||
amount=obj.amount,
|
||||
text=obj.purpose,
|
||||
bic=tmp.bic,
|
||||
encoding="utf-8",
|
||||
)
|
||||
uri = qrcode.png_data_uri(scale=3.0)
|
||||
return format_html(f'<img src="{uri}">')
|
||||
|
||||
@admin.display(description="Status")
|
||||
def status_colored(self, obj):
|
||||
# TODO: if there is a status without color, set nothing.
|
||||
|
||||
@@ -16,6 +16,7 @@ ldap3==2.9.1
|
||||
mysqlclient==2.1.1
|
||||
pillow==9.5.0
|
||||
reportlab<4
|
||||
segno==1.6.0
|
||||
xhtml2pdf==0.2.11 # dependency reportlab<4
|
||||
Whoosh==2.7.4
|
||||
elasticsearch
|
||||
|
||||
Reference in New Issue
Block a user