km_mapping_record=frappe.db.sql("""select name from {0}.`tabKilometer Mapping` where variant_mapping = '{1}' and language = '{2}'""".format(current_db_name,str(v),self.language),as_dict=True)
frappe.msgprint(str(l)+' Procedure Status to be updated, Please check the Publish Documents table.')
draft_procedure_status=frappe.db.sql("""select name from {0}.`tabPublish_Docs` where parent = '{1}' and update_procedure_status = 'Draft' and procedure_link is not null""".format(current_db_name,doc.name),as_dict=True)
frappe.msgprint(str(
l)+' Procedure Status to be updated, Please check the Publish Documents table.')
draft_procedure_status=frappe.db.sql(
"""select name from {0}.`tabPublish_Docs` where parent = '{1}' and update_procedure_status = 'Draft' and procedure_link is not null""".format(current_db_name,doc.name),as_dict=True)
publish_record=frappe.db.sql("""select name from {0}.`tabPublish_Docs` where update_procedure_status != procedure_status and update_procedure_status != 'Publish Ready' and parent = '{1}'""".format(current_db_name,doc.name),as_dict=True)
publish_record=frappe.db.sql("""select name from {0}.`tabPublish_Docs` where update_procedure_status != procedure_status and update_procedure_status != 'Publish Ready' and parent = '{1}'""".format(
current_db_name,doc.name),as_dict=True)
ifpublish_record:
len_publish=len(publish_record)
ifstr(table_len)==str(len_publish):
frappe.throw("There is no item for global publish")
###Generate Publish versions
# Generate Publish versions
@frappe.whitelist()
defcal_ver(vehicle,lang,publish_type,doc):
update_procedure(vehicle,lang,publish_type,doc)
defcal_ver(vehicle,lang,publish_type,doc):
update_procedure(vehicle,lang,publish_type,doc)
current_db_name=frappe.conf.get("db_name")
doc=frappe.get_doc("Publish",doc)
doc=frappe.get_doc("Publish",doc)
ver=frappe.db.sql("""select max(version),publish_type from {current_db_name}.tabPublish where vehicle = '{vehi}' and language = '{lang}';"""
frappe.db.sql("""update {0}.`tabPublish` set version = '{1}' where name = '{2}'""".format(current_db_name,v,doc.name))
frappe.db.sql("""update {0}.`tabPublish` set version = '{1}' where name = '{2}'""".format(
current_db_name,v,doc.name))
frappe.db.commit()
returnv
###Create global publish document for publish ready procedures
# Create global publish document for publish ready procedures
@frappe.whitelist()
defglobal_publish(doc):
doc=frappe.get_doc("Publish",doc)
doc=frappe.get_doc("Publish",doc)
current_db_name=frappe.conf.get("db_name")
procedure=frappe.db.sql("""select parent,name from {0}.`tabPublish_Docs` where parent = '{1}' and update_procedure_status='Publish Ready' and procedure_link is not null""".format(current_db_name,doc.name))
asset=frappe.db.sql("""select parent,name from {0}.`tabPublish_Docs` where parent = '{1}' and variant_mapping is not null and procedure_link is null""".format(current_db_name,doc.name))
procedure=frappe.db.sql(
"""select parent,name from {0}.`tabPublish_Docs` where parent = '{1}' and update_procedure_status='Publish Ready' and procedure_link is not null""".format(current_db_name,doc.name))
asset=frappe.db.sql("""select parent,name from {0}.`tabPublish_Docs` where parent = '{1}' and variant_mapping is not null and procedure_link is null""".format(
current_db_name,doc.name))
ifnotprocedureandnotasset:
frappe.throw("There is no item for global publish")
frappe.msgprint('Global Publish Created for '+publish_record.name)
@frappe.whitelist()
defold_publish(vehicle,language):
defold_publish(vehicle,language):
current_db_name=frappe.conf.get("db_name")
publish_record=frappe.db.sql("""select name,publish_type from {0}.`tabPublish` where vehicle = '{1}' and language = '{2}' and publish_status='To Publish' and publish_type = 'Internal' and docstatus != '2'""".format(current_db_name,vehicle,language),as_dict=True)
publish_record=frappe.db.sql("""select name,publish_type from {0}.`tabPublish` where vehicle = '{1}' and language = '{2}' and publish_status='To Publish' and publish_type = 'Internal' and docstatus != '2'""".format(
current_db_name,vehicle,language),as_dict=True)
ifpublish_record:
returnpublish_record
global_publish_record=frappe.db.sql("""select name,publish_type from {0}.`tabPublish` where vehicle = '{1}' and language = '{2}' and publish_status='To Publish' and publish_type = 'Global' and docstatus != '2'""".format(current_db_name,vehicle,language),as_dict=True)
global_publish_record=frappe.db.sql("""select name,publish_type from {0}.`tabPublish` where vehicle = '{1}' and language = '{2}' and publish_status='To Publish' and publish_type = 'Global' and docstatus != '2'""".format(
current_db_name,vehicle,language),as_dict=True)
ifglobal_publish_record:
returnglobal_publish_record
###Update System and Variant Mapping and its called from publish client script
# Update System and Variant Mapping and its called from publish client script
frappe.db.sql("""update {0}.`tabVariant Mapping_Assets` set published = '1' where parent = '{1}' and category = '{2}'""".format(current_db_name,variant.variant_mapping,variant.asset_category))
frappe.db.sql("""update {0}.`tabVariant Mapping_Assets` set published = '1' where parent = '{1}' and category = '{2}'""".format(
system_mapping=frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping = '{1}' and language = '{2}'""".format(current_db_name,variant.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(
frappe.db.sql("""update {0}.`tabSystem Mapping_System Assets` set published = '1' where parent = '{1}' and systems = '{2}'""".format(current_db_name,sm.name,variant.system))
frappe.db.sql("""update {0}.`tabSystem Mapping_System Assets` set published = '1' where parent = '{1}' and systems = '{2}'""".format(
frappe.db.sql("""update {0}.`tabSystem Mapping_Sub System` set procedure_is_published = '1' where parent = '{1}' and systems = '{2}' and sub_systems = '{3}'""".format(current_db_name,sm.name,variant.system,variant.sub_system))
frappe.db.sql("""update {0}.`tabSystem Mapping_Sub System` set procedure_is_published = '1' where parent = '{1}' and systems = '{2}' and sub_systems = '{3}'""".format(
vm_assets=frappe.db.sql("""select category,language,attach_file,active_status from {0}.`tabVariant Mapping_Assets` where parent = '{1}' and published = '0'""".format(current_db_name,doc.name),as_dict=True)
doc=frappe.get_doc("Variant Mapping",doc)
vm_assets=frappe.db.sql("""select category,language,attach_file,active_status from {0}.`tabVariant Mapping_Assets` where parent = '{1}' and published = '0'""".format(
current_db_name,doc.name),as_dict=True)
returnvm_assets
@frappe.whitelist()
defget_sm_asset(doc,name):
system_map=frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping='{1}' and name = '{2}'""".format(current_db_name,doc,name),as_dict=True)
defget_sm_asset(doc,name):
system_map=frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping='{1}' and name = '{2}'""".format(
current_db_name,doc,name),as_dict=True)
ifsystem_map:
forsinsystem_map:
doc=frappe.get_doc("System Mapping",s.name)
system_asset=frappe.db.sql("""select systems,language,active_status,system_asset from {0}.`tabSystem Mapping_System Assets` where parent = '{1}' and published = '0'""".format(current_db_name,s.name),as_dict=True)
doc=frappe.get_doc("System Mapping",s.name)
system_asset=frappe.db.sql("""select systems,language,active_status,system_asset from {0}.`tabSystem Mapping_System Assets` where parent = '{1}' and published = '0'""".format(
current_db_name,s.name),as_dict=True)
returnsystem_asset
@frappe.whitelist()
defget_system(doc,name):
system_map=frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping='{1}' and name = '{2}'""".format(current_db_name,doc,name),as_dict=True)
defget_system(doc,name):
system_map=frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping='{1}' and name = '{2}'""".format(
current_db_name,doc,name),as_dict=True)
ifsystem_map:
forsinsystem_map:
doc=frappe.get_doc("System Mapping",s.name)
system=frappe.db.sql("""select systems,sub_systems,active_status,symptom,component,estimate_time,rts,component,mat,procedure_status,`procedure` from {0}.`tabSystem Mapping_Sub System` where parent = '{1}' and procedure_is_published = '0'""".format(current_db_name,s.name),as_dict=True)
doc=frappe.get_doc("System Mapping",s.name)
system=frappe.db.sql("""select systems,sub_systems,active_status,symptom,component,estimate_time,rts,component,mat,procedure_status,`procedure` from {0}.`tabSystem Mapping_Sub System` where parent = '{1}' and procedure_is_published = '0'""".format(
current_db_name,s.name),as_dict=True)
returnsystem
@frappe.whitelist()
defmax_publish(doc):
doc=frappe.get_doc("Publish",doc)
ver=frappe.db.sql("""select max(version) from {0}.tabPublish where vehicle = '{1}' and language = '{2}';""".format(current_db_name,doc.vehicle,doc.language))
doc=frappe.get_doc("Publish",doc)
ver=frappe.db.sql("""select max(version) from {0}.tabPublish where vehicle = '{1}' and language = '{2}';""".format(