mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-26 08:24:47 +00:00
chore: clean up e invoice actions
This commit is contained in:
@@ -162,7 +162,7 @@ def generate_irn(doctype, name):
|
|||||||
json_str = aes_decrypt(enc_json, credentials.sek)
|
json_str = aes_decrypt(enc_json, credentials.sek)
|
||||||
|
|
||||||
signed_einvoice = json.loads(json_str)
|
signed_einvoice = json.loads(json_str)
|
||||||
handle_irn_response(signed_einvoice)
|
decrypt_irn_response(signed_einvoice)
|
||||||
|
|
||||||
update_einvoice_fields(doctype, name, signed_einvoice)
|
update_einvoice_fields(doctype, name, signed_einvoice)
|
||||||
|
|
||||||
@@ -218,7 +218,7 @@ def cancel_eway_bill(doctype, name, eway_bill, reason, remark=''):
|
|||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def handle_irn_response(data):
|
def decrypt_irn_response(data):
|
||||||
enc_signed_invoice = data['SignedInvoice']
|
enc_signed_invoice = data['SignedInvoice']
|
||||||
enc_signed_qr_code = data['SignedQRCode']
|
enc_signed_qr_code = data['SignedQRCode']
|
||||||
signed_invoice = jwt_decrypt(enc_signed_invoice)['data']
|
signed_invoice = jwt_decrypt(enc_signed_invoice)['data']
|
||||||
@@ -473,7 +473,7 @@ def make_einvoice(doctype, name):
|
|||||||
else:
|
else:
|
||||||
frappe.throw(error_msgs[0], title=_('E Invoice Validation Failed'))
|
frappe.throw(error_msgs[0], title=_('E Invoice Validation Failed'))
|
||||||
|
|
||||||
return {'einvoice': json.dumps([einvoice])}
|
return json.dumps(einvoice)
|
||||||
|
|
||||||
def validate_einvoice(validations, einvoice, error_msgs=[]):
|
def validate_einvoice(validations, einvoice, error_msgs=[]):
|
||||||
type_map = { 'string': 'str', 'number': 'int', 'object': 'dict', 'array': 'list' }
|
type_map = { 'string': 'str', 'number': 'int', 'object': 'dict', 'array': 'list' }
|
||||||
|
|||||||
@@ -3,24 +3,157 @@ erpnext.setup_einvoice_actions = (doctype) => {
|
|||||||
refresh(frm) {
|
refresh(frm) {
|
||||||
const einvoicing_enabled = frappe.db.get_value("E Invoice Settings", "E Invoice Settings", "enable");
|
const einvoicing_enabled = frappe.db.get_value("E Invoice Settings", "E Invoice Settings", "enable");
|
||||||
const supply_type = frm.doc.gst_category;
|
const supply_type = frm.doc.gst_category;
|
||||||
if (!einvoicing_enabled
|
const valid_supply_type = ['Registered Regular', 'SEZ', 'Overseas', 'Deemed Export'].includes(supply_type)
|
||||||
|| !['Registered Regular', 'SEZ', 'Overseas', 'Deemed Export'].includes(supply_type)) {
|
|
||||||
return;
|
if (!einvoicing_enabled || !valid_supply_type) return;
|
||||||
|
|
||||||
|
const { docstatus, irn, irn_cancelled, ewaybill, eway_bill_cancelled, doctype, name, __unsaved } = frm.doc;
|
||||||
|
|
||||||
|
if (docstatus == 0 && !irn && !__unsaved) {
|
||||||
|
frm.add_custom_button(
|
||||||
|
_("Generate IRN"),
|
||||||
|
() => {
|
||||||
|
frappe.call({
|
||||||
|
method: 'erpnext.regional.india.e_invoice.e_invoice_utils.generate_irn',
|
||||||
|
args: { doctype: doctype, name: name },
|
||||||
|
freeze: true,
|
||||||
|
callback: () => frm.reload_doc()
|
||||||
|
})
|
||||||
|
},
|
||||||
|
__("E Invoicing")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (docstatus == 1 && irn && !irn_cancelled) {
|
||||||
|
frm.add_custom_button(
|
||||||
|
__("Cancel IRN"),
|
||||||
|
() => {
|
||||||
|
const fields = [
|
||||||
|
{
|
||||||
|
"label" : "Reason",
|
||||||
|
"fieldname": "reason",
|
||||||
|
"fieldtype": "Select",
|
||||||
|
"reqd": 1,
|
||||||
|
"default": "1-Duplicate",
|
||||||
|
"options": ["1-Duplicate", "2-Data Entry Error", "3-Order Cancelled", "4-Other"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Remark",
|
||||||
|
"fieldname": "remark",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"reqd": 1
|
||||||
|
}
|
||||||
|
];
|
||||||
|
const d = new frappe.ui.Dialog({
|
||||||
|
title: __("Cancel IRN"),
|
||||||
|
fields: fields,
|
||||||
|
primary_action: function() {
|
||||||
|
const data = d.get_values();
|
||||||
|
frappe.call({
|
||||||
|
method: 'erpnext.regional.india.e_invoice.e_invoice_utils.cancel_irn',
|
||||||
|
args: {
|
||||||
|
doctype: doctype,
|
||||||
|
name: name,
|
||||||
|
irn: irn,
|
||||||
|
reason: data.reason.split('-')[0],
|
||||||
|
remark: data.remark
|
||||||
|
},
|
||||||
|
freeze: true,
|
||||||
|
callback: () => frm.reload_doc() || d.hide(),
|
||||||
|
error: () => d.hide()
|
||||||
|
});
|
||||||
|
},
|
||||||
|
primary_action_label: __('Submit')
|
||||||
|
});
|
||||||
|
d.show();
|
||||||
|
},
|
||||||
|
__("E Invoicing")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (docstatus == 1 && irn && !irn_cancelled && !eway_bill_cancelled) {
|
||||||
|
frm.add_custom_button(
|
||||||
|
__("Cancel E-Way Bill"),
|
||||||
|
() => {
|
||||||
|
const fields = [
|
||||||
|
{
|
||||||
|
"label" : "Reason",
|
||||||
|
"fieldname": "reason",
|
||||||
|
"fieldtype": "Select",
|
||||||
|
"reqd": 1,
|
||||||
|
"default": "1-Duplicate",
|
||||||
|
"options": ["1-Duplicate", "2-Data Entry Error", "3-Order Cancelled", "4-Other"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Remark",
|
||||||
|
"fieldname": "remark",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"reqd": 1
|
||||||
|
}
|
||||||
|
]
|
||||||
|
const d = new frappe.ui.Dialog({
|
||||||
|
title: __('Cancel E-Way Bill'),
|
||||||
|
fields: fields,
|
||||||
|
primary_action: function() {
|
||||||
|
const data = d.get_values();
|
||||||
|
frappe.call({
|
||||||
|
method: 'erpnext.regional.india.e_invoice.e_invoice_utils.cancel_eway_bill',
|
||||||
|
args: {
|
||||||
|
doctype: doctype,
|
||||||
|
name: name,
|
||||||
|
eway_bill: ewaybill,
|
||||||
|
reason: data.reason.split('-')[0],
|
||||||
|
remark: data.remark
|
||||||
|
},
|
||||||
|
freeze: true,
|
||||||
|
callback: () => frm.reload_doc() || d.hide(),
|
||||||
|
error: () => d.hide()
|
||||||
|
})
|
||||||
|
},
|
||||||
|
primary_action_label: __('Submit')
|
||||||
|
});
|
||||||
|
d.show();
|
||||||
|
},
|
||||||
|
__("E Invoicing")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// if (frm.doc.docstatus == 0 && !frm.doc.irn && !frm.doc.__unsaved) {
|
// if (frm.doc.docstatus == 0 && !frm.doc.irn && !frm.doc.__unsaved) {
|
||||||
// frm.add_custom_button(
|
// frm.add_custom_button(
|
||||||
// "Generate IRN",
|
// "Download E-Invoice",
|
||||||
// () => {
|
// () => {
|
||||||
// frappe.call({
|
// frappe.call({
|
||||||
// method: 'erpnext.regional.india.e_invoice.e_invoice_utils.generate_irn',
|
// method: 'erpnext.regional.india.e_invoice.e_invoice_utils.make_einvoice',
|
||||||
// args: { doctype: frm.doc.doctype, name: frm.doc.name },
|
// args: { doctype: frm.doc.doctype, name: frm.doc.name },
|
||||||
// freeze: true,
|
// freeze: true,
|
||||||
// callback: () => frm.reload_doc()
|
// callback: (res) => {
|
||||||
|
// if (!res.exc) {
|
||||||
|
// const args = {
|
||||||
|
// cmd: 'erpnext.regional.india.e_invoice.e_invoice_utils.download_einvoice',
|
||||||
|
// einvoice: res.message.einvoice,
|
||||||
|
// name: frm.doc.name
|
||||||
|
// };
|
||||||
|
// open_url_post(frappe.request.url, args);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
// })
|
// })
|
||||||
// }
|
// }, "E-Invoicing");
|
||||||
// )
|
// frm.add_custom_button(
|
||||||
|
// "Upload Signed E-Invoice",
|
||||||
|
// () => {
|
||||||
|
// new frappe.ui.FileUploader({
|
||||||
|
// method: 'erpnext.regional.india.e_invoice.e_invoice_utils.upload_einvoice',
|
||||||
|
// allow_multiple: 0,
|
||||||
|
// doctype: frm.doc.doctype,
|
||||||
|
// docname: frm.doc.name,
|
||||||
|
// on_success: (attachment, r) => {
|
||||||
|
// if (!r.exc) {
|
||||||
|
// frm.reload_doc();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// }, "E-Invoicing");
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// if (frm.doc.docstatus == 1 && frm.doc.irn && !frm.doc.irn_cancelled) {
|
// if (frm.doc.docstatus == 1 && frm.doc.irn && !frm.doc.irn_cancelled) {
|
||||||
// frm.add_custom_button(
|
// frm.add_custom_button(
|
||||||
// "Cancel IRN",
|
// "Cancel IRN",
|
||||||
@@ -28,147 +161,45 @@ erpnext.setup_einvoice_actions = (doctype) => {
|
|||||||
// const d = new frappe.ui.Dialog({
|
// const d = new frappe.ui.Dialog({
|
||||||
// title: __('Cancel IRN'),
|
// title: __('Cancel IRN'),
|
||||||
// fields: [
|
// fields: [
|
||||||
// { "label" : "Reason", "fieldname": "reason", "fieldtype": "Select", "reqd": 1, "default": "1-Duplicate",
|
// {
|
||||||
// "options": ["1-Duplicate", "2-Data Entry Error", "3-Order Cancelled", "4-Other"] },
|
// "label" : "Reason", "fieldname": "reason",
|
||||||
// { "label": "Remark", "fieldname": "remark", "fieldtype": "Data", "reqd": 1 }
|
// "fieldtype": "Select", "reqd": 1, "default": "1-Duplicate",
|
||||||
|
// "options": ["1-Duplicate", "2-Data Entry Error", "3-Order Cancelled", "4-Other"]
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// "label": "Remark", "fieldname": "remark", "fieldtype": "Data", "reqd": 1
|
||||||
|
// }
|
||||||
// ],
|
// ],
|
||||||
// primary_action: function() {
|
// primary_action: function() {
|
||||||
// const data = d.get_values();
|
// const data = d.get_values();
|
||||||
// frappe.call({
|
// const args = {
|
||||||
// method: 'erpnext.regional.india.e_invoice.e_invoice_utils.cancel_irn',
|
// cmd: 'erpnext.regional.india.e_invoice.e_invoice_utils.download_cancel_einvoice',
|
||||||
// args: {
|
// irn: frm.doc.irn, reason: data.reason.split('-')[0], remark: data.remark, name: frm.doc.name
|
||||||
// doctype: frm.doc.doctype,
|
// };
|
||||||
// name: frm.doc.name,
|
// open_url_post(frappe.request.url, args);
|
||||||
// irn: frm.doc.irn,
|
// d.hide();
|
||||||
// reason: data.reason.split('-')[0],
|
|
||||||
// remark: data.remark
|
|
||||||
// },
|
|
||||||
// freeze: true,
|
|
||||||
// callback: () => frm.reload_doc() || d.hide(),
|
|
||||||
// error: () => d.hide()
|
|
||||||
// })
|
|
||||||
// },
|
// },
|
||||||
// primary_action_label: __('Submit')
|
// primary_action_label: __('Download JSON')
|
||||||
// });
|
// });
|
||||||
// d.show();
|
// d.show();
|
||||||
// }
|
// }, "E-Invoicing");
|
||||||
// )
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (frm.doc.docstatus == 1 && frm.doc.irn && !frm.doc.irn_cancelled && !frm.doc.eway_bill_cancelled) {
|
|
||||||
// frm.add_custom_button(
|
// frm.add_custom_button(
|
||||||
// "Cancel E-Way Bill",
|
// "Upload Cancel JSON",
|
||||||
// () => {
|
// () => {
|
||||||
// const d = new frappe.ui.Dialog({
|
// new frappe.ui.FileUploader({
|
||||||
// title: __('Cancel E-Way Bill'),
|
// method: 'erpnext.regional.india.e_invoice.e_invoice_utils.upload_cancel_ack',
|
||||||
// fields: [
|
// allow_multiple: 0,
|
||||||
// { "label" : "Reason", "fieldname": "reason", "fieldtype": "Select", "reqd": 1, "default": "1-Duplicate",
|
// doctype: frm.doc.doctype,
|
||||||
// "options": ["1-Duplicate", "2-Data Entry Error", "3-Order Cancelled", "4-Other"] },
|
// docname: frm.doc.name,
|
||||||
// { "label": "Remark", "fieldname": "remark", "fieldtype": "Data", "reqd": 1 }
|
// on_success: (attachment, r) => {
|
||||||
// ],
|
// if (!r.exc) {
|
||||||
// primary_action: function() {
|
// frm.reload_doc();
|
||||||
// const data = d.get_values();
|
// }
|
||||||
// frappe.call({
|
// }
|
||||||
// method: 'erpnext.regional.india.e_invoice.e_invoice_utils.cancel_eway_bill',
|
|
||||||
// args: { eway_bill: frm.doc.ewaybill, reason: data.reason.split('-')[0], remark: data.remark },
|
|
||||||
// freeze: true,
|
|
||||||
// callback: () => {
|
|
||||||
// frm.set_value('eway_bill_cancelled', 1);
|
|
||||||
// frm.save("Update");
|
|
||||||
// d.hide()
|
|
||||||
// },
|
|
||||||
// error: () => d.hide()
|
|
||||||
// })
|
|
||||||
// },
|
|
||||||
// primary_action_label: __('Submit')
|
|
||||||
// });
|
// });
|
||||||
// d.show();
|
// }, "E-Invoicing");
|
||||||
// }
|
|
||||||
// )
|
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if (frm.doc.docstatus == 0 && !frm.doc.irn && !frm.doc.__unsaved) {
|
|
||||||
frm.add_custom_button(
|
|
||||||
"Download E-Invoice",
|
|
||||||
() => {
|
|
||||||
frappe.call({
|
|
||||||
method: 'erpnext.regional.india.e_invoice.e_invoice_utils.make_einvoice',
|
|
||||||
args: { doctype: frm.doc.doctype, name: frm.doc.name },
|
|
||||||
freeze: true,
|
|
||||||
callback: (res) => {
|
|
||||||
if (!res.exc) {
|
|
||||||
const args = {
|
|
||||||
cmd: 'erpnext.regional.india.e_invoice.e_invoice_utils.download_einvoice',
|
|
||||||
einvoice: res.message.einvoice,
|
|
||||||
name: frm.doc.name
|
|
||||||
};
|
|
||||||
open_url_post(frappe.request.url, args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}, "E-Invoicing");
|
|
||||||
frm.add_custom_button(
|
|
||||||
"Upload Signed E-Invoice",
|
|
||||||
() => {
|
|
||||||
new frappe.ui.FileUploader({
|
|
||||||
method: 'erpnext.regional.india.e_invoice.e_invoice_utils.upload_einvoice',
|
|
||||||
allow_multiple: 0,
|
|
||||||
doctype: frm.doc.doctype,
|
|
||||||
docname: frm.doc.name,
|
|
||||||
on_success: (attachment, r) => {
|
|
||||||
if (!r.exc) {
|
|
||||||
frm.reload_doc();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}, "E-Invoicing");
|
|
||||||
}
|
|
||||||
if (frm.doc.docstatus == 1 && frm.doc.irn && !frm.doc.irn_cancelled) {
|
|
||||||
frm.add_custom_button(
|
|
||||||
"Cancel IRN",
|
|
||||||
() => {
|
|
||||||
const d = new frappe.ui.Dialog({
|
|
||||||
title: __('Cancel IRN'),
|
|
||||||
fields: [
|
|
||||||
{
|
|
||||||
"label" : "Reason", "fieldname": "reason",
|
|
||||||
"fieldtype": "Select", "reqd": 1, "default": "1-Duplicate",
|
|
||||||
"options": ["1-Duplicate", "2-Data Entry Error", "3-Order Cancelled", "4-Other"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"label": "Remark", "fieldname": "remark", "fieldtype": "Data", "reqd": 1
|
|
||||||
}
|
|
||||||
],
|
|
||||||
primary_action: function() {
|
|
||||||
const data = d.get_values();
|
|
||||||
const args = {
|
|
||||||
cmd: 'erpnext.regional.india.e_invoice.e_invoice_utils.download_cancel_einvoice',
|
|
||||||
irn: frm.doc.irn, reason: data.reason.split('-')[0], remark: data.remark, name: frm.doc.name
|
|
||||||
};
|
|
||||||
open_url_post(frappe.request.url, args);
|
|
||||||
d.hide();
|
|
||||||
},
|
|
||||||
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.e_invoice_utils.upload_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");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user