@ -15,12 +15,12 @@ sys.tracebacklimit = 0
site_name = cstr ( frappe . local . site )
base_url = os . path . expanduser (
" ~ " ) + " /frappe-bench/sites/ " + site_name + " /public " + " /files " + " /json_files " + " /Other_Module "
" ~ " ) + " /frappe-bench/sites/ " + site_name + " /public " + " /files " + " /json_files " + " /phase2 "
frappe . utils . logger . set_log_level ( " DEBUG " )
success_reponse = { " status " : 1 , " data " : " " , " message " : " " }
failure_reponse = { " status " : 0 , " data " : " " , " error " : " " }
module_name = ' feature_finder '
module_name = ' feature_finder '
class Publish ( Document ) :
@ -50,34 +50,46 @@ 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_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` set publish_status='Published' where name='{0}'""".format(self.name) )
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` 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 :
feature_finder_publish ( self . vehicle , self . vehicle_id ,
self . language , self . publish_type ,
self . release_description , self . feature_finder_publish , self . variant )
if self . docstatus == 1 and self . publish_module == ' Feature Finder ' and self . publish_type == ' Global ' :
feature_finder_publish ( self . vehicle , self . vehicle_id ,
self . language , self . publish_type ,
self . release_description , self . feature_finder_publish ,
self . variant )
feature_finder_publish ( self . vehicle , self . vehicle_id ,
self . language , self . publish_type ,
self . release_description , self . feature_finder_publish , self . variant )
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_module == ' Feature Finder ' and self . publish_type == ' Global ' :
feature_finder_publish ( self . vehicle , self . vehicle_id ,
self . language , self . publish_type ,
self . release_description , self . feature_finder_publish ,
self . variant )
update_feature_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 == ' Repair service ' and self . publish_type == ' Global ' :
repair_checksheet_publish ( self . vehicle , self . vehicle_id ,
self . language , self . publish_type ,
self . release_description , self . variant ,
self . repair_checksheet_publish )
if self . docstatus == 1 and self . publish_status == ' To Publish ' and self . publish_module == ' Repair service ' and self . publish_type == ' Global ' and 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_repair_published_docs ( self )
update_publish_status = frappe . db . sql (
""" update `tabPublish` set publish_status= ' Published ' where name= ' {0} ' """ . format ( self . name ) )
frappe . log_error ( str ( self . variant_mapping_details ) )
variant = self . variant_mapping_details . split ( ' /n ' )
frappe . log_error ( ' variant ' , str ( variant ) )
# for v in variant:
# frappe.log_error('v', str(v))
# if v:
# update_publish_mapping(
# self.vehicle, v, self.language, self.publish_module)
def onload1 ( self ) :
current_db_name = frappe . conf . get ( " db_name " )
# To validate updated procedure status
@ -187,6 +199,37 @@ def update_procedure(vehicle, lang, publish_type, doc):
# Generate Publish versions
def update_publish_mapping ( vehicle , variant , language , module ) :
frappe . set_user ( ' Administrator ' )
pub_data = frappe . db . get_list ( ' Module Publish Mapping ' , filters = {
" vehicle " : vehicle ,
" variant " : variant ,
" language " : language
} , fields = [ ' name ' ] )
if pub_data :
doc = frappe . get_doc ( ' Module Publish Mapping ' , pub_data [ 0 ] [ ' name ' ] )
else :
doc = frappe . get_doc ( {
' doctype ' : ' Module Publish Mapping ' ,
" vehicle " : vehicle ,
" variant " : variant ,
" language " : language
} )
if module == ' Automotive System ' :
doc . automotive_system = 1
doc . tsb = 1
doc . fsa = 1
doc . tekalert = 1
elif module == ' Feature Finder ' :
doc . feature_finder = 1
elif module == ' Repair service ' :
doc . repairservice_check_sheet = 1
doc . save ( )
def update_publish_status ( self ) :
try :
update_status = frappe . db . sql (
@ -244,7 +287,7 @@ def global_publish(doc):
publish_record . vehicle = doc . vehicle
publish_record . vehicle_id = doc . vehicle_id
publish_record . variant_mapping = doc . variant_mapping
publish_record . publish_module = doc . publish_module
publish_record . publish_module = ' Automotive System '
publish_record . variant_mapping_status = doc . variant_mapping_status
publish_record . kilometer_mapping = doc . kilometer_mapping
publish_record . km_active_status = doc . km_active_status
@ -278,17 +321,19 @@ def global_publish(doc):
def generate_global_publish ( name ) :
try :
res = frappe . get_doc ( " Publish " , name )
ret = frappe . get_doc ( {
" doctype " : " Publish " ,
" vehicle " : res . vehicle ,
" publish_type " : " Global " ,
" language " : res . language ,
" publish_status " : ' To Publish ' ,
" release_description " : res . release_description ,
" publish_module " : res . publish_module ,
" feature_finder_publish " : res . feature_finder_publish ,
" repair_checksheet_publish " : res . repair_checksheet_publish
" feature_finder_publish " : res . feature_finder_publish ,
" repair_checksheet_publish " : res . repair_checksheet_publish
} )
ret . in sert ( )
ret . sav e ( )
return { " status " : " success " , " message " : ret . name , " url " : frappe . utils . get_url ( ) }
except Exception as e :
frappe . throw ( str ( e ) )
@ -457,6 +502,7 @@ def update_procedure_value(name, file_path):
" Publish " , self . name , " published_by " , str ( name ) )
frappe . db . commit ( )
def update_feature_published_docs ( self ) :
try :
@ -465,9 +511,11 @@ def update_feature_published_docs(self):
frappe . db . sql (
""" UPDATE `tabFeature Finder` set is_published=1 where name= ' {0} ' """ . format ( d . parent1 ) )
frappe . db . commit ( )
except Exception as e :
frappe . throw ( str ( e ) )
def update_repair_published_docs ( self ) :
try :
@ -476,7 +524,7 @@ def update_repair_published_docs(self):
frappe . db . sql (
""" 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 ) )
@ -498,18 +546,21 @@ def create_publish_folders(folder_url):
''' New Module Publish Section '''
@frappe . whitelist ( )
def get_service_repair ( vehicle ,
language_label , publish_type ) :
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 ;
''' , as_dict=1)
return data
@frappe . whitelist ( )
def get_feature_finder ( vehicle , variant , language_label ) :
def get_feature_finder ( vehicle , variant , language_label ) :
try :
data = frappe . db . sql ( f """ select * from `tabFeature Finder` where vehicle= ' { vehicle } ' and variant_id= ' { variant } ' and language= ' { language_label } ' and is_published=0 """ , as_dict = 1 )
data = frappe . db . sql (
f """ select * from `tabFeature Finder` where vehicle= ' { vehicle } ' and variant_id= ' { variant } ' and language= ' { language_label } ' and is_published=0 """ , as_dict = 1 )
return data
except Exception as e :
return str ( e )
@ -558,9 +609,10 @@ def repair_checksheet_publish(vehicle, vehicle_id,
if repair_checksheet [ ' status ' ] == 1 :
publish_repair_checksheet = 1
repair_checksheet_tmp . append (
repair_checksheet [ ' data ' ] [ 0 ] )
repair_checksheet_tmp = get_latest_data ( { ' data ' : published_data [ ' data ' ] } , { ' data ' : repair_checksheet_tmp } )
repair_checksheet [ ' data ' ] [ 0 ] )
repair_checksheet_tmp = get_latest_data ( { ' data ' : published_data [ ' data ' ] } , {
' data ' : repair_checksheet_tmp } )
else :
for i in parent :
@ -573,7 +625,8 @@ def repair_checksheet_publish(vehicle, vehicle_id,
repair_checksheet_tmp . append (
repair_checksheet [ ' data ' ] [ 0 ] )
# frappe.msgprint(str(repair_checksheet['data'][0]))
repair_checksheet_tmp = get_latest_data ( { ' data ' : repair_checksheet_tmp } , { ' data ' : [ ] } )
repair_checksheet_tmp = get_latest_data (
{ ' data ' : repair_checksheet_tmp } , { ' data ' : [ ] } )
if publish_repair_checksheet == 1 :
""" Save publish file """
@ -589,10 +642,11 @@ def repair_checksheet_publish(vehicle, vehicle_id,
f ' { vehicle } - { language } - { publish_type } error in json creation ' + str ( e ) )
frappe . throw ( ' Failed To Publish ' )
def feature_finder_publish ( vehicle = None , vehicle_id = None ,
language = None , publish_type = None ,
release_description = None , parent = None ,
variant = None ) :
def feature_finder_publish ( vehicle = None , vehicle_id = None ,
language = None , publish_type = None ,
release_description = None , parent = None ,
variant = None ) :
try :
logger_file = f ' { vehicle } - { language } - { publish_type } - { module_name } - { variant } '
logger = frappe . logger ( logger_file ,
@ -631,50 +685,51 @@ def feature_finder_publish(vehicle=None,vehicle_id=None,
published_data = json . load ( f )
for i in parent :
feature_finder = feature_finder_data ( vehicle , language ,
publish_type , i . parent1 , i . variant )
publish_type , i . parent1 , i . variant )
if feature_finder [ ' status ' ] == 1 :
publish_repair_checksheet = 1
feature_finder_tmp . append (
feature_finder [ ' data ' ] [ 0 ] )
repair_checksheet_tmp = get_latest_data ( { ' data ' : published_data [ ' data ' ] } , { ' data ' : feature_finder_tmp } )
feature_finder [ ' data ' ] [ 0 ] )
feature_finder_tmp = get_latest_data (
{ ' data ' : published_data [ ' data ' ] } , { ' data ' : feature_finder_tmp } )
frappe . msgprint ( str ( feature_finder_tmp ) )
else :
for i in parent :
feature_finder = feature_finder_data (
vehicle , language , publish_type , i . parent1 , i . variant )
vehicle , language , publish_type , i . parent1 , i . variant )
if feature_finder [ ' status ' ] == 1 :
publish_feature_finder = 1
if len ( feature_finder [ ' data ' ] ) :
feature_finder_tmp . append (
feature_finder [ ' data ' ] [ 0 ] )
else :
frappe . throw ( ' failed to publish ' )
feature_finder_tmp = get_latest_data ( { ' data ' : feature_finder_tmp } , { ' data ' : [ ] } )
feature_finder_tmp = get_latest_data (
{ ' data ' : feature_finder_tmp } , { ' data ' : [ ] } )
# if publish_feature_finder == 1:
""" Save publish file """
vehicle_data [ ' data ' ] = feature_finder_tmp
""" Save publish file """
vehicle_data [ ' data ' ] = feature_finder_tmp
frappe . msgprint ( str ( file_path ) )
with open ( file_path , ' w ' ) as outfile :
outfile . write ( json . dumps ( vehicle_data , indent = 4 , default = str ) )
logger . info (
with open ( file_path , ' w ' ) as outfile :
outfile . write ( json . dumps ( vehicle_data , indent = 4 , default = str ) )
logger . info (
f ' Repair Checksheet Data Append Start:: { vehicle } - { language } - { publish_type } ' )
return 1 , file_path
return 1 , file_path
except Exception as e :
logger . info (
f ' { vehicle } - { language } - { publish_type } - { module_name } error in json creation ' + str ( e ) )
frappe . throw ( ' Failed To Publish ' )
def get_key_value_data ( data ) :
module_dic = { }
for d in data [ ' data ' ] :
@ -686,7 +741,7 @@ def get_latest_data(prev_data, latest_data):
try :
data_dic1 = get_key_value_data ( prev_data )
data_dic2 = get_key_value_data ( latest_data )
final_dic = data_dic1 . copy ( )
for d1 in data_dic1 :
@ -698,9 +753,9 @@ def get_latest_data(prev_data, latest_data):
final_dic . pop ( d2 )
else :
final_dic . update ( { d2 : data_dic2 [ d2 ] } )
final_list = list ( final_dic . values ( ) )
return final_list
except Exception as e :
frappe . throw ( str ( e ) )
@ -745,7 +800,7 @@ def repair_checksheet_data(vehicle=None, language=None,
def feature_finder_data ( vehicle = None , language = None ,
publish_type = None , parent = None , variant = None ) :
publish_type = None , parent = None , variant = None ) :
try :
logger_file = f ' { vehicle } - { language } - { publish_type } - { module_name } - { variant } - fetch data '
logger = frappe . logger ( logger_file ,
@ -770,7 +825,7 @@ def feature_finder_data(vehicle=None, language=None,
left join ` tabFeature Finder Master ` ffm on ff . features_names = ffm . feature_name
where ff . vehicle = " {vehicle} " and ffm . vehicle = " {vehicle} " and ff . variant = " {variant} "
and ff . language = " {language} " and ff . name = " {parent} " ; """ , as_dict=1)
for f in feature_finder_details :
f [ ' disclaimer ' ] = frappe . db . sql ( f '''
SELECT name , content , active_status , idx as display_order FROM ` tabFeature Finder Disclaimer `
@ -819,35 +874,37 @@ def feature_finder_data(vehicle=None, language=None,
logger . error ( ' error in repair checksheet ' + 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(creat ion) from {0} .tabPublish where vehicle = " {1} " and language = " {2} " ; """ . format (
ver = frappe . db . sql ( """ select max(vers ion) 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
# @frappe.whitelist()
# def cal_ver_new_module(vehicle, lang, publish_type, doc):
# current_db_name = frappe.conf.get("db_name")
# doc = frappe.get_doc("Publish", doc)
# ver = frappe.db.sql(f"""select max(creation) from `tabPublish` where vehicle = "{vehicle}" and language = "{lang}";""",as_dict=1)
# v = 0.0
# if publish_type == 'Global':
# if ver[0][0] == None:
# v = 1.0
# else:
# v = int(float(ver[0][0])) + 1.0
# elif publish_type == 'Internal':
# if ver[0][0] == None:
# v = 0.01
# else:
# v = float(ver[0][0]) + 0.01
# v = "{:.2f}".format(v)
# doc.version = v
# frappe.db.sql("""update {0}.`tabPublish` set version = "{1}" where name = "{2}";""".format(
# current_db_name, v, doc.name))
# frappe.db.commit()
# return v
@frappe . whitelist ( )
def cal_ver_new_module ( vehicle , lang , publish_type , doc ) :
current_db_name = frappe . conf . get ( " db_name " )
doc = frappe . get_doc ( " Publish " , doc )
ver = frappe . db . sql ( """ select max(version) from `tabPublish` where vehicle = " {vehi} " and language = " {lang} " and publish_module!= " Automotive System " ; """
. format ( vehi = vehicle , lang = lang ) )
v = 0.0
if publish_type == ' Global ' :
if ver [ 0 ] [ 0 ] == None :
v = 1.0
else :
v = int ( float ( ver [ 0 ] [ 0 ] ) ) + 1.0
elif publish_type == ' Internal ' :
if ver [ 0 ] [ 0 ] == None :
v = 0.01
else :
v = float ( ver [ 0 ] [ 0 ] ) + 0.01
v = " {:.2f} " . format ( v )
doc . version = v
frappe . db . sql ( """ update {0} .`tabPublish` set version = " {1} " where name = " {2} " ; """ . format (
current_db_name , v , doc . name ) )
frappe . db . commit ( )
return v