Browse Source

Kilometer mapping fix reload issue

master
venkataakhil 1 year ago
parent
commit
e557e455b1
  1. 8
      smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.js
  2. 29
      smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.py

8
smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.js

@ -56,9 +56,6 @@ frappe.ui.form.on('Kilometer Mapping', {
}, },
validate: function (frm) { validate: function (frm) {
if (frm.doc.__unsaved == 1){
frm.doc.workflow_state = "Draft";
}
frm.doc.kilometer_filter = "All"; frm.doc.kilometer_filter = "All";
if (frm.doc.kilometer_filter == "All") { if (frm.doc.kilometer_filter == "All") {
@ -72,7 +69,7 @@ frappe.ui.form.on('Kilometer Mapping', {
}, },
refresh: function (frm) { refresh: function (frm) {
//custom duplicate button //custom button
frm.add_custom_button(__("Duplicate Data"), function () { frm.add_custom_button(__("Duplicate Data"), function () {
let d = new frappe.ui.Dialog({ let d = new frappe.ui.Dialog({
title: 'Choose the variant', title: 'Choose the variant',
@ -101,11 +98,11 @@ frappe.ui.form.on('Kilometer Mapping', {
if (r.message && r.message['status'] == "success") { if (r.message && r.message['status'] == "success") {
cur_frm.refresh_fields("config_kilometer"); cur_frm.refresh_fields("config_kilometer");
frm.save() frm.save()
cur_frm.reload_doc();
frappe.show_alert({ frappe.show_alert({
message: __('Saved'), message: __('Saved'),
indicator: 'green' indicator: 'green'
}, 5); }, 5);
frm.refresh()
} }
} }
}) })
@ -122,6 +119,7 @@ frappe.ui.form.on('Kilometer Mapping', {
d.show(); d.show();
setTimeout(function mysam() { setTimeout(function mysam() {
console.log("jiiii", $('.modal-dialog').find('.custom-actions').html('<p>Are you sure to update the kilometer mapping?</p>'))
$('.modal-dialog').find('.custom-actions').html('<p>Are you sure to update the <b>kilometer mapping</b>?</p>') $('.modal-dialog').find('.custom-actions').html('<p>Are you sure to update the <b>kilometer mapping</b>?</p>')
} }
, 300); , 300);

29
smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.py

@ -6,33 +6,41 @@ from frappe.model.document import Document
import sys import sys
from frappe import _ from frappe import _
sys.tracebacklimit = 0 sys.tracebacklimit = 0
current_db_name = frappe.conf.get("db_name")
class KilometerMapping(Document): class KilometerMapping(Document):
def onload(self): def onload(self):
###Kilometer mapping config table idx allignment # Kilometer mapping config table idx allignment
if (self.config_kilometer): if (self.config_kilometer):
idx = 0 idx = 0
for x in self.get("config_kilometer"): for x in self.get("config_kilometer"):
idx += 1 idx += 1
x.idx = idx x.idx = idx
@frappe.whitelist() @frappe.whitelist()
def get_system(doc): def get_system(doc):
current_db_name = frappe.conf.get("db_name")
system_map = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping='{1}'""".format(current_db_name,doc),as_dict=True) system_map = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping='{1}'""".format(
current_db_name, doc), as_dict=True)
if system_map: if system_map:
for s in system_map: for s in system_map:
doc = frappe.get_doc("System Mapping", s.name) doc = frappe.get_doc("System Mapping", s.name)
system = frappe.db.sql("""select sub_systems,mat from {0}.`tabSystem Mapping_Sub System` where parent = '{1}' and procedure_is_published = '0'""".format(current_db_name,s.name),as_dict=True) system = frappe.db.sql("""select sub_systems,mat from {0}.`tabSystem Mapping_Sub System` where parent = '{1}' and procedure_is_published = '0'""".format(
current_db_name, s.name), as_dict=True)
return system return system
@frappe.whitelist() @frappe.whitelist()
def get_subsystem(doc): def get_subsystem(doc):
current_db_name = frappe.conf.get("db_name") current_db_name = frappe.conf.get("db_name")
system_map = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping='{1}'""".format(current_db_name,doc),as_dict=True) system_map = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping='{1}'""".format(
current_db_name, doc), as_dict=True)
if system_map: if system_map:
for s in system_map: for s in system_map:
doc = frappe.get_doc("System Mapping", s.name) doc = frappe.get_doc("System Mapping", s.name)
sub_system = frappe.db.sql("""select sub_systems,mat,idx from {0}.`tabSystem Mapping_Sub System` where parent = '{1}' and procedure_is_published = '0'""".format(current_db_name,s.name),as_dict=True) sub_system = frappe.db.sql("""select sub_systems,mat,idx from {0}.`tabSystem Mapping_Sub System` where parent = '{1}' and procedure_is_published = '0'""".format(
current_db_name, s.name), as_dict=True)
return sub_system return sub_system
@ -40,7 +48,8 @@ def get_subsystem(doc):
def update_duplicate_km(doc, kilometer): def update_duplicate_km(doc, kilometer):
km = frappe.get_doc("Kilometer Mapping", doc) km = frappe.get_doc("Kilometer Mapping", doc)
output = frappe.db.sql("""select kilometer,mat,sub_systems,row_name from `tabKilometer Mapping_Items` where parent = '{0}' and kilometer = '{1}' order by kilometer""".format(doc,kilometer),as_dict=True) output = frappe.db.sql("""select kilometer,mat,sub_systems,row_name from `tabKilometer Mapping_Items` where parent = '{0}' and kilometer = '{1}' order by kilometer""".format(
doc, kilometer), as_dict=True)
# frappe.msgprint(str(output)) # frappe.msgprint(str(output))
for data in output: for data in output:
# frappe.msgprint(str(data['mat'])) # frappe.msgprint(str(data['mat']))
@ -53,10 +62,10 @@ def update_duplicate_km(doc,kilometer):
km.save(ignore_permissions=True) km.save(ignore_permissions=True)
@frappe.whitelist() @frappe.whitelist()
def get_config_kilometer(doc, docname): def get_config_kilometer(doc, docname):
res = frappe.db.sql(f"""select kilometer,mat,sub_systems,applicable,row_name from `tabKilometer Mapping_Items` where parent='{doc}'""",as_dict=1) res = frappe.db.sql(
f"""select kilometer,mat,sub_systems,applicable,row_name from `tabKilometer Mapping_Items` where parent='{doc}'""", as_dict=1)
ress = frappe.get_doc("Kilometer Mapping", docname) ress = frappe.get_doc("Kilometer Mapping", docname)
ress.config_kilometer = [] ress.config_kilometer = []
for d in res: for d in res:

Loading…
Cancel
Save