@ -65,7 +65,23 @@ class Publish(Document):
self . repiar_checksheet_publish_docs )
update_publish_status = frappe . db . sql (
""" update `tabPublish` set publish_status= ' Published ' where name= ' {0} ' """ . format ( self . name ) )
if self . docstatus == 1 and self . publish_status == ' To Publish ' and self . publish_module == ' Qwik Service ' and self . publish_type == ' Internal ' :
qwik_service_publish ( self . vehicle , self . vehicle_id , self . variant ,
self . language , self . publish_type ,
self . release_description , self . qwik_service_publish_docs )
update_publish_status = frappe . db . sql (
""" update `tabPublish` set publish_status= ' Published ' where name= ' {0} ' """ . format ( self . name ) )
if self . docstatus == 1 and self . publish_status == ' To Publish ' and self . publish_module == ' Qwik Service ' and self . publish_type == ' Global ' 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 )
update_publish_status = frappe . db . sql (
""" update `tabPublish` set publish_status= ' Published ' where name= ' {0} ' """ . format ( self . name ) )
update_qwik_published_docs ( self )
update_publish_status = frappe . db . sql (
""" update `tabPublish` set publish_status= ' Published ' where name= ' {0} ' """ . format ( self . name ) )
if self . docstatus == 1 and self . publish_status == ' To Publish ' and self . publish_module == ' Feature Finder ' and self . publish_type == ' Internal ' and self . feature_finder_publish_docs :
feature_finder_publish ( self . vehicle , self . vehicle_id ,
self . language , self . publish_type ,
@ -90,8 +106,24 @@ class Publish(Document):
update_publish_status = frappe . db . sql (
""" update `tabPublish` set publish_status= ' Published ' where name= ' {0} ' """ . format ( self . name ) )
if self . docstatus == 1 and self . publish_status == ' To Publish ' and self . publish_module == ' Special Tool ' and self . publish_type == ' Internal ' :
special_tool_publish ( self . vehicle , self . vehicle_id ,
self . publish_type ,
self . release_description ,
self . special_tool_publish_docs )
update_publish_status = frappe . db . sql (
""" update `tabPublish` set publish_status= ' Published ' where name= ' {0} ' """ . format ( self . name ) )
if self . docstatus == 1 and self . publish_status == ' To Publish ' and self . publish_module == ' Special Tool ' and self . publish_type == ' Global ' 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 )
update_special_tool_publish_docs ( self )
update_publish_status = frappe . db . sql (
""" update `tabPublish` set publish_status= ' Published ' where name= ' {0} ' """ . format ( self . name ) )
variant = self . variant_mapping_details . split ( ' /n ' )
frappe . log_error ( ' variant ' , str ( variant ) )
# for v in variant:
# frappe.log_error('v', str(v))
@ -156,7 +188,15 @@ def update_procedure(vehicle, lang, publish_type, doc):
frappe . throw ( " There is no item for global publish " )
# 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_publish_mapping ( vehicle , variant , language , module , publish_type ) :
frappe . set_user ( ' Administrator ' )
@ -322,7 +362,29 @@ def generate_global_publish(name, module_name):
" publish_module " : res . publish_module ,
" repiar_checksheet_publish_docs " : res . repiar_checksheet_publish_docs
} )
elif module_name == ' Qwik Service ' :
ret = frappe . get_doc ( {
" doctype " : " Publish " ,
" vehicle " : res . vehicle ,
" publish_type " : " Global " ,
" language " : res . language ,
" qwik_service_publish_docs " : res . qwik_service_publish_docs ,
" publish_status " : ' To Publish ' ,
" release_description " : res . release_description ,
" publish_module " : res . publish_module
} )
elif module_name == ' Special Tool ' :
ret = frappe . get_doc ( {
" doctype " : " Publish " ,
" vehicle " : res . vehicle ,
" publish_type " : " Global " ,
" special_tool_publish_docs " : res . special_tool_publish_docs ,
" publish_status " : ' To Publish ' ,
" release_description " : res . release_description ,
" publish_module " : res . publish_module
} )
ret . save ( )
return { " status " : " success " , " message " : ret . name , " url " : frappe . utils . get_url ( ) }
except Exception as e :
@ -518,6 +580,17 @@ def update_repair_published_docs(self):
except Exception as e :
frappe . throw ( str ( e ) )
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 ) )
frappe . db . commit ( )
except Exception as e :
frappe . throw ( str ( e ) )
def create_publish_folders ( folder_url ) :
try :
@ -533,7 +606,6 @@ def create_publish_folders(folder_url):
frappe . throw ( str ( e ) )
return False
''' New Module Publish Section '''
@ -647,6 +719,8 @@ def repair_checksheet_publish(vehicle, vehicle_id,
frappe . throw ( ' Failed To Publish ' )
def feature_finder_publish ( vehicle = None , vehicle_id = None ,
language = None , publish_type = None ,
release_description = None , parent = None ,
@ -759,6 +833,210 @@ def feature_finder_publish(vehicle=None, vehicle_id=None,
f ' { vehicle } - { language } - { publish_type } - { module_name } error in json creation ' + str ( e ) )
frappe . throw ( ' Failed To Publish ' )
def qwik_service_publish ( vehicle = None , vehicle_id = None , variant = None ,
language = None , publish_type = None ,
release_description = None , parent = None ) :
try :
logger_file = f ' { variant } - { language } - { publish_type } - Qwik_service '
logger = frappe . logger ( logger_file , allow_site = True , file_count = 100 )
logger . info (
f ' Qwik_service- { variant } - { language } - { publish_type } - { parent } ' )
folder_url = base_url + " / " + vehicle . replace ( ' ' , ' - ' ) + " / " + language
logger . info ( f ' Created Folder- { vehicle } - { language } - { publish_type } ' )
''' Publish Ready Flags '''
publish_qwik_service = 0
qwik_service_tmp = [ ]
qwik_service = ' '
''' Create Folder For Publish '''
create_publish_folders ( folder_url )
file_path = folder_url + " / " + publish_type + " / " + \
vehicle . replace ( ' ' , ' - ' ) + ' -qwik_service ' + ' .json '
global_file_path = folder_url + " / " + " Global " + " / " + \
vehicle . replace ( ' ' , ' - ' ) + ' -qwik_service ' + ' .json '
exising_internal_path = folder_url + " / " + " Internal " + " / " + \
vehicle . replace ( ' ' , ' - ' ) + ' -qwik_service ' + ' .json '
''' Append Published Data to Json '''
logger . info (
f ' Qwik_service Data Append Start:: { vehicle } - { language } - { publish_type } ' )
vehicle_data = {
' vehicle ' : vehicle ,
' vehicle_myid ' : vehicle_id ,
' variant ' : variant ,
' publish_type ' : publish_type ,
' publish_description ' : release_description ,
' publish_language ' : language ,
' data ' : ' '
}
if os . path . isfile ( global_file_path ) and publish_type == ' Internal ' :
with open ( global_file_path ) as f :
published_data = json . load ( f )
for i in parent :
qwik_service = qwik_service_data (
language , publish_type , i . variant , i . parent1 , vehicle )
if qwik_service [ ' status ' ] == 1 and len ( qwik_service [ ' data ' ] ) > 0 :
publish_qwik_service = 1
qwik_service_tmp . append (
qwik_service [ ' data ' ] [ 0 ] )
qwik_service_tmp = create_df ( qwik_service_tmp )
vehi_data = compare_get_data ( { ' data ' : published_data [ ' data ' ] } , {
' data ' : qwik_service_tmp } )
if vehi_data :
find_distinct = set ( exisitng_var )
new_variant_name = [
x for x in new_variant if x not in find_distinct ]
vehi_data = add_new_val (
vehi_data , new_variant_name , qwik_service_tmp )
elif os . path . isfile ( global_file_path ) and publish_type == ' Global ' :
frappe . msgprint ( str ( ' compare_internal ' ) )
with open ( global_file_path ) as f :
published_data = json . load ( f )
for i in parent :
qwik_service = qwik_service_data (
language , publish_type , i . variant , i . parent1 , vehicle )
if qwik_service [ ' status ' ] == 1 and len ( qwik_service [ ' data ' ] ) > 0 :
publish_qwik_service = 1
qwik_service_tmp . append (
qwik_service [ ' data ' ] [ 0 ] )
frappe . log_error ( str ( qwik_service_tmp ) )
qwik_service_tmp = create_df ( qwik_service_tmp )
vehi_data = compare_get_data ( { ' data ' : published_data [ ' data ' ] } , {
' data ' : qwik_service_tmp } )
if vehi_data :
find_distinct = set ( exisitng_var )
new_variant_name = [
x for x in new_variant if x not in find_distinct ]
vehi_data = add_new_val (
vehi_data , new_variant_name , qwik_service_tmp )
else :
for i in parent :
qwik_service = qwik_service_data (
language , publish_type , i . variant , i . parent1 , vehicle )
if qwik_service [ ' status ' ] == 1 and len ( qwik_service [ ' data ' ] ) > 0 :
publish_qwik_service = 1
qwik_service_tmp . append (
qwik_service [ ' data ' ] [ 0 ] )
else :
frappe . throw ( ' failed to publish ' )
qwik_service_tmp = get_latest_data (
{ ' data ' : qwik_service_tmp } , { ' data ' : [ ] } )
vehi_data = create_df ( qwik_service_tmp )
""" Save publish file """
vehicle_data [ ' data ' ] = vehi_data
with open ( file_path , ' w ' ) as outfile :
outfile . write ( json . dumps ( vehicle_data , indent = 4 , default = str ) )
except Exception as e :
logger . error ( f ' { variant } - { language } - { publish_type } - Qwik_service ' + str ( e ) )
def special_tool_publish ( vehicle , vehicle_id ,
publish_type , release_description ,
parent = None ) :
# special_tool_publish(self.vehicle, self.vehicle_id,
# self.publish_type,
# self.release_description,
# self.special_tool_publish_docs)
try :
frappe . log_error ( str ( parent ) )
logger_file = f ' { vehicle } - { publish_type } - special tool '
logger = frappe . logger ( logger_file , allow_site = True , file_count = 100 )
logger . info (
f ' Special Tool Started- { vehicle } - { publish_type } - { parent } ' )
folder_url = base_url + " / " + vehicle . replace ( ' ' , ' - ' )
logger . info ( f ' Created Folder- { vehicle } - { publish_type } ' )
''' Publish Ready Flags '''
publish_special_tool = 0
special_tool_tmp = [ ]
''' Create Folder For Publish '''
create_publish_folders ( folder_url )
file_path = folder_url + " / " + publish_type + " / " + \
vehicle . replace ( ' ' , ' - ' ) + ' -special_tool ' + ' .json '
existing_global = folder_url + " / " + " Global " + " / " + \
vehicle . replace ( ' ' , ' - ' ) + ' -special_tool ' + ' .json '
# frappe.msgprint(str(existing_global))
''' Append Published Data to Json '''
logger . info (
f ' Special tool Data Append Start:: { vehicle } - { publish_type } ' )
vehicle_data = {
' vehicle ' : vehicle ,
' vehicle_myid ' : vehicle_id ,
' publish_type ' : publish_type ,
' publish_description ' : release_description ,
' data ' : ' '
}
''' update existing global json file '''
if os . path . isfile ( existing_global ) and publish_type == ' Internal ' :
# frappe.msgprint(str('exiting'))
with open ( existing_global ) as f :
published_data = json . load ( f )
for i in parent :
special_tool = special_tool_data ( vehicle , publish_type , i . parent1 )
if special_tool [ ' status ' ] == 1 and len ( special_tool [ ' data ' ] ) > 0 :
publish_special_tool = 1
special_tool_tmp . append (
special_tool [ ' data ' ] [ 0 ] )
frappe . log_error ( str ( special_tool_tmp ) )
special_tool_tmp = get_latest_data ( { ' data ' : published_data [ ' data ' ] } , {
' data ' : special_tool_tmp } )
elif os . path . isfile ( file_path ) and publish_type == ' Global ' :
# frappe.msgprint(str('exiting Global'))
with open ( existing_global ) as f :
published_data = json . load ( f )
for i in parent :
special_tool = special_tool_data ( vehicle , publish_type , i . parent1 )
if special_tool [ ' status ' ] == 1 and len ( special_tool [ ' data ' ] ) > 0 :
publish_special_tool = 1
special_tool_tmp . append (
special_tool [ ' data ' ] [ 0 ] )
frappe . log_error ( str ( special_tool_tmp ) )
special_tool_tmp = get_latest_data ( { ' data ' : published_data [ ' data ' ] } , {
' data ' : special_tool_tmp } )
else :
for i in parent :
special_tool = special_tool_data (
vehicle , publish_type , i . parent1 )
frappe . log_error ( str ( special_tool ) )
if special_tool [ ' status ' ] == 1 :
publish_special_tool = 1
if len ( special_tool [ ' data ' ] ) > 0 :
special_tool_tmp . append (
special_tool [ ' data ' ] [ 0 ] )
# frappe.msgprint(str(special_tool['data'][0]))
special_tool_tmp = get_latest_data (
{ ' data ' : special_tool_tmp } , { ' data ' : [ ] } )
if publish_special_tool == 1 :
""" Save publish file """
vehicle_data [ ' data ' ] = special_tool_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 } - { publish_type } error in json creation ' + str ( e ) )
frappe . throw ( ' Failed To Publish ' )
def get_key_value_data ( data ) :
module_dic = { }
@ -769,6 +1047,8 @@ def get_key_value_data(data):
def get_latest_data ( prev_data , latest_data ) :
try :
logger_file = " remove inactive start "
logger = frappe . logger ( logger_file , allow_site = True , file_count = 100 )
data_dic1 = get_key_value_data ( prev_data )
data_dic2 = get_key_value_data ( latest_data )
@ -784,9 +1064,10 @@ def get_latest_data(prev_data, latest_data):
final_dic . update ( { d2 : data_dic2 [ d2 ] } )
final_list = list ( final_dic . values ( ) )
logger . info ( " remove inactive end " )
return final_list
except Exception as e :
logger . error ( " remove inactive error " + str ( e ) )
frappe . throw ( str ( e ) )
@ -994,13 +1275,86 @@ def feature_finder_data(vehicle=None, language=None,
e )
logger . error ( ' error in repair checksheet ' + str ( e ) )
return failure_reponse
def qwik_service_data ( language , publish_type , variant , parent , vehicle ) :
try :
logger_file = f ' fetch qwik data { variant } - { language } '
logger = frappe . logger ( logger_file ,
allow_site = True , file_count = 100 )
logger . info (
f " start of qwik service data { variant } - { language } " )
qwik_service_details = frappe . db . sql ( ''' select name,variant,vehicle,kilometers,language,service_time,active_status,
pdf , display_order , keywords , my_id from ` tabQwik Service ` where name = ' %s ' ; ''' %
( parent ) , as_dict = 1 )
for q in qwik_service_details :
q [ ' pre_work ' ] = frappe . db . sql ( ''' select idx as ' display_order ' , content from `tabQwik Service Content` where parent= ' %s '
& & content_type = ' Pre-work ' order by display_order ; ''' % (q[ ' name ' ]), as_dict=1)
q [ ' consumables ' ] = frappe . db . sql ( ''' select idx as ' display_order ' , content from `tabQwik Service Content` where
parent = ' %s ' & & content_type = ' Consumables ' order by display_order ; ''' % (q[ ' name ' ]), as_dict=1)
q [ ' tools ' ] = frappe . db . sql ( ''' select idx as ' display_order ' , content from `tabQwik Service Content` where
parent = ' %s ' & & content_type = ' Tools ' order by display_order ; ''' % (q[ ' name ' ]), as_dict=1)
for p in qwik_service_details :
# p['qwik_procedure'] = frappe.db.sql('''select idx as 'display_order',side,level,content from `tabQwik Procedure`
# where parent ='%s';''' % (p['name']), as_dict=1)
LHS = frappe . db . sql ( ''' select idx as ' display_order ' ,side,level,content from `tabQwik Procedure`
where parent = ' %s ' and side = ' LHS ' ; ''' % (p[ ' name ' ]), as_dict=1)
RHS = frappe . db . sql ( ''' select idx as ' display_order ' ,side,level,content from `tabQwik Procedure`
where parent = ' %s ' and side = ' RHS ' ; ''' % (p[ ' name ' ]), as_dict=1)
p [ ' qwik_procedure ' ] = { ' LHS ' : LHS , ' RHS ' : RHS }
logger . info (
f " end of qwik service data { variant } - { language } " )
success_reponse [ ' data ' ] = qwik_service_details
success_reponse [
' message ' ] = f ' Qwik Service Fecthed Succesfully for { vehicle } - { language } '
return success_reponse
except Exception as e :
logger . error ( ' error in qwik service data ' + str ( e ) )
def special_tool_data ( vehicle = None ,
publish_type = None , parent = None ) :
try :
logger_file = f ' special_tool_data start '
logger = frappe . logger ( logger_file ,
allow_site = True , file_count = 100 )
logger . info (
f " start of fetching special tool data - { parent } " )
special_tool_information = frappe . db . sql ( ''' select name,vehicle,tool_type,
category , tool_name , aggregate_name , aggregate_image ,
pdf , keywords , display_order , my_id , active_status from
` tabSpecial Tool Information `
where name = ' %s ' ; ''' % (parent), as_dict=1)
for s in special_tool_information :
s [ ' instructions ' ] = frappe . db . sql ( ''' select idx as ' display_order ' ,step_name,
content_type , content , attach_file
from ` tabInstructions ` where parent = ' %s '
order by display_order ; ''' % (s[ ' name ' ]), as_dict=1)
logger . info (
f " end of fetching special tool data { vehicle } " )
success_reponse [ ' data ' ] = special_tool_information
success_reponse [
' message ' ] = f ' Special Tool Fecthed Succesfully for { vehicle } - special_tool_data '
return success_reponse
except Exception as e :
failure_reponse [ ' error ' ] = f " { vehicle } has following error - " + str (
e )
logger . error ( ' error in special tool ' + str ( e ) )
return failure_reponse
@frappe . whitelist ( )
def max_publish_new_module ( doc ) :
doc = frappe . get_doc ( " Publish " , doc )
ver = frappe . db . sql ( """ select max(version) from {0} .tabPublish where vehicle = " {1} " and language = " {2} " and publish_module!= " Automotive System " ; """ . format (
current_db_name , doc . vehicle , doc . language ) )
if ver :
return ver
@ -1030,3 +1384,19 @@ def cal_ver_new_module(vehicle, lang, publish_type, doc):
current_db_name , v , doc . name ) )
frappe . db . commit ( )
return v
@frappe . whitelist ( )
def get_qwik_service ( variant = None , language_label = None , kilometers = 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
@frappe . whitelist ( )
def get_special_tool ( vehicle = None , publish_type = None ) :
data = frappe . db . sql ( '''
select * from ` tabSpecial Tool Information ` where vehicle = ' %s ' and published = ' %s ' ; ''' % (vehicle,0), as_dict=1)
return data