diff --git a/erpnext/regional/india/e_invoice_utils.py b/erpnext/regional/india/e_invoice_utils.py index 6109f800f7d..b33c15507c0 100644 --- a/erpnext/regional/india/e_invoice_utils.py +++ b/erpnext/regional/india/e_invoice_utils.py @@ -464,7 +464,7 @@ def make_e_invoice(doctype, name): else: frappe.throw(_("{}").format(error_msgs[0]), title=_("E Invoice Validation Failed")) - return {'einvoice': json.dumps(e_invoice)} + return {'einvoice': json.dumps([e_invoice])} def validate_einvoice(validations, e_invoice, error_msgs=[]): type_map = { @@ -549,9 +549,18 @@ def download_cancel_einvoice(): reason = data['reason'] remark = data['remark'] - cancel_einvoice = json.dumps(dict(Irn=irn, CnlRsn=reason, CnlRem=remark)) + cancel_einvoice = json.dumps([dict(Irn=irn, CnlRsn=reason, CnlRem=remark)]) frappe.response['filename'] = "Cancel E-Invoice " + name + ".json" frappe.response['filecontent'] = cancel_einvoice frappe.response['content_type'] = 'application/json' - frappe.response['type'] = 'download' \ No newline at end of file + frappe.response['type'] = 'download' + +@frappe.whitelist() +def download_cancel_ack(): + cancel_ack = json.loads(frappe.local.uploaded_file) + data = frappe._dict(frappe.local.form_dict) + doctype = data['doctype'] + name = data['docname'] + + frappe.db.set_value(doctype, name, "irn_cancelled", 1) \ No newline at end of file diff --git a/erpnext/regional/india/einvoice.js b/erpnext/regional/india/einvoice.js index 4f98ffc88ab..2255358b8da 100644 --- a/erpnext/regional/india/einvoice.js +++ b/erpnext/regional/india/einvoice.js @@ -112,10 +112,7 @@ erpnext.setup_einvoice_actions = (doctype) => { } } }) - } - ); - } - if (frm.doc.docstatus == 0 && !frm.doc.irn && !frm.doc.__unsaved) { + }, "E-Invoicing"); frm.add_custom_button( "Upload Signed E-Invoice", () => { @@ -130,8 +127,7 @@ erpnext.setup_einvoice_actions = (doctype) => { } } }); - } - ); + }, "E-Invoicing"); } if (frm.doc.docstatus == 1 && frm.doc.irn && !frm.doc.irn_cancelled) { frm.add_custom_button( @@ -161,8 +157,22 @@ erpnext.setup_einvoice_actions = (doctype) => { primary_action_label: __('Download JSON') }); d.show(); - } - ); + }, "E-Invoicing"); + frm.add_custom_button( + "Upload Cancel JSON", + () => { + new frappe.ui.FileUploader({ + method: 'erpnext.regional.india.e_invoice_utils.download_cancel_ack', + allow_multiple: 0, + doctype: frm.doc.doctype, + docname: frm.doc.name, + on_success: (attachment, r) => { + if (!r.exc) { + frm.reload_doc(); + } + } + }); + }, "E-Invoicing"); } } })