system_map=frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping='{1}'""".format(
current_db_name,doc),as_dict=True)
ifsystem_map:
forsinsystem_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)
returnsystem
sys.tracebacklimit=0
current_db_name=frappe.conf.get("db_name")
classKilometerMapping(Document):
defonload(self):
###Kilometer mapping config table idx allignment
@ -15,10 +41,9 @@ class KilometerMapping(Document):
forxinself.get("config_kilometer"):
idx+=1
x.idx=idx
@frappe.whitelist()
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(current_db_name,doc),as_dict=True)
ifsystem_map:
forsinsystem_map:
@ -28,34 +53,48 @@ def get_system(doc):
@frappe.whitelist()
defget_subsystem(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)
ifsystem_map:
forsinsystem_map:
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)
returnsub_system
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)
ifsystem_map:
forsinsystem_map:
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)
returnsub_system
@frappe.whitelist()
defupdate_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))
fordatainoutput:
# 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)
defupdate_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))
fordatainoutput:
# 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()
defget_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)
ress=frappe.get_doc("Kilometer Mapping",docname)
ress.config_kilometer=[]
fordinres:
ress.append("config_kilometer",d)
ress.add_comment(text=_("data added"+str(res)))
ress.save()
frappe.db.commit()
return{"status":"success"}
defget_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)
# Copyright (c) 2021, Hard n Soft Technologies Pvt Ltd and contributors
# For license information, please see license.txt
importsys
importfrappe
fromfrappe.model.documentimportDocument
current_db_name=frappe.conf.get("db_name")
importsys
sys.tracebacklimit=0
sys.tracebacklimit=0
classVariantMapping(Document):
defvalidate(self):
assets=frappe.db.sql("""select category,idx,active_status,attach_file from {0}.`tabVariant Mapping_Assets` where parent = '{1}'""".format(current_db_name,self.name),as_dict=True)
forxinassets:
foryinself.get("assets"):
ifx.idx==y.idxandy.category==x.category:
ify.active_status!=x.active_status:
y.published="0"
frappe.db.sql("""update {0}.`tabVariant Mapping_Assets` set published = '0' where parent = '{1}' and idx = '{2}'""".format(current_db_name,self.name,str(y.idx)))
frappe.db.commit()
ify.attach_file!=x.attach_file:
y.published="0"
frappe.db.sql("""update {0}.`tabVariant Mapping_Assets` set published = '0' where parent = '{1}' and idx = '{2}'""".format(current_db_name,self.name,str(y.idx)))
frappe.db.commit()
ifself.is_new():
data=frappe.db.sql("""select name from {0}.`tabVariant Mapping`
defvalidate(self):
assets=frappe.db.sql("""select category,idx,active_status,attach_file from {0}.`tabVariant Mapping_Assets` where parent = '{1}'""".format(
current_db_name,self.name),as_dict=True)
forxinassets:
foryinself.get("assets"):
ifx.idx==y.idxandy.category==x.category:
ify.active_status!=x.active_status:
y.published="0"
frappe.db.sql("""update {0}.`tabVariant Mapping_Assets` set published = '0' where parent = '{1}' and idx = '{2}'""".format(
current_db_name,self.name,str(y.idx)))
frappe.db.commit()
ify.attach_file!=x.attach_file:
y.published="0"
frappe.db.sql("""update {0}.`tabVariant Mapping_Assets` set published = '0' where parent = '{1}' and idx = '{2}'""".format(
current_db_name,self.name,str(y.idx)))
frappe.db.commit()
ifself.is_new():
data=frappe.db.sql("""select name from {0}.`tabVariant Mapping`