Skip to content

Commit

Permalink
feat(india): store e-way bill auto calculated distance in sales invoi…
Browse files Browse the repository at this point in the history
…ce (frappe#30923)
  • Loading branch information
mergify[bot] committed May 8, 2022
1 parent 2972ef8 commit b96f156
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
20 changes: 17 additions & 3 deletions erpnext/regional/india/e_invoice/einvoice.js
Expand Up @@ -99,8 +99,21 @@ erpnext.setup_einvoice_actions = (doctype) => {
...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')
Expand Down Expand Up @@ -202,7 +215,8 @@ const get_ewaybill_fields = (frm) => {
'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',
Expand Down
13 changes: 13 additions & 0 deletions erpnext/regional/india/e_invoice/utils.py
Expand Up @@ -1112,6 +1112,19 @@ def generate_eway_bill(self, **kwargs):
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,
Expand Down

0 comments on commit b96f156

Please sign in to comment.