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. 101
      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);

101
smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.py

@ -5,63 +5,72 @@ import frappe
from frappe.model.document import Document 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)
if system_map:
for s in system_map:
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)
return system
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:
for s in system_map:
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)
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(
if system_map: current_db_name, doc), as_dict=True)
for s in system_map: if system_map:
doc = frappe.get_doc("System Mapping",s.name) for s in system_map:
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) doc = frappe.get_doc("System Mapping", s.name)
return sub_system 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
@frappe.whitelist() @frappe.whitelist()
def update_duplicate_km(doc,kilometer): def update_duplicate_km(doc, kilometer):
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)
# frappe.msgprint(str(output))
for data in output:
# frappe.msgprint(str(data['mat']))
km.append('duplicate_kilometer_mapping_items', {
'kilometer': data['kilometer'],
'mat': data['mat'],
'sub_systems': data['sub_systems'],
'row_name': data['row_name']
})
km.save(ignore_permissions=True)
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)
# frappe.msgprint(str(output))
for data in output:
# frappe.msgprint(str(data['mat']))
km.append('duplicate_kilometer_mapping_items', {
'kilometer': data['kilometer'],
'mat': data['mat'],
'sub_systems': data['sub_systems'],
'row_name': data['row_name']
})
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(
ress = frappe.get_doc("Kilometer Mapping",docname) f"""select kilometer,mat,sub_systems,applicable,row_name from `tabKilometer Mapping_Items` where parent='{doc}'""", as_dict=1)
ress.config_kilometer = [] ress = frappe.get_doc("Kilometer Mapping", docname)
for d in res: ress.config_kilometer = []
ress.append("config_kilometer",d) for d in res:
ress.add_comment(text=_("data added"+str(res))) ress.append("config_kilometer", d)
ress.save() ress.add_comment(text=_("data added"+str(res)))
frappe.db.commit() ress.save()
return {"status":"success"} frappe.db.commit()
return {"status": "success"}

Loading…
Cancel
Save