Create QRcode in Sales Invoice

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

2 Likes

It is giving me this " ImportError: import not found " error no matter what changes i make in this code please help!

Did you add those import ?
import io
import os
from frappe.utils import get_url
from pyqrcode import create as qr_create

1 Like

Hi,based on the above code i tried to impliment qr code on my sales invoice, where that qrcode contain upi link for the payment of the customer and i try to save this in the file doctype and the file successfuly saved , but i cant preview the qrcode in the file list and also its file size is not in kb/mb its a random number how i can resolve this issue, can you help me???