chore: clean up einvoice actions

This commit is contained in:
Saqib Ansari
2020-11-04 11:54:01 +05:30
committed by Saurabh
parent 6dcf334199
commit ac2fc8470b

View File

@@ -10,112 +10,104 @@ erpnext.setup_einvoice_actions = (doctype) => {
const { docstatus, irn, irn_cancelled, ewaybill, eway_bill_cancelled, doctype, name, __unsaved } = frm.doc; const { docstatus, irn, irn_cancelled, ewaybill, eway_bill_cancelled, doctype, name, __unsaved } = frm.doc;
if (docstatus == 0 && !irn && !__unsaved) { if (docstatus == 0 && !irn && !__unsaved) {
frm.add_custom_button( const action = () => {
__("Generate IRN"), frappe.call({
() => { method: 'erpnext.regional.india.e_invoice.utils.generate_irn',
frappe.call({ args: { doctype: doctype, name: name },
method: 'erpnext.regional.india.e_invoice.utils.generate_irn', freeze: true,
args: { doctype: doctype, name: name }, callback: () => frm.reload_doc()
freeze: true, })
callback: () => frm.reload_doc() };
})
}, frm.add_custom_button(__("Generate IRN"), action, __('E Invoicing'));
__("E Invoicing")
);
} }
if (docstatus == 1 && irn && !irn_cancelled) { if (docstatus == 1 && irn && !irn_cancelled) {
frm.add_custom_button( const fields = [
__("Cancel IRN"), {
() => { "label" : "Reason",
const fields = [ "fieldname": "reason",
{ "fieldtype": "Select",
"label" : "Reason", "reqd": 1,
"fieldname": "reason", "default": "1-Duplicate",
"fieldtype": "Select", "options": ["1-Duplicate", "2-Data Entry Error", "3-Order Cancelled", "4-Other"]
"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.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") {
) "label": "Remark",
"fieldname": "remark",
"fieldtype": "Data",
"reqd": 1
}
];
const action = () => {
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.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();
};
frm.add_custom_button(__("Cancel IRN"), action, __("E Invoicing"));
} }
if (docstatus == 1 && irn && !irn_cancelled && !eway_bill_cancelled) { if (docstatus == 1 && irn && !irn_cancelled && !eway_bill_cancelled) {
frm.add_custom_button( const fields = [
__("Cancel E-Way Bill"), {
() => { "label" : "Reason",
const fields = [ "fieldname": "reason",
{ "fieldtype": "Select",
"label" : "Reason", "reqd": 1,
"fieldname": "reason", "default": "1-Duplicate",
"fieldtype": "Select", "options": ["1-Duplicate", "2-Data Entry Error", "3-Order Cancelled", "4-Other"]
"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.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") {
); "label": "Remark",
"fieldname": "remark",
"fieldtype": "Data",
"reqd": 1
}
];
const action = () => {
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.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();
};
frm.add_custom_button(__("Cancel E-Way Bill"), action, __("E Invoicing"));
} }
} }
}) })