@ -6,41 +6,33 @@ from frappe.model.document import Document
importsys
importsys
fromfrappeimport_
fromfrappeimport_
sys.tracebacklimit=0
sys.tracebacklimit=0
current_db_name=frappe.conf.get("db_name")
classKilometerMapping(Document):
classKilometerMapping(Document):
defonload(self):
defonload(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
forxinself.get("config_kilometer"):
forxinself.get("config_kilometer"):
idx+=1
idx+=1
x.idx=idx
x.idx=idx
@frappe.whitelist()
@frappe.whitelist()
defget_system(doc):
defget_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)
ifsystem_map:
ifsystem_map:
forsinsystem_map:
forsinsystem_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)
returnsystem
returnsystem
@frappe.whitelist()
@frappe.whitelist()
defget_subsystem(doc):
defget_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)
ifsystem_map:
ifsystem_map:
forsinsystem_map:
forsinsystem_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)
returnsub_system
returnsub_system
@ -48,8 +40,7 @@ def get_subsystem(doc):
defupdate_duplicate_km(doc,kilometer):
defupdate_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)
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=[]
fordinres:
fordinres:
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)