Browse Source

system mapping query string fix

master
venkataakhil 1 year ago
parent
commit
f03cb21c0b
  1. 68
      smart_service/transactions/doctype/system_mapping/system_mapping.py

68
smart_service/transactions/doctype/system_mapping/system_mapping.py

@ -14,9 +14,10 @@ class SystemMapping(Document):
###Set Procedure Status and Active status in DB level
for x in self.get("system_sub_systems"):
procedure = frappe.db.sql("""select name,workflow_state from {0}.`tabProcedure` where name = '{1}'""".format(current_db_name,x.procedure),as_dict=True)
procedure = frappe.db.get_value('Procedure', x.procedure, 'workflow_state')
frappe.db.sql("""update `tabSystem Mapping_Sub System` set procedure_status = '{0}' where parent = '{1}'
procedure = frappe.db.sql("""select name,workflow_state from {0}.`tabProcedure` where name = "{1}";""".format(
current_db_name,x.procedure),as_dict=1)
procedure = frappe.db.get_value("Procedure", x.procedure, "workflow_state")
frappe.db.sql("""update `tabSystem Mapping_Sub System` set procedure_status = "{0}" where parent = "{1}"
""".format(str(procedure),self.name))
frappe.db.commit()
# x.procedure_status = str(procedure)
@ -25,12 +26,13 @@ class SystemMapping(Document):
# x.save()
# frappe.flags.mute_messages = True
po = frappe.db.sql("""select procedure_status from {0}.`tabSystem Mapping_Sub System` where parent = '{1}'""".format(current_db_name,self.name))
# po = frappe.db.sql("""select procedure_status from {0}.`tabSystem Mapping_Sub System` where parent = "{1}";""".format(current_db_name,self.name))
frappe.db.commit()
km = frappe.db.sql("""select name,active_status from {0}.`tabKilometer Mapping` where variant_mapping = '{1}'""".format(current_db_name,self.variant_mapping),as_dict=True)
km = frappe.db.sql("""select name,active_status from {0}.`tabKilometer Mapping` where variant_mapping = "{1}";""".format(
current_db_name,self.variant_mapping),as_dict=True)
if km:
for status in km:
frappe.db.sql("""update `tabSystem Mapping` set km_active_status = '{0}' where name = '{1}'
frappe.db.sql("""update `tabSystem Mapping` set km_active_status = "{0}" where name = "{1}"
""".format(status.active_status,self.name))
frappe.db.commit()
# self.km_active_status = status.active_status
@ -38,17 +40,18 @@ class SystemMapping(Document):
def validate(self):
###On creation of System Mapping to create Kilometer Mapping record
km = frappe.db.sql("""select name from {0}.`tabKilometer Mapping` where variant_mapping = '{1}' and language = '{2}'""".format(current_db_name,self.variant_mapping,self.language),as_list=True)
km = frappe.db.sql("""select name from {0}.`tabKilometer Mapping` where variant_mapping = "{1}" and language = "{2}";""".format(current_db_name,self.variant_mapping,self.language),as_list=True)
if not km:
mat = []
km_record = frappe.new_doc("Kilometer Mapping")
km_record.variant_mapping = self.variant_mapping
km_record.language = self.language
vehicle_sk = frappe.db.sql("""select service_kilometers from {0}.`tabVehicle_SK` where parent = '{1}' order by service_kilometers""".format(current_db_name,self.vehicle),as_dict=True)
vehicle_sk = frappe.db.sql("""select service_kilometers from {0}.`tabVehicle_SK` where parent = "{1}"
order by service_kilometers""".format(current_db_name,self.vehicle),as_dict=1)
for service_km in vehicle_sk:
for sys in self.get('system_sub_systems'):
for sys in self.get("system_sub_systems"):
if sys.mat:
sub_system = km_record.append('config_kilometer', {})
sub_system = km_record.append("config_kilometer", {})
sub_system.kilometer = str(service_km.service_kilometers)
sub_system.mat = sys.mat
sub_system.systems = sys.systems
@ -61,16 +64,16 @@ class SystemMapping(Document):
###Should not allow duplicate mat code value
mat_code = []
for sm in self.get('system_sub_systems'):
for sm in self.get("system_sub_systems"):
if str(sm.mat):
if str(sm.mat) in mat_code:
frappe.throw('You Cannot Select Same MAT ' + str(sm.mat) + ' Multiple Times' + ' in Row no ' + str(sm.idx))
frappe.throw("You Cannot Select Same MAT " + str(sm.mat) + " Multiple Times" + " in Row no " + str(sm.idx))
else:
mat_code.append(sm.mat)
###If anything change system and subsystem table to be set Published flag as 0
systems = frappe.db.sql("""select systems,sub_systems,active_status,estimate_time,idx,rts,mat,cover_image,`procedure`
from {0}.`tabSystem Mapping_Sub System` where parent = '{1}'""".format(current_db_name,self.name),as_dict=True)
from {0}.`tabSystem Mapping_Sub System` where parent = "{1}";""".format(current_db_name,self.name),as_dict=1)
if systems:
for prev_system in systems:
for cur_system in self.get("system_sub_systems"):
@ -100,29 +103,30 @@ class SystemMapping(Document):
cur_system.procedure_is_published = "0"
update_procedure(current_db_name,self.name,str(cur_system.idx))
assets = frappe.db.sql("""select systems,idx,active_status,system_asset,remarks from {0}.`tabSystem Mapping_System Assets` where parent = '{1}'""".format(current_db_name,self.name),as_dict=True)
assets = frappe.db.sql("""select systems,idx,active_status,system_asset,remarks from {0}.`tabSystem Mapping_System Assets`
where parent = "{1}";""".format(current_db_name,self.name),as_dict=1)
if assets:
for x in assets:
for y in self.get("systems_assets"):
if x.idx == y.idx and y.systems == x.systems:
if y.active_status != x.active_status:
y.published = "0"
frappe.db.sql("""update {0}.`tabSystem Mapping_System Assets` set published = '0' where parent = '{1}' and idx = '{2}'""".format(current_db_name,self.name,str(y.idx)))
frappe.db.sql("""update {0}.`tabSystem Mapping_System Assets` set published = "0" where parent = "{1}" and idx = "{2}";""".format(current_db_name,self.name,str(y.idx)))
frappe.db.commit()
if y.system_asset != x.system_asset:
y.published = "0"
frappe.db.sql("""update {0}.`tabSystem Mapping_System Assets` set published = '0' where parent = '{1}' and idx = '{2}'""".format(current_db_name,self.name,str(y.idx)))
frappe.db.sql("""update {0}.`tabSystem Mapping_System Assets` set published = "0" where parent = "{1}" and idx = "{2}";""".format(current_db_name,self.name,str(y.idx)))
frappe.db.commit()
if y.remarks != x.remarks:
y.published = "0"
frappe.db.sql("""update {0}.`tabSystem Mapping_System Assets` set published = '0' where parent = '{1}' and idx = '{2}'""".format(current_db_name,self.name,str(y.idx)))
frappe.db.sql("""update {0}.`tabSystem Mapping_System Assets` set published = "0" where parent = "{1}" and idx = "{2}";""".format(current_db_name,self.name,str(y.idx)))
frappe.db.commit()
###Mandatory fields for system mapping table
for system in self.get("system_sub_systems"):
if not system.procedure:
frappe.throw('Procedure to be added in row no ' + str(system.idx))
values = self.get('system_sub_systems')
frappe.throw("Procedure to be added in row no " + str(system.idx))
values = self.get("system_sub_systems")
for i in range(0, len(values)):
if values[i].systems:
for x in range(i + 1, len(values)):
@ -142,7 +146,7 @@ class SystemMapping(Document):
###Method called from validation fucntion
def update_procedure(current_db_name,name,idx):
frappe.db.sql("""update {0}.`tabSystem Mapping_Sub System` set procedure_is_published = '0' where parent = '{1}' and idx = '{2}'""".format(current_db_name,name,idx))
frappe.db.sql("""update {0}.`tabSystem Mapping_Sub System` set procedure_is_published = "0" where parent = "{1}" and idx = "{2}";""".format(current_db_name,name,idx))
frappe.db.commit()
###Method called from system mapping js file
@ -156,7 +160,7 @@ def update_mat(doc,km,vehicle,type,idx,systems,sub_systems,mat_initial,mat_updat
###Updating MAT in kilometer mapping for edited mat
if type == "Edited":
subsystem_record = frappe.db.sql("""select systems,sub_systems,mat,idx from {0}.`tabSystem Mapping_Sub System` where parent = '{1}'""".format(current_db_name,doc.name),as_dict=True)
subsystem_record = frappe.db.sql("""select systems,sub_systems,mat,idx from {0}.`tabSystem Mapping_Sub System` where parent = "{1}";""".format(current_db_name,doc.name),as_dict=True)
for km in kilometer_mapping.get("config_kilometer"):
for sys in subsystem_record:
if str(sub_systems) == str(km.sub_systems) and str(idx) == str(km.row_name):
@ -172,9 +176,9 @@ def update_mat(doc,km,vehicle,type,idx,systems,sub_systems,mat_initial,mat_updat
###Insert MAT in kilometer mappnig for added mat
if mat:
if type == "Added" or type == "New":
vehicle_sk = frappe.db.sql("""select service_kilometers from {0}.`tabVehicle_SK` where parent = '{1}' order by service_kilometers""".format(current_db_name,vehicle),as_dict=True)
vehicle_sk = frappe.db.sql("""select service_kilometers from {0}.`tabVehicle_SK` where parent = "{1}" order by service_kilometers""".format(current_db_name,vehicle),as_dict=True)
for service_km in vehicle_sk:
sub_system = kilometer_mapping.append('config_kilometer', {})
sub_system = kilometer_mapping.append("config_kilometer", {})
sub_system.kilometer = str(service_km.service_kilometers)
sub_system.mat = str(mat)
sub_system.systems = str(systems)
@ -187,38 +191,38 @@ def update_mat(doc,km,vehicle,type,idx,systems,sub_systems,mat_initial,mat_updat
if type == "Deleted":
for km in kilometer_mapping.get("config_kilometer"):
if km.row_name == str(idx):
frappe.db.sql("""delete from {0}.`tabKilometer Mapping_Items` where parent = '{1}' and row_name = '{2}'""".format(current_db_name,kilometer_mapping.name,str(idx)))
frappe.db.sql("""delete from {0}.`tabKilometer Mapping_Items` where parent = "{1}" and row_name = "{2}";""".format(current_db_name,kilometer_mapping.name,str(idx)))
###Filter applied depends on last modified records and its called from system mapping js file
def variant(doctype, txt, searchfield, start, page_len, filters):
return frappe.db.sql(""" select name,variant,vehicle,vehicle_segment,active_status
FROM {0}.tabVariant where
(active_status like "%%%(txt)s%%" or vehicle_segment like "%%%(txt)s%%" or name like "%%%(txt)s%%" or variant like "%%%(txt)s%%") order by modified desc limit %(start)s, %(page_len)s """.format(current_db_name)%{'txt': txt, 'start': start, 'page_len': page_len})
(active_status like "%%%(txt)s%%" or vehicle_segment like "%%%(txt)s%%" or name like "%%%(txt)s%%" or variant like "%%%(txt)s%%") order by modified desc limit %(start)s, %(page_len)s """.format(current_db_name)%{"txt": txt, "start": start, "page_len": page_len})
@frappe.whitelist()
def systems(doctype, txt, searchfield, start, page_len, filters):
return frappe.db.sql(""" select name FROM {0}.tabSystems where
(name like "%%%(txt)s%%") order by modified desc limit %(start)s, %(page_len)s """.format(current_db_name)%{'txt': txt, 'start': start, 'page_len': page_len})
(name like "%%%(txt)s%%") order by modified desc limit %(start)s, %(page_len)s """.format(current_db_name)%{"txt": txt, "start": start, "page_len": page_len})
@frappe.whitelist()
def sub_systems(doctype, txt, searchfield, start, page_len, filters):
return frappe.db.sql(""" select name FROM {0}.`tabSub Systems` where
(name like "%%%(txt)s%%") order by modified desc limit %(start)s, %(page_len)s """.format(current_db_name)%{'txt': txt, 'start': start, 'page_len': page_len})
(name like "%%%(txt)s%%") order by modified desc limit %(start)s, %(page_len)s """.format(current_db_name)%{"txt": txt, "start": start, "page_len": page_len})
@frappe.whitelist()
def procedure(doctype, txt, searchfield, start, page_len, filters):
return frappe.db.sql(""" select name FROM {0}.`tabProcedure` where
(name like "%%%(txt)s%%") order by modified desc limit %(start)s, %(page_len)s """.format(current_db_name)%{'txt': txt, 'start': start, 'page_len': page_len})
(name like "%%%(txt)s%%") order by modified desc limit %(start)s, %(page_len)s """.format(current_db_name)%{"txt": txt, "start": start, "page_len": page_len})
@frappe.whitelist()
def system_filter(doctype, txt, searchfield, start, page_len, filters):
name = filters.get('system_filter')
system = frappe.db.sql("""select name FROM {0}.`tabSystems` where name LIKE '{1}' and
(name like "%%%(txt)s%%") order by modified desc limit %(start)s, %(page_len)s """.format(current_db_name,name)%{'txt': txt, 'start': start, 'page_len': page_len})
name = filters.get("system_filter")
system = frappe.db.sql("""select name FROM {0}.`tabSystems` where name LIKE "{1}" and
(name like "%%%(txt)s%%") order by modified desc limit %(start)s, %(page_len)s """.format(current_db_name,name)%{"txt": txt, "start": start, "page_len": page_len})
if system:
return system
else:
return frappe.db.sql(""" select name FROM {0}.`tabSystems` where
(name like "%%%(txt)s%%") order by modified desc limit %(start)s, %(page_len)s """.format(current_db_name)%{'txt': txt, 'start': start, 'page_len': page_len})
(name like "%%%(txt)s%%") order by modified desc limit %(start)s, %(page_len)s """.format(current_db_name)%{"txt": txt, "start": start, "page_len": page_len})

Loading…
Cancel
Save