venkataakhil
2 years ago
1 changed files with 191 additions and 153 deletions
@ -1,208 +1,246 @@ |
|||
# Copyright (c) 2021, Hard n Soft Technologies Pvt Ltd and contributors |
|||
# For license information, please see license.txt |
|||
|
|||
import re |
|||
import sys |
|||
import frappe |
|||
from frappe.model.document import Document |
|||
import frappe,json |
|||
import frappe |
|||
import json |
|||
current_db_name = frappe.conf.get("db_name") |
|||
import sys |
|||
sys.tracebacklimit=0 |
|||
import re |
|||
sys.tracebacklimit = 0 |
|||
|
|||
|
|||
class Procedure(Document): |
|||
def validate(self): |
|||
if self.procedure_details: |
|||
for x in self.get("procedure_details"): |
|||
if x.content: |
|||
|
|||
res_str = re.sub("–", "—", x.content) |
|||
res_str = re.sub("—", "–", res_str) |
|||
res_str = re.sub("‘", "‘", res_str) |
|||
res_str = re.sub("’", "’", res_str) |
|||
res_str = re.sub("“", "“", res_str) |
|||
res_str = re.sub("â€", "”", res_str) |
|||
res_str = re.sub("Â", "", res_str) |
|||
x.content = res_str |
|||
|
|||
if x.content_type == "File": |
|||
if not x.file: |
|||
frappe.throw("Please choose the file in row no " + str(x.idx)) |
|||
if x.content_type != "File": |
|||
if not x.content: |
|||
frappe.throw("Please enter the content in row no " + str(x.idx)) |
|||
def validate(self): |
|||
if self.procedure_details: |
|||
for x in self.get("procedure_details"): |
|||
if x.content: |
|||
|
|||
res_str = re.sub("–", "—", x.content) |
|||
res_str = re.sub("—", "–", res_str) |
|||
res_str = re.sub("‘", "‘", res_str) |
|||
res_str = re.sub("’", "’", res_str) |
|||
res_str = re.sub("“", "“", res_str) |
|||
res_str = re.sub("â€", "”", res_str) |
|||
res_str = re.sub("Â", "", res_str) |
|||
x.content = res_str |
|||
|
|||
if x.content_type == "File": |
|||
if not x.file: |
|||
frappe.throw( |
|||
"Please choose the file in row no " + str(x.idx)) |
|||
if x.content_type != "File": |
|||
if not x.content: |
|||
frappe.throw( |
|||
"Please enter the content in row no " + str(x.idx)) |
|||
|
|||
if not self.is_new(): |
|||
frappe.db.sql( |
|||
f"""UPDATE `tabSystem Mapping_Sub System` set procedure_is_published=0 where procedure='{self.name}';""") |
|||
frappe.db.commit() |
|||
|
|||
|
|||
@frappe.whitelist() |
|||
def get_doc_status(docname): |
|||
self = frappe.get_doc("Procedure",docname) |
|||
return self.workflow_state |
|||
self = frappe.get_doc("Procedure", docname) |
|||
return self.workflow_state |
|||
|
|||
|
|||
@frappe.whitelist() |
|||
def get_publish_details(procedure_name,status): |
|||
data=frappe.db.sql('''select pd.parent from {0}.`tabPublish_Docs` pd, {0}.`tabPublish` p where pd.procedure_link='{1}' and p.publish_status != '{2}' and pd.parent=p.name'''.format(current_db_name,procedure_name,status), as_list=True) |
|||
return data |
|||
def get_publish_details(procedure_name, status): |
|||
data = frappe.db.sql('''select pd.parent from {0}.`tabPublish_Docs` pd, {0}.`tabPublish` p where pd.procedure_link='{1}' and p.publish_status != '{2}' and pd.parent=p.name'''.format( |
|||
current_db_name, procedure_name, status), as_list=True) |
|||
return data |
|||
|
|||
|
|||
@frappe.whitelist() |
|||
def sub_systems(doctype, txt, searchfield, start, page_len, filters): |
|||
return frappe.db.sql(""" select name |
|||
return frappe.db.sql(""" select name |
|||
FROM {0}.`tabSub Systems` where |
|||
(name like "%%%(txt)s%%") order by creation 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 creation desc limit %(start)s, %(page_len)s """.format(current_db_name) % {'txt': txt, 'start': start, 'page_len': page_len}) |
|||
|
|||
|
|||
@frappe.whitelist() |
|||
def variant(doctype, txt, searchfield, start, page_len, filters): |
|||
return frappe.db.sql(""" select name,family_code,fuel,transmission,vehicle_segment,active_status |
|||
return frappe.db.sql(""" select name,family_code,fuel,transmission,vehicle_segment,active_status |
|||
FROM {0}.`tabVariant Mapping` where |
|||
(active_status like "%%%(txt)s%%" or vehicle_segment like "%%%(txt)s%%" or name like "%%%(txt)s%%" or variant like "%%%(txt)s%%" or family_code like "%%%(txt)s%%" or fuel like "%%%(txt)s%%" or transmission 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%%" or family_code like "%%%(txt)s%%" or fuel like "%%%(txt)s%%" or transmission 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 fuel(doctype, txt, searchfield, start, page_len, filters): |
|||
return frappe.db.sql(""" select name FROM {0}.tabFuel 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}) |
|||
return frappe.db.sql(""" select name FROM {0}.tabFuel 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}) |
|||
|
|||
|
|||
@frappe.whitelist() |
|||
def transmission(doctype, txt, searchfield, start, page_len, filters): |
|||
return frappe.db.sql(""" select name FROM {0}.tabTransmission 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}) |
|||
return frappe.db.sql(""" select name FROM {0}.tabTransmission 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}) |
|||
|
|||
|
|||
@frappe.whitelist() |
|||
def drive(doctype, txt, searchfield, start, page_len, filters): |
|||
return frappe.db.sql(""" select name FROM {0}.tabDrive 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}) |
|||
return frappe.db.sql(""" select name FROM {0}.tabDrive 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}) |
|||
|
|||
|
|||
@frappe.whitelist() |
|||
def get_variant(doctype, txt, searchfield, start, page_len, filters): |
|||
if not filters: |
|||
return [] |
|||
filters = frappe._dict(filters) |
|||
vm = filters.get('variant_mapping') |
|||
lang = filters.get('language') |
|||
if vm: |
|||
vehicle = frappe.db.get_value('Variant Mapping', vm, 'vehicle') |
|||
variant = frappe.db.sql("""select name,family_code,fuel,transmission,drive,active_status FROM {0}.`tabVariant Mapping` where vehicle = '{1}' and |
|||
(name like "%%%(txt)s%%" or active_status like "%%%(txt)s%%" or drive like "%%%(txt)s%%" or family_code like "%%%(txt)s%%" or fuel like "%%%(txt)s%%" or transmission like "%%%(txt)s%%") group by name limit %(start)s, %(page_len)s """.format(current_db_name,vehicle)%{'txt': txt, 'start': start, 'page_len': page_len}) |
|||
if variant: |
|||
return variant |
|||
else: |
|||
return [] |
|||
else: |
|||
return [] |
|||
if not filters: |
|||
return [] |
|||
filters = frappe._dict(filters) |
|||
vm = filters.get('variant_mapping') |
|||
lang = filters.get('language') |
|||
if vm: |
|||
vehicle = frappe.db.get_value('Variant Mapping', vm, 'vehicle') |
|||
variant = frappe.db.sql("""select name,family_code,fuel,transmission,drive,active_status FROM {0}.`tabVariant Mapping` where vehicle = '{1}' and |
|||
(name like "%%%(txt)s%%" or active_status like "%%%(txt)s%%" or drive like "%%%(txt)s%%" or family_code like "%%%(txt)s%%" or fuel like "%%%(txt)s%%" or transmission like "%%%(txt)s%%") group by name limit %(start)s, %(page_len)s """.format(current_db_name, vehicle) % {'txt': txt, 'start': start, 'page_len': page_len}) |
|||
if variant: |
|||
return variant |
|||
else: |
|||
return [] |
|||
else: |
|||
return [] |
|||
|
|||
|
|||
@frappe.whitelist() |
|||
def get_systems(doctype, txt, searchfield, start, page_len, filters): |
|||
if not filters: |
|||
return [] |
|||
filters = frappe._dict(filters) |
|||
vm = filters.get('variant_mapping') |
|||
lang = filters.get('language') |
|||
if vm: |
|||
sys_mapping = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping = '{1}' and language ='{2}'""".format(current_db_name,vm,lang),as_dict=True) |
|||
if sys_mapping: |
|||
for x in sys_mapping: |
|||
doc = frappe.get_doc('System Mapping', x.name) |
|||
systems = frappe.db.sql(""" select systems FROM {0}.`tabSystem Mapping_Sub System` where parent = '{1}' and |
|||
(systems like "%%%(txt)s%%") group by systems limit %(start)s, %(page_len)s """.format(current_db_name,doc.name)%{'txt': txt, 'start': start, 'page_len': page_len},as_list=True) |
|||
if systems: |
|||
return systems |
|||
else: |
|||
return [] |
|||
else: |
|||
return [] |
|||
else: |
|||
return [] |
|||
if not filters: |
|||
return [] |
|||
filters = frappe._dict(filters) |
|||
vm = filters.get('variant_mapping') |
|||
lang = filters.get('language') |
|||
if vm: |
|||
sys_mapping = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping = '{1}' and language ='{2}'""".format( |
|||
current_db_name, vm, lang), as_dict=True) |
|||
if sys_mapping: |
|||
for x in sys_mapping: |
|||
doc = frappe.get_doc('System Mapping', x.name) |
|||
systems = frappe.db.sql(""" select systems FROM {0}.`tabSystem Mapping_Sub System` where parent = '{1}' and |
|||
(systems like "%%%(txt)s%%") group by systems limit %(start)s, %(page_len)s """.format(current_db_name, doc.name) % {'txt': txt, 'start': start, 'page_len': page_len}, as_list=True) |
|||
if systems: |
|||
return systems |
|||
else: |
|||
return [] |
|||
else: |
|||
return [] |
|||
else: |
|||
return [] |
|||
|
|||
|
|||
@frappe.whitelist() |
|||
def get_subsystems(doctype, txt, searchfield, start, page_len, filters): |
|||
if not filters: |
|||
return [] |
|||
filters = frappe._dict(filters) |
|||
vm = filters.get('variant_mapping') |
|||
systems = filters.get('systems') |
|||
lang = filters.get('language') |
|||
if vm: |
|||
sys_mapping = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping = '{1}' and language = '{2}'""".format(current_db_name,vm,lang),as_dict=True) |
|||
if sys_mapping: |
|||
for x in sys_mapping: |
|||
doc = frappe.get_doc('System Mapping', x.name) |
|||
systems = frappe.db.sql(""" select sub_systems FROM {0}.`tabSystem Mapping_Sub System` where parent = '{1}' and systems = '{2}' and |
|||
(sub_systems like "%%%(txt)s%%") group by sub_systems limit %(start)s, %(page_len)s """.format(current_db_name,doc.name,systems)%{'txt': txt, 'start': start, 'page_len': page_len}) |
|||
if systems: |
|||
return systems |
|||
else: |
|||
return [] |
|||
else: |
|||
return [] |
|||
else: |
|||
return [] |
|||
if not filters: |
|||
return [] |
|||
filters = frappe._dict(filters) |
|||
vm = filters.get('variant_mapping') |
|||
systems = filters.get('systems') |
|||
lang = filters.get('language') |
|||
if vm: |
|||
sys_mapping = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping = '{1}' and language = '{2}'""".format( |
|||
current_db_name, vm, lang), as_dict=True) |
|||
if sys_mapping: |
|||
for x in sys_mapping: |
|||
doc = frappe.get_doc('System Mapping', x.name) |
|||
systems = frappe.db.sql(""" select sub_systems FROM {0}.`tabSystem Mapping_Sub System` where parent = '{1}' and systems = '{2}' and |
|||
(sub_systems like "%%%(txt)s%%") group by sub_systems limit %(start)s, %(page_len)s """.format(current_db_name, doc.name, systems) % {'txt': txt, 'start': start, 'page_len': page_len}) |
|||
if systems: |
|||
return systems |
|||
else: |
|||
return [] |
|||
else: |
|||
return [] |
|||
else: |
|||
return [] |
|||
|
|||
|
|||
@frappe.whitelist() |
|||
def get_procedure(doctype, txt, searchfield, start, page_len, filters): |
|||
if not filters: |
|||
return [] |
|||
filters = frappe._dict(filters) |
|||
vm = filters.get('variant_mapping') |
|||
systems = filters.get('systems') |
|||
sub_systems = filters.get('sub_systems') |
|||
lang = filters.get('language') |
|||
if vm: |
|||
sys_mapping = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping = '{1}' and language = '{2}'""".format(current_db_name,vm,lang),as_dict=True) |
|||
if sys_mapping: |
|||
for x in sys_mapping: |
|||
doc = frappe.get_doc('System Mapping', x.name) |
|||
procedure = frappe.db.sql(""" select `procedure` FROM {0}.`tabSystem Mapping_Sub System` where parent = '{1}' and systems = '{2}' and sub_systems = '{3}' and |
|||
(`procedure` like "%%%(txt)s%%") group by `procedure` limit %(start)s, %(page_len)s """.format(current_db_name,doc.name,systems,sub_systems)%{'txt': txt, 'start': start, 'page_len': page_len}) |
|||
if procedure: |
|||
return procedure |
|||
else: |
|||
return [] |
|||
else: |
|||
return [] |
|||
else: |
|||
return [] |
|||
|
|||
@frappe.whitelist() |
|||
def get_procedures(variant_mapping,systems,sub_systems,language): |
|||
sys_mapping = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping = '{1}' and language = '{2}'""".format(current_db_name,variant_mapping,language),as_dict=True) |
|||
if sys_mapping: |
|||
for x in sys_mapping: |
|||
doc = frappe.get_doc('System Mapping', x.name) |
|||
procedure = frappe.db.sql(""" select `procedure` FROM {0}.`tabSystem Mapping_Sub System` where parent = '{1}' and systems = '{2}' and sub_systems = '{3}'""".format(current_db_name,doc.name,systems,sub_systems)) |
|||
return procedure |
|||
if not filters: |
|||
return [] |
|||
filters = frappe._dict(filters) |
|||
vm = filters.get('variant_mapping') |
|||
systems = filters.get('systems') |
|||
sub_systems = filters.get('sub_systems') |
|||
lang = filters.get('language') |
|||
if vm: |
|||
sys_mapping = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping = '{1}' and language = '{2}'""".format( |
|||
current_db_name, vm, lang), as_dict=True) |
|||
if sys_mapping: |
|||
for x in sys_mapping: |
|||
doc = frappe.get_doc('System Mapping', x.name) |
|||
procedure = frappe.db.sql(""" select `procedure` FROM {0}.`tabSystem Mapping_Sub System` where parent = '{1}' and systems = '{2}' and sub_systems = '{3}' and |
|||
(`procedure` like "%%%(txt)s%%") group by `procedure` limit %(start)s, %(page_len)s """.format(current_db_name, doc.name, systems, sub_systems) % {'txt': txt, 'start': start, 'page_len': page_len}) |
|||
if procedure: |
|||
return procedure |
|||
else: |
|||
return [] |
|||
else: |
|||
return [] |
|||
else: |
|||
return [] |
|||
|
|||
|
|||
@frappe.whitelist() |
|||
def get_procedures(variant_mapping, systems, sub_systems, language): |
|||
sys_mapping = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping = '{1}' and language = '{2}'""".format( |
|||
current_db_name, variant_mapping, language), as_dict=True) |
|||
if sys_mapping: |
|||
for x in sys_mapping: |
|||
doc = frappe.get_doc('System Mapping', x.name) |
|||
procedure = frappe.db.sql(""" select `procedure` FROM {0}.`tabSystem Mapping_Sub System` where parent = '{1}' and systems = '{2}' and sub_systems = '{3}'""".format( |
|||
current_db_name, doc.name, systems, sub_systems)) |
|||
return procedure |
|||
|
|||
|
|||
@frappe.whitelist() |
|||
def get_systemid(systems): |
|||
system = frappe.db.sql(""" select myid FROM {0}.`tabSystems` where name = '{1}'""".format(current_db_name,systems)) |
|||
if system: |
|||
return system |
|||
system = frappe.db.sql(""" select myid FROM {0}.`tabSystems` where name = '{1}'""".format( |
|||
current_db_name, systems)) |
|||
if system: |
|||
return system |
|||
|
|||
|
|||
@frappe.whitelist() |
|||
def get_subsystemid(systems): |
|||
system = frappe.db.sql(""" select myid FROM {0}.`tabSub Systems` where name = '{1}'""".format(current_db_name,systems)) |
|||
if system: |
|||
return system |
|||
system = frappe.db.sql(""" select myid FROM {0}.`tabSub Systems` where name = '{1}'""".format( |
|||
current_db_name, systems)) |
|||
if system: |
|||
return system |
|||
|
|||
|
|||
@frappe.whitelist() |
|||
def procedure_name(doctype, txt, searchfield, start, page_len, filters): |
|||
return frappe.db.sql(""" select name FROM {0}.`tabProcedure Name` 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}) |
|||
return frappe.db.sql(""" select name FROM {0}.`tabProcedure Name` 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}) |
|||
|
|||
|
|||
@frappe.whitelist() |
|||
def procedure_step_name(doctype, txt, searchfield, start, page_len, filters): |
|||
return frappe.db.sql(""" select name FROM {0}.`tabProcedure Step Name` 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}) |
|||
return frappe.db.sql(""" select name FROM {0}.`tabProcedure Step Name` 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}) |
|||
|
|||
|
|||
@frappe.whitelist() |
|||
def update_system_id(name): |
|||
doc = frappe.get_doc("Procedure",name) |
|||
for table in doc.get("procedure_details"): |
|||
if table.content_type == "Link": |
|||
procedure = table.temp_cnt |
|||
system_mapping = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping = '{1}' and language = '{2}'""".format(current_db_name,doc.variant_mapping,doc.language),as_dict=True) |
|||
if system_mapping: |
|||
sm = system_mapping[0]['name'] |
|||
sys_procedure = frappe.db.sql("""select systems,sub_systems,system_id,sub_system_id,`procedure` from {0}.`tabSystem Mapping_Sub System` where parent = '{1}' and `procedure` = '{2}'""".format(current_db_name,sm,table.temp_cnt),as_dict=True) |
|||
if sys_procedure: |
|||
if table.temp_cnt == sys_procedure[0]['procedure']: |
|||
sys_id = doc.variant_mapping + ',' + str(sys_procedure[0]['system_id']) + ',' + str(sys_procedure[0]['sub_system_id']) |
|||
table.system_id = sys_id |
|||
frappe.db.sql("""update {0}.`tabProcedure_Details` set system_id = '{1}' where parent = '{2}' and temp_cnt = '{3}'""".format(current_db_name,sys_id,doc.name,table.temp_cnt) ) |
|||
frappe.db.commit() |
|||
|
|||
doc = frappe.get_doc("Procedure", name) |
|||
for table in doc.get("procedure_details"): |
|||
if table.content_type == "Link": |
|||
procedure = table.temp_cnt |
|||
system_mapping = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping = '{1}' and language = '{2}'""".format( |
|||
current_db_name, doc.variant_mapping, doc.language), as_dict=True) |
|||
if system_mapping: |
|||
sm = system_mapping[0]['name'] |
|||
sys_procedure = frappe.db.sql("""select systems,sub_systems,system_id,sub_system_id,`procedure` from {0}.`tabSystem Mapping_Sub System` where parent = '{1}' and `procedure` = '{2}'""".format( |
|||
current_db_name, sm, table.temp_cnt), as_dict=True) |
|||
if sys_procedure: |
|||
if table.temp_cnt == sys_procedure[0]['procedure']: |
|||
sys_id = doc.variant_mapping + ',' + \ |
|||
str(sys_procedure[0]['system_id']) + ',' + \ |
|||
str(sys_procedure[0]['sub_system_id']) |
|||
table.system_id = sys_id |
|||
frappe.db.sql("""update {0}.`tabProcedure_Details` set system_id = '{1}' where parent = '{2}' and temp_cnt = '{3}'""".format( |
|||
current_db_name, sys_id, doc.name, table.temp_cnt)) |
|||
frappe.db.commit() |
|||
|
Loading…
Reference in new issue