fix(einvoice): QRCode generation (#24412)
diff --git a/erpnext/regional/india/e_invoice/einvoice.js b/erpnext/regional/india/e_invoice/einvoice.js
index 9c86cc8..9fa94c4 100644
--- a/erpnext/regional/india/e_invoice/einvoice.js
+++ b/erpnext/regional/india/e_invoice/einvoice.js
@@ -18,6 +18,9 @@
if (!irn && !__unsaved) {
const action = () => {
+ if (frm.doc.__unsaved) {
+ frappe.throw(__('Please save the document to generate IRN.'));
+ }
frappe.call({
method: 'erpnext.regional.india.e_invoice.utils.get_einvoice',
args: { doctype, docname: name },
diff --git a/erpnext/regional/india/e_invoice/utils.py b/erpnext/regional/india/e_invoice/utils.py
index eb210be..2366fcb 100644
--- a/erpnext/regional/india/e_invoice/utils.py
+++ b/erpnext/regional/india/e_invoice/utils.py
@@ -11,6 +11,7 @@
import base64
import frappe
import traceback
+import io
from frappe import _, bold
from pyqrcode import create as qrcreate
from frappe.integrations.utils import make_post_request, make_get_request
@@ -436,7 +437,7 @@
self.irn_details_url = self.base_url + '/enriched/ei/api/invoice/irn'
self.generate_irn_url = self.base_url + '/enriched/ei/api/invoice'
self.gstin_details_url = self.base_url + '/enriched/ei/api/master/gstin'
- self.cancel_ewaybill_url = self.base_url + '/enriched/ei/api/ewayapi'
+ self.cancel_ewaybill_url = self.base_url + '/enriched/ewb/ewayapi?action=CANEWB'
self.generate_ewaybill_url = self.base_url + '/enriched/ei/api/ewaybill'
def get_credentials(self):
@@ -527,7 +528,7 @@
except Exception:
self.log_error()
self.raise_error(True)
-
+
@staticmethod
def get_gstin_details(gstin):
'''fetch and cache GSTIN details'''
@@ -622,7 +623,7 @@
except Exception:
self.log_error(data)
self.raise_error(True)
-
+
def generate_eway_bill(self, **kwargs):
args = frappe._dict(kwargs)
@@ -671,7 +672,8 @@
'cancelRsnCode': reason,
'cancelRmrk': remark
}, indent=4)
-
+ headers["username"] = headers["user_name"]
+ del headers["user_name"]
try:
res = self.make_request('post', self.cancel_ewaybill_url, headers, data)
if res.get('success'):
@@ -769,21 +771,21 @@
qrcode = self.invoice.signed_qr_code
doctype = self.invoice.doctype
docname = self.invoice.name
+ filename = 'QRCode_{}.png'.format(docname).replace(os.path.sep, "__")
- _file = frappe.new_doc('File')
- _file.update({
- 'file_name': 'QRCode_{}.png'.format(docname.replace('/', '-')),
- 'attached_to_doctype': doctype,
- 'attached_to_name': docname,
- 'content': str(base64.b64encode(os.urandom(64))),
- 'is_private': 1
- })
- _file.insert()
- frappe.db.commit()
+ qr_image = io.BytesIO()
url = qrcreate(qrcode, error='L')
- abs_file_path = os.path.abspath(_file.get_full_path())
- url.png(abs_file_path, scale=2, quiet_zone=1)
-
+ url.png(qr_image, scale=2, quiet_zone=1)
+ _file = frappe.get_doc({
+ "doctype": "File",
+ "file_name": filename,
+ "attached_to_doctype": doctype,
+ "attached_to_name": docname,
+ "attached_to_field": "qrcode_image",
+ "is_private": 1,
+ "content": qr_image.getvalue()})
+ _file.save()
+ frappe.db.commit()
self.invoice.qrcode_image = _file.file_url
def update_invoice(self):