Browse Source

Kilometer mapping fix

master
venkataakhil 1 year ago
parent
commit
beaa118e44
  1. 14
      smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.js
  2. 43
      smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.py

14
smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.js

@ -56,6 +56,9 @@ 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") {
@ -69,7 +72,7 @@ frappe.ui.form.on('Kilometer Mapping', {
}, },
refresh: function (frm) { refresh: function (frm) {
//custom button //custom duplicate 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',
@ -96,13 +99,19 @@ frappe.ui.form.on('Kilometer Mapping', {
}, },
callback: function (r) { callback: function (r) {
if (r.message && r.message['status'] == "success") { if (r.message && r.message['status'] == "success") {
frm.doc.workflow_state = 'Draft';
frm.set_value('workflow_state','Draft')
cur_frm.refresh_fields("config_kilometer"); cur_frm.refresh_fields("config_kilometer");
cur_frm.refresh_fields("workflow_state");
frm.save() frm.save()
frappe.show_alert({ frappe.show_alert({
message: __('Saved'), message: __('Saved'),
indicator: 'green' indicator: 'green'
}, 5); }, 5);
frm.refresh() // frm.refresh()
// frm.refresh_fields("config_kilometer");
cur_frm.reload_doc();
} }
} }
}) })
@ -119,7 +128,6 @@ 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);

43
smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.py

@ -6,41 +6,33 @@ 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( system_map = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping='{1}'""".format(current_db_name,doc),as_dict=True)
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( 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)
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( system_map = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping='{1}'""".format(current_db_name,doc),as_dict=True)
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( 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)
current_db_name, s.name), as_dict=True)
return sub_system return sub_system
@ -48,8 +40,7 @@ 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( 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)
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']))
@ -62,15 +53,29 @@ 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( res = frappe.db.sql(f"""select kilometer,mat,sub_systems,applicable,row_name from `tabKilometer Mapping_Items` where parent='{doc}'""",as_dict=1)
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:
ress.append("config_kilometer",d) ress.append("config_kilometer",d)
ress.add_comment(text=_("data added"+str(res))) ress.add_comment(text=_("data added"+str(res)))
ress.save() ress.save()
frappe.db.sql(f"""update `tabKilometer Mapping` set workflow_state = 'Draft' where name = '{docname}'
""")
frappe.db.commit() frappe.db.commit()
return {"status":"success"} return {"status":"success"}
# @frappe.whitelist()
# def km_filter(parent = None , record = None, km = None):
# if record == "All":
# km_filters = frappe.db.sql(f"""select * from `tabKilometer Mapping_Items` where parent ="{parent}" order by length(kilometer),kilometer;""",as_dict = 1)
# else:
# km_filters =frappe.db.sql(f"""select * from `tabKilometer Mapping_Items` where parent ="{parent}" and kilometer ="{km}" order by length(kilometer),kilometer """,as_dict = 1)
# return km_filters
Loading…
Cancel
Save