@ -19,7 +19,7 @@ site_name = cstr(frappe.local.site)
base_url = os . path . expanduser (
" ~ " ) + " /frappe-bench/sites/ " + site_name + " /public " + " /files " + " /json_files " + " /phase2 "
frappe . utils . logger . set_log_level ( " DEBUG " )
frappe . utils . logger . set_log_level ( " DEBUG " )
success_reponse = { " status " : 1 , " data " : " " , " message " : " " }
failure_reponse = { " status " : 0 , " data " : " " , " error " : " " }
module_name = ' feature_finder '
@ -59,25 +59,24 @@ class Publish(Document):
def on_submit ( self ) :
if self . docstatus == 1 and self . publish_status == ' To Publish ' and self . publish_module == ' Repair service ' and self . publish_type == ' Internal ' :
repair_res_obj = repair_checksheet_publish ( self . vehicle , self . vehicle_id ,
self . language , self . publish_type ,
self . release_description , self . variant ,
self . repiar_checksheet_publish_docs )
repair_res_obj = repair_checksheet_publish ( self . vehicle , self . vehicle_id ,
self . language , self . publish_type ,
self . release_description , self . variant ,
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 )
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 `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 )
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 ) )
@ -107,25 +106,27 @@ class Publish(Document):
update_repair_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 == ' 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 )
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 )
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 ' )
variant = self . variant_mapping_details . split ( ' /n ' )
frappe . log_error ( ' publish type ' , str ( self . publish_type ) )
update_publish_mapping ( self . vehicle , self . variant_mapping ,
self . language , self . publish_module , self . publish_type )
def on_cancel ( self ) :
# Published document should not allow to cancel
@ -184,16 +185,19 @@ 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 ) )
""" 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 ' )
if module == ' Repair service ' :
@ -208,7 +212,19 @@ def update_publish_mapping(vehicle, variant, language, module, publish_type):
frappe . db . sql (
f """ UPDATE `tabModule Publish Mapping` set repairservice_check_sheet= ' 1 ' and publish_type= ' 1 ' where name = ' { d [ ' name ' ] } ' """ , as_dict = 1 )
frappe . db . commit ( )
elif module == ' Special Tool ' :
pub_data = frappe . db . get_list ( ' Module Publish Mapping ' , filters = {
" vehicle " : vehicle ,
" language " : language ,
" publish_type " : publish_type
} , fields = [ ' name ' ] )
if len ( pub_data ) > 0 :
for d in pub_data :
if d [ ' name ' ] :
frappe . db . sql (
f """ UPDATE `tabModule Publish Mapping` set mahindra_special_tool_information= ' 1 ' and publish_type= ' 1 ' where name = ' { d [ ' name ' ] } ' """ , as_dict = 1 )
frappe . db . commit ( )
else :
pub_data = frappe . db . get_list ( ' Module Publish Mapping ' , filters = {
" vehicle " : vehicle ,
@ -224,7 +240,8 @@ def update_publish_mapping(vehicle, variant, language, module, publish_type):
' doctype ' : ' Module Publish Mapping ' ,
" vehicle " : vehicle ,
" variant " : variant ,
" language " : language
" language " : language ,
" publish_type " : publish_type
} )
if module == ' Automotive System ' :
doc . automotive_system = 1
@ -234,7 +251,9 @@ def update_publish_mapping(vehicle, variant, language, module, publish_type):
elif module == ' Feature Finder ' :
doc . feature_finder = 1
elif module == ' Qwik Service ' :
doc . qwik_service = 1
doc . save ( )
@ -370,7 +389,7 @@ def generate_global_publish(name, module_name):
" publish_status " : ' To Publish ' ,
" release_description " : res . release_description ,
" publish_module " : res . publish_module
} )
elif module_name == ' Special Tool ' :
ret = frappe . get_doc ( {
@ -381,7 +400,7 @@ def generate_global_publish(name, module_name):
" 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 ( ) }
@ -555,9 +574,7 @@ def update_procedure_value(name, file_path):
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 ) )
frappe . db . commit ( )
@ -568,9 +585,7 @@ def update_feature_published_docs(self):
def update_repair_published_docs ( self ) :
try :
for d in self . repair_checksheet_publish :
frappe . db . sql (
""" UPDATE `tabRepair Service Mapping` set published=1 where name= ' {0} ' """ . format ( d . parent_name ) )
frappe . db . commit ( )
@ -578,11 +593,10 @@ def update_repair_published_docs(self):
except Exception as e :
frappe . throw ( str ( e ) )
def update_special_tool_publish_docs ( self ) :
try :
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 ( )
@ -592,7 +606,6 @@ def update_special_tool_publish_docs(self):
def create_publish_folders ( folder_url ) :
try :
if not os . path . isdir ( folder_url + " / " + " Global " ) :
os . makedirs ( folder_url + " / " + " Global " )
@ -604,6 +617,7 @@ def create_publish_folders(folder_url):
frappe . throw ( str ( e ) )
return False
''' New Module Publish Section '''
@ -717,8 +731,6 @@ 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 ,
@ -830,9 +842,10 @@ 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 ) :
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 )
@ -845,7 +858,7 @@ def qwik_service_publish(vehicle = None , vehicle_id = None,variant = None,
''' Publish Ready Flags '''
publish_qwik_service = 0
qwik_service_tmp = [ ]
qwik_service = ' '
qwik_service = ' '
''' Create Folder For Publish '''
create_publish_folders ( folder_url )
@ -861,21 +874,21 @@ def qwik_service_publish(vehicle = None , vehicle_id = None,variant = None,
vehicle_data = {
' vehicle ' : vehicle ,
' vehicle_myid ' : vehicle_id ,
' variant ' : variant ,
' 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 :
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 ] )
@ -894,15 +907,14 @@ def qwik_service_publish(vehicle = None , vehicle_id = None,variant = None,
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 :
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 :
@ -914,18 +926,18 @@ def qwik_service_publish(vehicle = None , vehicle_id = None,variant = None,
else :
for i in parent :
qwik_service = qwik_service_data (
language , publish_type , i . variant , i . parent1 , vehicle )
language , publish_type , i . variant , i . parent1 , vehicle )
if qwik_service [ ' status ' ] == 1 and len ( qwik_service [ ' data ' ] ) > 0 :
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 [ ' 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 """
@ -933,13 +945,14 @@ def qwik_service_publish(vehicle = None , vehicle_id = None,variant = None,
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 ) )
logger . error (
f ' { variant } - { language } - { publish_type } - Qwik_service ' + str ( e ) )
def special_tool_publish ( vehicle , vehicle_id ,
publish_type , release_description ,
parent = None ) :
publish_type , release_description ,
parent = None ) :
try :
logger_file = f ' { vehicle } - { publish_type } - special tool '
logger = frappe . logger ( logger_file , allow_site = True , file_count = 100 )
@ -957,7 +970,7 @@ def special_tool_publish(vehicle, vehicle_id,
create_publish_folders ( folder_url )
file_path = folder_url + " / " + publish_type + " / " + \
vehicle . replace ( ' ' , ' - ' ) + ' -special_tool ' + ' .json '
existing_global = folder_url + " / " + " Global " + " / " + \
existing_global = folder_url + " / " + " Global " + " / " + \
vehicle . replace ( ' ' , ' - ' ) + ' -special_tool ' + ' .json '
''' Append Published Data to Json '''
@ -972,45 +985,47 @@ def special_tool_publish(vehicle, vehicle_id,
}
''' update existing global json file '''
if os . path . isfile ( existing_global ) and publish_type == ' Internal ' :
if os . path . isfile ( existing_global ) and publish_type == ' Internal ' :
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 :
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 ] )
special_tool_tmp = get_latest_data ( { ' data ' : published_data [ ' data ' ] } , {
' data ' : special_tool_tmp } )
elif os . path . isfile ( file_path ) and publish_type == ' Global ' :
' data ' : special_tool_tmp } )
elif os . path . isfile ( file_path ) and publish_type == ' 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 :
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 ] )
special_tool_tmp = get_latest_data ( { ' data ' : published_data [ ' data ' ] } , {
' data ' : special_tool_tmp } )
' data ' : special_tool_tmp } )
else :
for i in parent :
special_tool = special_tool_data (
vehicle , publish_type , i . parent1 )
if special_tool [ ' status ' ] == 1 :
publish_special_tool = 1
if len ( special_tool [ ' data ' ] ) > 0 :
if len ( special_tool [ ' data ' ] ) > 0 :
special_tool_tmp . append (
special_tool [ ' data ' ] [ 0 ] )
special_tool_tmp = get_latest_data (
{ ' data ' : special_tool_tmp } , { ' data ' : [ ] } )
if publish_special_tool == 1 :
if publish_special_tool == 1 :
""" Save publish file """
vehicle_data [ ' data ' ] = special_tool_tmp
@ -1262,18 +1277,20 @@ 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 ) :
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 )
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)
@ -1296,13 +1313,14 @@ def qwik_service_data(language,publish_type,variant,parent,vehicle):
success_reponse [ ' data ' ] = qwik_service_details
success_reponse [
' message ' ] = f ' Qwik Service Fecthed Succesfully for { vehicle } - { language } '
return success_reponse
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 ) :
publish_type = None , parent = None ) :
try :
logger_file = f ' special_tool_data start '
logger = frappe . logger ( logger_file ,
@ -1310,7 +1328,6 @@ def special_tool_data(vehicle=None,
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
@ -1335,13 +1352,14 @@ def special_tool_data(vehicle=None,
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
@ -1372,18 +1390,20 @@ def cal_ver_new_module(vehicle, lang, publish_type, doc):
frappe . db . commit ( )
return v
@frappe . whitelist ( )
def get_qwik_service ( variant = None , language_label = None , kilometers = None ) :
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)
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
select * from ` tabSpecial Tool Information ` where vehicle = ' %s ' and published = ' %s ' ; ''' % (vehicle, 0), as_dict=1)
return data