mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-12 14:58:24 +00:00
feat: cancel e-way bill before cancelling IRN
This commit is contained in:
@@ -192,6 +192,21 @@ def cancel_irn(irn, reason, remark=''):
|
||||
|
||||
return res
|
||||
|
||||
@frappe.whitelist()
|
||||
def cancel_eway_bill(eway_bill, reason, remark=''):
|
||||
einv_creds = get_einv_credentials()
|
||||
endpoint = 'https://einv-apisandbox.nic.in/ewaybillapi/v1.03/ewayapi'
|
||||
headers = get_header(einv_creds)
|
||||
|
||||
cancel_eway_bill_json = json.dumps(dict(ewbNo=eway_bill, cancelRsnCode=reason, cancelRmrk=remark))
|
||||
enc_json = aes_encrypt(cancel_eway_bill_json, einv_creds.sek)
|
||||
payload = dict(action="CANEWB", Data=enc_json)
|
||||
|
||||
res = make_post_request(endpoint, headers=headers, data=json.dumps(payload))
|
||||
handle_err_response(res)
|
||||
|
||||
return res
|
||||
|
||||
def handle_irn_response(data):
|
||||
enc_signed_invoice = data['SignedInvoice']
|
||||
enc_signed_qr_code = data['SignedQRCode']
|
||||
|
||||
@@ -28,7 +28,8 @@ erpnext.setup_einvoice_actions = (doctype) => {
|
||||
})
|
||||
}
|
||||
)
|
||||
} else 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(
|
||||
"Cancel IRN",
|
||||
() => {
|
||||
@@ -59,6 +60,38 @@ erpnext.setup_einvoice_actions = (doctype) => {
|
||||
}
|
||||
)
|
||||
}
|
||||
if (frm.doc.docstatus == 1 && frm.doc.irn && !frm.doc.irn_cancelled && !frm.doc.eway_bill_cancelled) {
|
||||
frm.add_custom_button(
|
||||
"Cancel E-Way Bill",
|
||||
() => {
|
||||
const d = new frappe.ui.Dialog({
|
||||
title: __('Cancel E-Way Bill'),
|
||||
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();
|
||||
frappe.call({
|
||||
method: 'erpnext.regional.india.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();
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
@@ -369,7 +369,7 @@ def make_custom_fields(update=True):
|
||||
'fieldname': 'ewaybill',
|
||||
'label': 'e-Way Bill No.',
|
||||
'fieldtype': 'Data',
|
||||
'depends_on': 'eval:(doc.docstatus === 1)',
|
||||
'depends_on': 'eval:((doc.docstatus === 1 || doc.ewaybill) && doc.eway_bill_cancelled === 0)',
|
||||
'allow_on_submit': 1,
|
||||
'insert_after': 'tax_id',
|
||||
'translatable': 0
|
||||
@@ -379,10 +379,12 @@ def make_custom_fields(update=True):
|
||||
si_einvoice_fields = [
|
||||
dict(fieldname='irn', label='IRN', fieldtype='Data', read_only=1, insert_after='customer', no_copy=1,
|
||||
depends_on='eval:in_list(["Register Regular", "SEZ", "Overseas", "Deemed Export"], doc.gst_category) && doc.irn_cancelled === 0'),
|
||||
dict(fieldname='irn_cancelled', label='IRN Cancelled', fieldtype='Check', no_copy=1
|
||||
dict(fieldname='irn_cancelled', label='IRN Cancelled', fieldtype='Check', no_copy=1,
|
||||
depends_on='eval:(doc.irn_cancelled === 1)', read_only=1, allow_on_submit=1, insert_after='customer'),
|
||||
dict(fieldname='signed_einvoice', fieldtype='Code', options='JSON', hidden=1, no_copy=1, read_only=1),
|
||||
dict(fieldname='signed_qr_code', fieldtype='Code', options='JSON', hidden=1, no_copy=1, read_only=1)
|
||||
dict(fieldname='signed_qr_code', fieldtype='Code', options='JSON', hidden=1, no_copy=1, read_only=1),
|
||||
dict(fieldname='eway_bill_cancelled', label='E-Way Bill Cancelled', fieldtype='Check', no_copy=1,
|
||||
depends_on='eval:(doc.eway_bill_cancelled === 1)', read_only=1, allow_on_submit=1, insert_after='customer'),
|
||||
]
|
||||
|
||||
custom_fields = {
|
||||
|
||||
Reference in New Issue
Block a user