@ -18,10 +18,9 @@ base_url = os.path.expanduser(
" ~ " ) + " /frappe-bench/sites/ " + site_name + " /public " + " /json_files " + " /Other_Module "
frappe . utils . logger . set_log_level ( " DEBUG " )
success_reponse = { " status " : 1 , " data " : " " , " message " : " " }
failure_reponse = { " status " : 0 , " data " : " " , " error " : " " }
class PublishTest ( Document ) :
def validate ( self ) :
self . published_date = str ( date . today ( ) )
@ -48,9 +47,6 @@ class PublishTest(Document):
str ( km_mapping . name ) + ' \n '
def on_submit ( self ) :
if self . docstatus == 1 and self . publish_status == ' To Publish ' and self . publish_module == ' Others ' and self . publish_type == ' Internal ' :
# 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 ) )
if self . docstatus == 1 and self . publish_module == ' Others ' and self . publish_type == ' Global ' :
@ -425,7 +421,7 @@ def update_procedure_value(name, file_path):
frappe . db . commit ( )
@ frappe . whitelist ( )
@ frappe. whitelist ( )
def get_service_repair ( vehicle , language_label , publish_type ) :
data = frappe . db . sql ( f '''
select * from ` tabRepair Service Mapping ` where vehicle = ' {vehicle} ' and language = ' {language_label} ' and published = 0 ;
@ -448,43 +444,43 @@ def repair_checksheet_publish(vehicle,vehicle_id,language,publish_type,release_d
''' Create Folder For Publish '''
create_publish_folders ( folder_url )
file_path = folder_url + " / " + publish_type + " / " + vehicle . replace ( ' ' ,
' - ' ) + ' .json '
try :
''' Append Published Data to Json '''
logger . info ( f ' Repair Checksheet Data Append Start:: { vehicle } - { language } - { publish_type } ' )
vehicle_data = {
' vehicle ' : vehicle ,
' vehicle_myid ' : vehicle_id ,
' publish_type ' : publish_type ,
' publish_description ' : release_description ,
' publish_language ' : language ,
' data ' : ' '
}
repair_checksheet_tmp = [ ]
for i in parent :
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_check_sheet ' + ' .json '
# try:
''' Append Published Data to Json '''
logger . info ( f ' Repair Checksheet Data Append Start:: { vehicle } - { language } - { publish_type } ' )
vehicle_data = {
' vehicle ' : vehicle ,
' vehicle_myid ' : vehicle_id ,
' publish_type ' : publish_type ,
' publish_description ' : release_description ,
' publish_language ' : language ,
' data ' : ' '
}
repair_checksheet_tmp = [ ]
for i in parent :
repair_checksheet = repair_checksheet_data ( vehicle , language , publish_type , i . parent_name )
if repair_checksheet [ ' status ' ] == 1 :
publish_repair_checksheet = 1
if len ( repair_checksheet [ ' data ' ] ) :
repair_checksheet_tmp . append ( repair_checksheet [ ' data ' ] [ 0 ] )
if publish_repair_checksheet == 1 :
""" Save publish file """
vehicle_data [ ' data ' ] = { ' repair_checksheet ' : repair_checksheet_tmp }
with open ( file_path , ' w ' ) as outfile :
outfile . write ( json . dumps ( vehicle_data , indent = 4 , default = str ) )
else :
logger . error ( f ' { vehicle } - { language } - { publish_type } error in json creation ' )
if publish_repair_checksheet == 1 :
""" Save publish file """
vehicle_data [ ' data ' ] = { ' repair_checksheet ' : repair_checksheet_tmp }
with open ( file_path , ' w ' ) as outfile :
outfile . write ( json . dumps ( vehicle_data , indent = 4 , default = str ) )
return 1 , file_path
except Exception as e :
logger . info ( f ' { vehicle } - { language } - { publish_type } error in json creation ' + str ( e ) )
return e
# except Exception as e:
# logger.info(f'{vehicle}-{language}-{publish_type} error in json creation'+str(e))
# frappe.throw('Failed To Publish')
# return e
except Exception as e :
return e
frappe . throw ( ' Failed To Publish ' )
def update_published_docs ( self ) :
try :
if self . repair_checksheet_publish :
@ -492,7 +488,7 @@ def update_published_docs(self):
for d in self . repair_checksheet_publish :
frappe . db . sql (
""" UPDATE `tabRepair Service Mapping` set published=1 where name= ' {0} ' """ . format ( i . 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 ) )
@ -521,7 +517,7 @@ def repair_checksheet_data(vehicle=None,language=None,publish_type=None,parent=N
logger = frappe . logger ( logger_file , allow_site = True , file_count = 100 )
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
` tabRepair Service Mapping ` where vehicle = ' {vehicle} ' and language = ' {language} ' and active_status = ' Active ' and name = ' {parent} ' """ , as_dict=1)
` tabRepair Service Mapping ` where vehicle = ' {vehicle} ' and language = ' {language} ' and name = ' {parent} ' """ , as_dict=1)
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`
where parent = ' {d['name']} ' order by display_order ; """ , as_dict=1)