# Copyright (c) 2021, Hard n Soft Technologies Pvt Ltd and contributors
# For license information, please see license.txt
importre
importsys
importfrappe
fromfrappe.model.documentimportDocument
importfrappe,json
importfrappe
importjson
current_db_name=frappe.conf.get("db_name")
importsys
sys.tracebacklimit=0
importre
sys.tracebacklimit=0
classProcedure(Document):
defvalidate(self):
@ -26,47 +28,63 @@ class Procedure(Document):
ifx.content_type=="File":
ifnotx.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))
ifx.content_type!="File":
ifnotx.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))
ifnotself.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()
defget_doc_status(docname):
self=frappe.get_doc("Procedure",docname)
self=frappe.get_doc("Procedure",docname)
returnself.workflow_state
@frappe.whitelist()
defget_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)
defget_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(
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)
ifsys_mapping:
forxinsys_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
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)
ifsys_mapping:
forxinsys_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
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)
ifsys_mapping:
forxinsys_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
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)
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))
returnprocedure
@frappe.whitelist()
defget_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))
ifsystem:
returnsystem
@frappe.whitelist()
defget_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(
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(
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(
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(