fix(india): duplicate qrcode and hide button (#31100)
This commit is contained in:
parent
e3c0d0134e
commit
935e5b1dcd
@ -11,7 +11,7 @@ erpnext.setup_einvoice_actions = (doctype) => {
|
|||||||
|
|
||||||
if (!invoice_eligible) return;
|
if (!invoice_eligible) return;
|
||||||
|
|
||||||
const { doctype, irn, irn_cancelled, ewaybill, eway_bill_cancelled, name, __unsaved } = frm.doc;
|
const { doctype, irn, irn_cancelled, ewaybill, eway_bill_cancelled, name, qrcode_image, __unsaved } = frm.doc;
|
||||||
|
|
||||||
const add_custom_button = (label, action) => {
|
const add_custom_button = (label, action) => {
|
||||||
if (!frm.custom_buttons[label]) {
|
if (!frm.custom_buttons[label]) {
|
||||||
@ -175,27 +175,44 @@ erpnext.setup_einvoice_actions = (doctype) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (irn && !irn_cancelled) {
|
if (irn && !irn_cancelled) {
|
||||||
const action = () => {
|
let is_qrcode_attached = false;
|
||||||
const dialog = frappe.msgprint({
|
if (qrcode_image && frm.attachments) {
|
||||||
title: __("Generate QRCode"),
|
let attachments = frm.attachments.get_attachments();
|
||||||
message: __("Generate and attach QR Code using IRN?"),
|
if (attachments.length != 0) {
|
||||||
primary_action: {
|
for (let i = 0; i < attachments.length; i++) {
|
||||||
action: function() {
|
if (attachments[i].file_url == qrcode_image) {
|
||||||
frappe.call({
|
is_qrcode_attached = true;
|
||||||
method: 'erpnext.regional.india.e_invoice.utils.generate_qrcode',
|
break;
|
||||||
args: { doctype, docname: name },
|
|
||||||
freeze: true,
|
|
||||||
callback: () => frm.reload_doc() || dialog.hide(),
|
|
||||||
error: () => dialog.hide()
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!is_qrcode_attached) {
|
||||||
|
const action = () => {
|
||||||
|
if (frm.doc.__unsaved) {
|
||||||
|
frappe.throw(__('Please save the document to generate QRCode.'));
|
||||||
|
}
|
||||||
|
const dialog = frappe.msgprint({
|
||||||
|
title: __("Generate QRCode"),
|
||||||
|
message: __("Generate and attach QR Code using IRN?"),
|
||||||
|
primary_action: {
|
||||||
|
action: function() {
|
||||||
|
frappe.call({
|
||||||
|
method: 'erpnext.regional.india.e_invoice.utils.generate_qrcode',
|
||||||
|
args: { doctype, docname: name },
|
||||||
|
freeze: true,
|
||||||
|
callback: () => frm.reload_doc() || dialog.hide(),
|
||||||
|
error: () => dialog.hide()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
primary_action_label: __('Yes')
|
primary_action_label: __('Yes')
|
||||||
});
|
});
|
||||||
dialog.show();
|
dialog.show();
|
||||||
};
|
};
|
||||||
add_custom_button(__("Generate QRCode"), action);
|
add_custom_button(__("Generate QRCode"), action);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1010,13 +1010,32 @@ class GSPConnector:
|
|||||||
return failed
|
return failed
|
||||||
|
|
||||||
def fetch_and_attach_qrcode_from_irn(self):
|
def fetch_and_attach_qrcode_from_irn(self):
|
||||||
qrcode = self.get_qrcode_from_irn(self.invoice.irn)
|
is_qrcode_file_attached = self.invoice.qrcode_image and frappe.db.exists(
|
||||||
if qrcode:
|
"File",
|
||||||
qrcode_file = self.create_qr_code_file(qrcode)
|
{
|
||||||
frappe.db.set_value("Sales Invoice", self.invoice.name, "qrcode_image", qrcode_file.file_url)
|
"attached_to_doctype": "Sales Invoice",
|
||||||
frappe.msgprint(_("QR Code attached to the invoice"), alert=True)
|
"attached_to_name": self.invoice.name,
|
||||||
|
"file_url": self.invoice.qrcode_image,
|
||||||
|
"attached_to_field": "qrcode_image",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if not is_qrcode_file_attached:
|
||||||
|
if self.invoice.signed_qr_code:
|
||||||
|
self.attach_qrcode_image()
|
||||||
|
frappe.db.set_value(
|
||||||
|
"Sales Invoice", self.invoice.name, "qrcode_image", self.invoice.qrcode_image
|
||||||
|
)
|
||||||
|
frappe.msgprint(_("QR Code attached to the invoice."), alert=True)
|
||||||
|
else:
|
||||||
|
qrcode = self.get_qrcode_from_irn(self.invoice.irn)
|
||||||
|
if qrcode:
|
||||||
|
qrcode_file = self.create_qr_code_file(qrcode)
|
||||||
|
frappe.db.set_value("Sales Invoice", self.invoice.name, "qrcode_image", qrcode_file.file_url)
|
||||||
|
frappe.msgprint(_("QR Code attached to the invoice."), alert=True)
|
||||||
|
else:
|
||||||
|
frappe.msgprint(_("QR Code not found for the IRN"), alert=True)
|
||||||
else:
|
else:
|
||||||
frappe.msgprint(_("QR Code not found for the IRN"), alert=True)
|
frappe.msgprint(_("QR Code is already Attached"), indicator="green", alert=True)
|
||||||
|
|
||||||
def get_qrcode_from_irn(self, irn):
|
def get_qrcode_from_irn(self, irn):
|
||||||
import requests
|
import requests
|
||||||
@ -1281,7 +1300,6 @@ class GSPConnector:
|
|||||||
|
|
||||||
def attach_qrcode_image(self):
|
def attach_qrcode_image(self):
|
||||||
qrcode = self.invoice.signed_qr_code
|
qrcode = self.invoice.signed_qr_code
|
||||||
|
|
||||||
qr_image = io.BytesIO()
|
qr_image = io.BytesIO()
|
||||||
url = qrcreate(qrcode, error="L")
|
url = qrcreate(qrcode, error="L")
|
||||||
url.png(qr_image, scale=2, quiet_zone=1)
|
url.png(qr_image, scale=2, quiet_zone=1)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user