feat(india): store e-way bill auto calculated distance in sales invoice (#30908)
diff --git a/erpnext/regional/india/e_invoice/einvoice.js b/erpnext/regional/india/e_invoice/einvoice.js
index 17b018c..58f8e11 100644
--- a/erpnext/regional/india/e_invoice/einvoice.js
+++ b/erpnext/regional/india/e_invoice/einvoice.js
@@ -99,8 +99,21 @@
...data
},
freeze: true,
- callback: () => frm.reload_doc() || d.hide(),
- error: () => d.hide()
+ callback: () => {
+ frappe.show_alert({
+ message: __('E-Way Bill Generated successfully'),
+ indicator: 'green'
+ }, 7);
+ frm.reload_doc();
+ d.hide();
+ },
+ error: () => {
+ frappe.show_alert({
+ message: __('E-Way Bill was not Generated'),
+ indicator: 'red'
+ }, 7);
+ d.hide();
+ }
});
},
primary_action_label: __('Submit')
@@ -202,7 +215,8 @@
'fieldname': 'distance',
'label': 'Distance (in km)',
'fieldtype': 'Float',
- 'default': frm.doc.distance
+ 'default': frm.doc.distance,
+ 'description': 'Set as zero to auto calculate distance using pin codes',
},
{
'fieldname': 'transporter_col_break',
diff --git a/erpnext/regional/india/e_invoice/utils.py b/erpnext/regional/india/e_invoice/utils.py
index cfe9cee..4e6c9a5 100644
--- a/erpnext/regional/india/e_invoice/utils.py
+++ b/erpnext/regional/india/e_invoice/utils.py
@@ -1113,6 +1113,19 @@
self.invoice.eway_bill_validity = res.get("result").get("EwbValidTill")
self.invoice.eway_bill_cancelled = 0
self.invoice.update(args)
+ if res.get("info"):
+ info = res.get("info")
+ # when we have more features (responses) in eway bill, we can add them using below forloop.
+ for msg in info:
+ if msg.get("InfCd") == "EWBPPD":
+ pin_to_pin_distance = int(re.search(r"\d+", msg.get("Desc")).group())
+ frappe.msgprint(
+ _("Auto Calculated Distance is {} KM.").format(str(pin_to_pin_distance)),
+ title="Notification",
+ indicator="green",
+ alert=True,
+ )
+ self.invoice.distance = flt(pin_to_pin_distance)
self.invoice.flags.updater_reference = {
"doctype": self.invoice.doctype,
"docname": self.invoice.name,