I created a Custom field qr_code type attach image
You can fetch your default print format bt dynamically from Property Setter
import io
import os
import frappe
from frappe.utils import get_url
from pyqrcode import create as qr_create
def create_qr_code(doc, method=None):
print_format = 'Standard'
qr_image = io.BytesIO()
link = get_url(doc.doctype)+"/"+doc.name+"?format=" + \
print_format+"&key="+doc.get_signature()
url = qr_create(link, error='L')
url.png(qr_image, scale=2, quiet_zone=1)
name = frappe.generate_hash(doc.name, 5)
filename = f"QRCode-{name}.png".replace(os.path.sep, "__")
_file = frappe.get_doc({
"doctype": "File",
"file_name": filename,
"attached_to_doctype": doc.get("doctype"),
"attached_to_name": doc.get("name"),
"attached_to_field": "qr_code",
"is_private": 0,
"content": qr_image.getvalue()
})
_file.save()
doc.db_set('qr_code', _file.file_url)
#Thanks