Compare commits

...

3 Commits

  1. 86
      smart_service/apis/master_api.py
  2. 106
      smart_service/transactions/doctype/procedure/procedure.py

86
smart_service/apis/master_api.py

@ -528,50 +528,48 @@ def change_star_data():
def change_single_star_data():
count = frappe.db.sql('''
select count(*) from tabProcedure_Details where content like "%* %";''', as_dict=1)
print(count)
updated_list = []
error_list = []
data = frappe.db.sql('''
select name,parent,step_name,content_type,content,replace(content,'* ','abcxyz ') as new_content from tabProcedure_Details where content like "%* %";
''', as_dict=1)
for v in data:
try:
result = re.split(r"abcxyz ", v['new_content'], flags=0)
sts = '<ul>'
if len(result) > 1:
for a in range(1, len(result)):
sts += '<li>' + result[a] + '</li> '
sts += '</ul>'
frappe.db.sql(
f'''update tabProcedure_Details set content = "{sts}" where name = '{v['name']}'; ''')
frappe.db.commit()
v['new_content'] = sts
updated_list.append(v)
except Exception as e:
error_list.append({v['name']: e})
content_file = base_path + "/files/json_files/content_single_star_update.json"
error_file = base_path + "/files/json_files/content_error_single_star.json"
with open(error_file, 'w') as outfile:
try:
outfile.write(json.dumps(error_list))
except:
pass
with open(content_file, 'w') as outfile:
try:
outfile.write(json.dumps(updated_list))
except:
pass
return content_file
def get_single_star_data():
count = frappe.db.sql('''
select count(*) from tabProcedure_Details where content like "%*%";''', as_dict=1)
print(count)
# updated_list = []
# error_list = []
# data = frappe.db.sql('''
# select parent,step_name,content_type,content,name,replace(content,'*','abcxyz ') as new_content from tabProcedure_Details where content like "%*%";
# ''', as_dict=1)
# for v in data:
# try:
# result = re.split(r"abcxyz ", v['new_content'], flags=0)
# sts = '<ul>'
# if result[0] == '' and len(result) > 2:
# for a in range(1, len(result)):
# sts += '<li>' + result[a] + '</li> '
# sts += '</ul>'
# # print(sts)
# else:
# sts += '<li>' + result[1] + '</li> '
# sts += '</ul>'
# # print(sts)
# frappe.db.sql(
# f'''update tabProcedure_Details set content = "{sts}" where name = '{v['name']}'; ''')
# frappe.db.commit()
# v['new_content'] = sts
# updated_list.append(v)
# except Exception as e:
# error_list.append({v['name']: e})
# content_file = base_path + "/files/json_files/content_single_star_update.json"
# error_file = base_path + "/files/json_files/content_error_single_star.json"
# with open(error_file, 'w') as outfile:
# try:
# outfile.write(json.dumps(error_list))
# except:
# pass
# with open(content_file, 'w') as outfile:
# try:
# outfile.write(json.dumps(updated_list))
# except:
# pass
# return content_file

106
smart_service/transactions/doctype/procedure/procedure.py

@ -1,13 +1,15 @@
# 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):
@ -26,47 +28,63 @@ class Procedure(Document):
if x.content_type == "File":
if not x.file:
frappe.throw("Please choose the file in row no " + str(x.idx))
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))
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)
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)
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
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
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})
(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})
(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})
(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):
@ -78,7 +96,7 @@ def get_variant(doctype, txt, searchfield, start, page_len, filters):
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})
(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:
@ -86,6 +104,7 @@ def get_variant(doctype, txt, searchfield, start, page_len, filters):
else:
return []
@frappe.whitelist()
def get_systems(doctype, txt, searchfield, start, page_len, filters):
if not filters:
@ -94,12 +113,13 @@ def get_systems(doctype, txt, searchfield, start, page_len, 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)
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)
(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:
@ -109,6 +129,7 @@ def get_systems(doctype, txt, searchfield, start, page_len, filters):
else:
return []
@frappe.whitelist()
def get_subsystems(doctype, txt, searchfield, start, page_len, filters):
if not filters:
@ -118,12 +139,13 @@ def get_subsystems(doctype, txt, searchfield, start, page_len, filters):
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)
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})
(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:
@ -133,6 +155,7 @@ def get_subsystems(doctype, txt, searchfield, start, page_len, filters):
else:
return []
@frappe.whitelist()
def get_procedure(doctype, txt, searchfield, start, page_len, filters):
if not filters:
@ -143,12 +166,13 @@ def get_procedure(doctype, txt, searchfield, start, page_len, filters):
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)
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})
(`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:
@ -158,51 +182,65 @@ def get_procedure(doctype, txt, searchfield, start, page_len, filters):
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)
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))
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))
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))
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})
(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})
(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)
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)
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)
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'])
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.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…
Cancel
Save