@ -48,11 +48,15 @@ class PublishTest(Document):
str ( km_mapping . name ) + ' \n '
str ( km_mapping . name ) + ' \n '
def on_submit ( self ) :
def on_submit ( self ) :
if self . docstatus == 1 and self . publish_status == ' To Publish ' and self . publish_module == ' Others ' and self . publish_type == ' Internal ' :
if self . docstatus == 1 and self . publish_status == ' To Publish ' and self . publish_module == ' Others ' and self . publish_type == ' Internal ' :
repair_checksheet_publish ( self . vehicle , self . vehicle_id , self . language , self . publish_type , self . release_description , self . variant )
# for i in self.repair_checksheet_publish:
repair_checksheet_publish ( self . vehicle , self . vehicle_id , self . language , self . publish_type , self . release_description , self . variant , self . repair_checksheet_publish )
update_publish_status = frappe . db . sql ( """ update `tabPublish Test` set publish_status= ' Published ' where name= ' {0} ' """ . format ( self . name ) )
update_publish_status = frappe . db . sql ( """ update `tabPublish Test` set publish_status= ' Published ' where name= ' {0} ' """ . format ( self . name ) )
if self . docstatus == 1 and self . publish_module == ' Others ' and self . publish_type == ' Global ' :
if self . docstatus == 1 and self . publish_module == ' Others ' and self . publish_type == ' Global ' :
# for i in self.repair_checksheet_publish:
repair_checksheet_publish ( self . vehicle , self . vehicle_id , self . language , self . publish_type , self . release_description , self . variant , self . repair_checksheet_publish )
update_published_docs ( self )
update_published_docs ( self )
repair_checksheet_publish ( self . vehicle , self . vehicle_id , self . language , self . publish_type , self . release_description , self . variant )
@ -429,11 +433,11 @@ def get_service_repair(vehicle, language_label, publish_type):
return data
return data
def repair_checksheet_publish ( vehicle , vehicle_id , language , publish_type , release_description , variant ) :
def repair_checksheet_publish ( vehicle , vehicle_id , language , publish_type , release_description , variant , parent ) :
try :
try :
logger_file = f ' { vehicle } - { language } - { publish_type } '
logger_file = f ' { vehicle } - { language } - { publish_type } '
logger = frappe . logger ( logger_file , allow_site = True , file_count = 100 )
logger = frappe . logger ( logger_file , allow_site = True , file_count = 100 )
logger . info ( f ' Repair Checksheet Started- { vehicle } - { language } - { publish_type } ' )
logger . info ( f ' Repair Checksheet Started- { vehicle } - { language } - { publish_type } - { parent } ')
folder_url = base_url + " / " + vehicle . replace ( ' ' , ' - ' ) + " / " + language
folder_url = base_url + " / " + vehicle . replace ( ' ' , ' - ' ) + " / " + language
logger . info ( f ' Created Folder- { vehicle } - { language } - { publish_type } ' )
logger . info ( f ' Created Folder- { vehicle } - { language } - { publish_type } ' )
@ -456,12 +460,18 @@ def repair_checksheet_publish(vehicle,vehicle_id,language,publish_type,release_d
' publish_language ' : language ,
' publish_language ' : language ,
' data ' : ' '
' data ' : ' '
}
}
repair_checksheet = repair_checksheet_data ( vehicle , language , publish_type )
repair_checksheet_tmp = [ ]
if repair_checksheet [ ' status ' ] == 1 :
for i in parent :
publish_repair_checksheet = 1
frappe . msgprint ( str ( i . parent_name ) )
repair_checksheet = repair_checksheet_data ( vehicle , language , publish_type , i . parent_name )
frappe . msgprint ( str ( repair_checksheet ) )
if repair_checksheet [ ' status ' ] == 1 :
publish_repair_checksheet = 1
repair_checksheet_tmp . append ( repair_checksheet [ ' data ' ] [ 0 ] )
if publish_repair_checksheet == 1 :
if publish_repair_checksheet == 1 :
""" Save publish file """
""" Save publish file """
vehicle_data [ ' data ' ] = { ' repair_checksheet ' : repair_checksheet [ ' data ' ] }
vehicle_data [ ' data ' ] = { ' repair_checksheet ' : repair_checksheet_tmp }
with open ( file_path , ' w ' ) as outfile :
with open ( file_path , ' w ' ) as outfile :
outfile . write ( json . dumps ( vehicle_data , indent = 4 , default = str ) )
outfile . write ( json . dumps ( vehicle_data , indent = 4 , default = str ) )
else :
else :
@ -480,8 +490,9 @@ def update_published_docs(self):
if self . repair_checksheet_publish :
if self . repair_checksheet_publish :
try :
try :
for d in self . repair_checksheet_publish :
for d in self . repair_checksheet_publish :
frappe . db . sql (
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 ( i . parent_name ) )
frappe . db . commit ( )
frappe . db . commit ( )
except Exception as e :
except Exception as e :
frappe . throw ( str ( e ) )
frappe . throw ( str ( e ) )
@ -504,13 +515,13 @@ def create_publish_folders(folder_url):
frappe . throw ( str ( e ) )
frappe . throw ( str ( e ) )
return False
return False
def repair_checksheet_data ( vehicle = None , language = None , publish_type = None ) :
def repair_checksheet_data ( vehicle = None , language = None , publish_type = None , parent = None ) :
try :
try :
logger_file = f ' { vehicle } - { language } - { publish_type } '
logger_file = f ' { vehicle } - { language } - { publish_type } '
logger = frappe . logger ( logger_file , allow_site = True , file_count = 100 )
logger = frappe . logger ( logger_file , allow_site = True , file_count = 100 )
logger . info ( f " start of fetching repair checksheet data- { vehicle } - { language } " )
logger . info ( f " start of fetching repair checksheet data- { vehicle } - { language } " )
repair_service_details = frappe . db . sql ( f """ select vehicle,vehicle_id,name,language,check_list_name,active_status,display_order,my_id from
repair_service_details = frappe . db . sql ( f """ select vehicle,vehicle_id,name,language,check_list_name,active_status,display_order,my_id from
` tabRepair Service Mapping ` where vehicle = ' {vehicle} ' and language = ' {language} ' and active_status = ' Active ' """ , as_dict=1)
` tabRepair Service Mapping ` where vehicle = ' {vehicle} ' and language = ' {language} ' and active_status = ' Active ' and name = ' {parent} ' """ , as_dict=1)
for d in repair_service_details :
for d in repair_service_details :
d [ ' complaint ' ] = frappe . db . sql ( f """ select complaint,remedial_action_ok,remedial_action_not_ok,idx as display_order,active_status from `tabRepair Service Child`
d [ ' complaint ' ] = frappe . db . sql ( f """ select complaint,remedial_action_ok,remedial_action_not_ok,idx as display_order,active_status from `tabRepair Service Child`
where parent = ' {d['name']} ' order by display_order ; """ , as_dict=1)
where parent = ' {d['name']} ' order by display_order ; """ , as_dict=1)