@ -51,35 +51,19 @@ class Publish(Document):
for v in variant :
self . variant_mapping_details = self . variant_mapping_details + \
str ( v ) + ' \n '
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=1)
km_mapping_record = frappe . db . sql ( """ select name from `tabKilometer Mapping` where variant_mapping = " {0 } " and
language = ' {1} ' ; """ .format(str(v), self.language), as_dict=1)
for km_mapping in km_mapping_record :
self . kilometer_mapping_details = self . kilometer_mapping_details + \
str ( km_mapping . name ) + ' \n '
def on_submit ( self ) :
""" qwik_service """
if self . docstatus == 1 and self . publish_status == ' To Publish ' and self . publish_module == ' Qwik Service ' and self . qwik_service_publish_docs :
qwik_service_publish ( self . vehicle , self . vehicle_id , self . variant ,
self . language , self . publish_type ,
self . release_description , self . qwik_service_publish_docs )
frappe . db . sql (
""" update `tabPublish` set publish_status= ' Published ' where name= ' {0} ' ; """ . format ( self . name ) )
variant_list = frappe . db . sql (
f ''' SELECT distinct(variant) as variant FROM `tabQwik Service Publish Docs` where parent = ' { self . name } ' ; ''' , as_dict = 1 )
update_publish_mapping ( self . vehicle , variant_list ,
self . language , self . publish_module , self . publish_type )
if self . publish_type == ' Global ' :
update_qwik_published_docs ( self )
try :
""" Feature Finder """
if self . docstatus == 1 and self . publish_status == ' To Publish ' and self . publish_module == ' Feature Finder ' and self . feature_finder_publish_docs :
feature_finder_publish ( self . vehicle , self . vehicle_id ,
self . language , self . publish_type ,
self . release_description , self . feature_finder_publish_docs , self . variant )
frappe . db . sql (
""" update `tabPublish` set publish_status= ' Published ' where name= ' {0} ' ; """ . format ( self . name ) )
variant_list = frappe . db . sql (
f ''' SELECT distinct(variant) as variant FROM `tabFeature Finder Publish Docs` where parent = ' { self . name } ' ; ''' , as_dict = 1 )
@ -94,19 +78,30 @@ class Publish(Document):
self . language , self . publish_type ,
self . release_description , self . variant ,
self . repiar_checksheet_publish_docs )
frappe . db . sql (
""" update `tabPublish` set publish_status= ' Published ' where name= ' {0} ' ; """ . format ( self . name ) )
if self . publish_type == ' Global ' :
update_repair_published_docs ( self )
""" qwik_service """
if self . docstatus == 1 and self . publish_status == ' To Publish ' and self . publish_module == ' Qwik Service ' and self . qwik_service_publish_docs :
qwik_service_publish ( self . vehicle , self . vehicle_id , self . variant ,
self . language , self . publish_type ,
self . release_description , self . qwik_service_publish_docs )
variant_list = frappe . db . sql (
f ''' SELECT distinct(variant) as variant FROM `tabQwik Service Publish Docs` where parent = ' { self . name } ' ; ''' , as_dict = 1 )
update_publish_mapping ( self . vehicle , variant_list ,
self . language , self . publish_module , self . publish_type )
if self . publish_type == ' Global ' :
update_qwik_published_docs ( self )
""" Special Tools Information """
if self . docstatus == 1 and self . publish_status == ' To Publish ' and self . publish_module == ' Special Tool ' and self . special_tool_publish_docs :
special_tool_publish ( self . vehicle , self . vehicle_id ,
self . publish_type ,
self . release_description ,
self . special_tool_publish_docs )
frappe . db . sql (
""" update `tabPublish` set publish_status= ' Published ' where name= ' {0} ' ; """ . format ( self . name ) )
if self . publish_type == ' Global ' :
update_special_tool_publish_docs ( self )
@ -115,8 +110,6 @@ class Publish(Document):
torque_manual_publish ( self . vehicle , self . vehicle_id ,
self . language , self . publish_type ,
self . release_description , self . torque_manual_publish_docs , self . variant )
frappe . db . sql (
""" update `tabPublish` set publish_status= ' Published ' where name= ' {0} ' ; """ . format ( self . name ) )
variant_list = frappe . db . sql (
f ''' SELECT distinct(variant) as variant FROM `tabTorque Manual Publish Docs` where parent = ' { self . name } ' ; ''' , as_dict = 1 )
@ -131,11 +124,16 @@ class Publish(Document):
self . language , self . publish_type ,
self . release_description , self . variant ,
self . training_information_publish_docs )
frappe . db . sql (
""" update `tabPublish` set publish_status= ' Published ' where name= ' {0} ' ; """ . format ( self . name ) )
# if not self.training_information_publish_docs:
# frappe.throw("no data added" )
if self . publish_type == ' Global ' :
update_training_published_docs ( self )
""" Update Publish status """
frappe . db . sql (
""" update `tabPublish` set publish_status= ' Published ' where name= ' {0} ' ; """ . format ( self . name ) )
""" Update Vehicle and language Publihs Status """
if self . publish_type == ' Internal ' :
frappe . db . sql (
''' update `tabVehicle` set internal_publish = 1 where vehicle= ' {0} ' ; ''' . format ( self . vehicle ) )
@ -149,6 +147,9 @@ class Publish(Document):
frappe . db . sql (
''' update `tabCustom Languages` set global_publish = 1 where lang_code= ' {0} ' ; ''' . format ( self . language ) )
except Exception as e :
frappe . throw ( str ( e ) )
def on_cancel ( self ) :
""" Published document should not allow to cancel """
if self . publish_status == " Published " :
@ -161,9 +162,9 @@ def update_procedure(vehicle, lang, publish_type, doc):
current_db_name = frappe . conf . get ( " db_name " )
procedure_status = frappe . db . sql ( """ select p.name,p.update_procedure_status,pro.name,p.variant_mapping,p.system,p.sub_system,p.asset_category,
p . item_category , p . variant , p . procedure_link , p . procedure_status , pro . name , pro . workflow_state
from { 0 } . ` tabPublish_Docs ` as p , { 0 } . ` tabProcedure ` as pro
where p . parent = " {1 } " and p . procedure_link = pro . name and pro . workflow_state != p . update_procedure_status
and p . procedure_link is not null """ .format(current_db_name, doc.name), as_dict=1)
from ` tabPublish_Docs ` as p , ` tabProcedure ` as pro
where p . parent = " {0 } " and p . procedure_link = pro . name and pro . workflow_state != p . update_procedure_status
and p . procedure_link is not null """ .format(doc.name), as_dict=1)
l = len ( procedure_status )
if procedure_status :
for x in procedure_status :
@ -209,27 +210,6 @@ def update_procedure(vehicle, lang, publish_type, doc):
""" Generate Publish versions """
def update_qwik_published_docs ( self ) :
try :
for d in self . qwik_service_publish_docs :
frappe . db . sql (
""" UPDATE `tabQwik Service` set is_published=1 where name= ' {0} ' ; """ . format ( d . parent1 ) )
frappe . db . commit ( )
except Exception as ex :
return str ( ex )
def update_torque_manual_published_docs ( self ) :
try :
for d in self . torque_manual_publish_docs :
frappe . db . sql (
''' update `tabTorque Manual` set is_published=1 where name= ' {0} ' ; ''' . format ( d . parent1 ) )
frappe . db . commit ( )
except Exception as e :
raise e
def update_publish_mapping ( vehicle , variant_list , language , module , publish_type ) :
try :
@ -666,7 +646,7 @@ def update_feature_published_docs(self):
try :
for d in self . feature_finder_publish_docs :
frappe . db . sql (
""" UPDATE `tabFeature Finder` set is_published=1 where name= ' {0} ' ; """ . format ( d . parent1 ) )
''' update `tabFeature Finder` set is_published=1 where name= ' {0} ' ; ''' . format ( d . parent1 ) )
frappe . db . commit ( )
except Exception as e :
@ -678,30 +658,50 @@ def update_repair_published_docs(self):
for d in self . repiar_checksheet_publish_docs :
frappe . db . sql (
""" UPDATE `tabRepair Service Mapping` set published=1 where name= ' {0} ' ; """ . format ( d . parent_name ) )
''' update `tabRepair Service Mapping` set published=1 where name= ' {0} ' ; ''' . format ( d . parent_name ) )
frappe . db . commit ( )
except Exception as e :
frappe . throw ( str ( e ) )
def update_qwik_published_docs ( self ) :
try :
for d in self . qwik_service_publish_docs :
frappe . db . sql (
''' update `tabQwik Service` set is_published=1 where name= ' {0} ' ; ''' . format ( d . parent1 ) )
frappe . db . commit ( )
except Exception as ex :
return str ( ex )
def update_special_tool_publish_docs ( self ) :
try :
for d in self . special_tool_publish_docs :
frappe . db . sql (
""" UPDATE `tabSpecial Tool Information` set published=1 where name= ' {0} ' ; """ . format ( d . parent1 ) )
''' update `tabSpecial Tool Information` set published=1 where name= ' {0} ' ; ''' . format ( d . parent1 ) )
frappe . db . commit ( )
except Exception as e :
frappe . throw ( str ( e ) )
def update_training_published_docs ( self ) :
def update_torque_manual _published_docs ( self ) :
try :
for d in self . training_inf ormatio n_publish :
for d in self . torque_ manual _publish_docs :
frappe . db . sql (
""" UPDATE `tabTraining Information` set published=1 where name= ' {0} ' ; """ . format ( d . parent1 ) )
''' update `tabTorque Manual` set is_published=1 where name= ' {0} ' ; ''' . format ( d . parent1 ) )
frappe . db . commit ( )
except Exception as e :
raise e
def update_training_published_docs ( self ) :
try :
for d in self . training_information_publish_docs :
frappe . db . sql (
''' update `tabTraining Information` set is_published=1 where name= ' {0} ' ; ''' . format ( d . parent1 ) )
frappe . db . commit ( )
except Exception as e :
frappe . throw ( str ( e ) )
@ -762,13 +762,16 @@ def repair_checksheet_publish(vehicle, vehicle_id,
""" Create Folder For Publish """
create_publish_folders ( folder_url )
file_path = folder_url + " / " + publish_type + " / " + \
vehicle . replace ( ' ' , ' - ' ) + ' -repair_check_sheet ' + ' .json '
# full_update_folder_url = folder_url + "/" + "{}".format(publish_type)+"_Full_Update"
global_file_path = folder_url + " / " + ' Global ' + " / " + \
vehicle . replace ( ' ' , ' - ' ) + ' -repair_check_sheet ' + ' .json '
check_inter_file = folder_url + " / " + ' Internal ' + " / " + \
vehicle . replace ( ' ' , ' - ' ) + ' -repair_check_sheet ' + ' .json '
""" Append Published Data to Json """
logger . info (
f ' Repair Checksheet Data Append Start:: { vehicle } - { language } - { publish_type } ' )
@ -783,7 +786,7 @@ def repair_checksheet_publish(vehicle, vehicle_id,
''' update existing global json file '''
if os . path . isfile ( global_file_path ) and publish_type == ' Internal ' :
if os . path . isfile ( global_file_path ) :
# if os.path.isfile(global_file_path) :
with open ( global_file_path ) as f :
published_data = json . load ( f )
for i in parent :
@ -846,6 +849,7 @@ def repair_checksheet_publish(vehicle, vehicle_id,
vehicle . replace ( ' ' , ' - ' ) + ' -repair_check_sheet ' + ' .json '
if os . path . isfile ( internal_check ) :
os . remove ( internal_check )
if publish_repair_checksheet == 1 :
""" Save publish file """
@ -1502,9 +1506,10 @@ def torque_manual_publish(vehicle=None, vehicle_id=None,
torque_manual [ ' data ' ] [ 0 ] )
else :
frappe . throw ( ' failed to publish ' )
torque_manual_tmp = get_latest_data (
{ ' data ' : torque_manual_tmp } , { ' data ' : [ ] } )
# torque_manual_tmp = get_latest_data(
# {'data': torque_manual_tmp}, {'data': []})
frappe . log_error ( ' before ' + str ( torque_manual_tmp ) )
vehi_data = create_df ( torque_manual_tmp )
latest_pub_data [ ' data ' ] = vehi_data
@ -1577,6 +1582,7 @@ def training_information_publish(vehicle, vehicle_id,
''' update existing global json file '''
if os . path . isfile ( global_file_path ) and publish_type == ' Internal ' :
frappe . log_error ( str ( ' Global Exits ' ) )
if os . path . isfile ( global_file_path ) :
with open ( global_file_path ) as f :
published_data = json . load ( f )
@ -1627,6 +1633,7 @@ def training_information_publish(vehicle, vehicle_id,
' data ' : training_information_tmp1 } )
else :
for i in parent :
training_information = training_information_data (
vehicle , language , publish_type , i . parent1 )
@ -1635,9 +1642,11 @@ def training_information_publish(vehicle, vehicle_id,
publish_training_information = 1
if len ( training_information [ ' data ' ] ) :
training_information_tmp . append (
training_information [ ' data ' ] [ 0 ] )
training_information [ ' data ' ] )
training_information_tmp = get_latest_data (
{ ' data ' : training_information_tmp } , { ' data ' : [ ] } )
frappe . log_error ( str ( training_information_tmp ) )
if publish_type == " Global " :
""" Remove Internal File On Global Publish """
@ -1652,8 +1661,8 @@ def training_information_publish(vehicle, vehicle_id,
with open ( file_path , ' w ' ) as outfile :
outfile . write ( json . dumps ( vehicle_data , indent = 4 , default = str ) )
with open ( file_path , ' w ' ) as outfile :
outfile . write ( json . dumps ( vehicle_data , indent = 4 , default = str ) )
# with open(file_path, 'w') as outfile :
# outfile.write(json.dumps(vehicle_data, indent=4, default=str) )
return 1 , file_path
@ -2020,7 +2029,7 @@ def training_information_data(vehicle=None, language=None,
and language = ' {language} ' and name = ' {parent} ' ; """ , as_dict=1)
for d in training_information_details :
d [ ' content ' ] = frappe . db . sql ( f """ select idx as ' display_order ' ,topic as file_type,case when topic != ' SCROM ' then file_url
d [ ' content ' ] = frappe . db . sql ( f """ select idx as ' display_order ' ,topic as file_type,case when topic != ' SCROM ' and topic != ' HTML ' then file_url
else scrom_file_url end as file_url , file_name from ` tabTraining Information Content Reference `
where parent = ' {d['name']} ' order by display_order ; """ , as_dict=1)
@ -2114,7 +2123,6 @@ def get_qwik_service(variant=None, language_label=None):
try :
data = frappe . db . sql ( """ select * from `tabQwik Service` where variant= ' %s '
and language = ' %s ' and is_published = ' %s ' ; """ % (variant, language_label, 0), as_dict=1)
return data
except Exception as e :
return e