@ -61,7 +61,7 @@ class Publish(Document):
try :
""" Feature Finder """
if self . docstatus == 1 and self . publish_status == ' To Publish ' and self . publish_module == ' Feature Finder ' and self . feature_finder_publish_docs :
feature_finder_publish ( self . vehicle , self . vehicle_id ,
pub_file_res = feature_finder_publish ( self . vehicle , self . vehicle_id ,
self . language , self . publish_type ,
self . release_description , self . feature_finder_publish_docs , self . variant )
@ -69,22 +69,25 @@ class Publish(Document):
f ''' SELECT distinct(variant) as variant FROM `tabFeature Finder Publish Docs` where parent = ' { self . name } ' ; ''' , as_dict = 1 )
update_publish_mapping ( self . vehicle , variant_list ,
self . language , self . publish_module , self . publish_type )
if self . publish_type == ' Global ' :
update_feature_published_docs ( self )
""" Repair Service """
if self . docstatus == 1 and self . publish_status == ' To Publish ' and self . publish_module == ' Repair service ' and self . repiar_checksheet_publish_docs :
repair_checksheet_publish ( self . vehicle , self . vehicle_id ,
pub_file_res = repair_checksheet_publish ( self . vehicle , self . vehicle_id ,
self . language , self . publish_type ,
self . release_description , self . variant ,
self . repiar_checksheet_publish_docs )
variant_list = None
update_publish_mapping ( self . vehicle , variant_list ,
self . language , self . publish_module , self . publish_type )
if self . publish_type == ' Global ' :
update_repair_published_docs ( self )
""" qwik_service """
if self . docstatus == 1 and self . publish_status == ' To Publish ' and self . publish_module == ' Qwik Service ' and self . qwik_service_publish_docs :
qwik_service_publish ( self . vehicle , self . vehicle_id , self . variant ,
pub_file_res = qwik_service_publish ( self . vehicle , self . vehicle_id , self . variant ,
self . language , self . publish_type ,
self . release_description , self . qwik_service_publish_docs )
@ -97,17 +100,19 @@ class Publish(Document):
""" Special Tools Information """
if self . docstatus == 1 and self . publish_status == ' To Publish ' and self . publish_module == ' Special Tool ' and self . special_tool_publish_docs :
special_tool_publish ( self . vehicle , self . vehicle_id ,
pub_file_res = special_tool_publish ( self . vehicle , self . vehicle_id ,
self . publish_type ,
self . release_description ,
self . special_tool_publish_docs )
variant_list = None
update_publish_mapping ( self . vehicle , variant_list ,
self . language , self . publish_module , self . publish_type )
if self . publish_type == ' Global ' :
update_special_tool_publish_docs ( self )
""" Torque Manual """
if self . docstatus == 1 and self . publish_status == ' To Publish ' and self . publish_module == ' Torque Manual ' and self . torque_manual_publish_docs :
torque_manual_publish ( self . vehicle , self . vehicle_id ,
pub_file_res = torque_manual_publish ( self . vehicle , self . vehicle_id ,
self . language , self . publish_type ,
self . release_description , self . torque_manual_publish_docs , self . variant )
@ -120,15 +125,20 @@ class Publish(Document):
""" Training Information """
if self . docstatus == 1 and self . publish_status == ' To Publish ' and self . publish_module == ' Training Information ' and self . training_information_publish_docs :
training_information_publish ( self . vehicle , self . vehicle_id ,
pub_file_res = training_information_publish ( self . vehicle , self . vehicle_id ,
self . language , self . publish_type ,
self . release_description , self . variant ,
self . training_information_publish_docs )
# if not self.training_information_publish_docs:
# frappe.throw("no data added")
variant_list = None
update_publish_mapping ( self . vehicle , variant_list ,
self . language , self . publish_module , self . publish_type )
if self . publish_type == ' Global ' :
update_training_published_docs ( self )
""" Update Publish status """
frappe . db . sql (
""" update `tabPublish` set publish_status= ' Published ' where name= ' {0} ' ; """ . format ( self . name ) )
@ -209,98 +219,170 @@ def update_procedure(vehicle, lang, publish_type, doc):
""" Generate Publish versions """
def update_publish_mapping ( vehicle , variant_list , language , module , publish_type ) :
try :
if module == ' Repair service ' :
variant_list = None
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 repairservice_check_sheet= ' 1 ' ,publish_type= ' { publish_type } '
where name = ' {d['name']} ' ; """ , as_dict=1)
frappe . db . commit ( )
elif module == ' Training Information ' :
variant_list = None
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 training_information= ' 1 ' ,publish_type= ' { publish_type } '
where name = ' {d['name']} ' ; """ , as_dict=1)
frappe . db . commit ( )
elif module == ' Special Tool ' :
variant_list = None
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 ' ,publish_type= ' { publish_type } '
where name = ' {d['name']} ' ; """ , as_dict=1)
frappe . db . commit ( )
else :
frappe . log_error ( ' variant_list ' + str ( variant_list ) )
get_variant = frappe . db . sql ( ''' select name from `tabVariant Mapping` where vehicle = " {} " ''' . format ( vehicle ) , as_dict = 1 )
if module == ' Repair service ' or module == ' Training Information ' or module == ' Special Tool ' :
for vari in get_variant :
pub_data = frappe . db . get_list ( ' Module Publish Mapping ' , filters = {
" vehicle " : vehicle ,
" language " : language ,
" variant " : vari [ ' name ' ] ,
" publish_type " : publish_type
} , fields = [ ' name ' ] )
if len ( pub_data ) > 0 :
# for d in pub_data:
if pub_data [ 0 ] [ ' name ' ] :
doc = frappe . get_doc ( ' Module Publish Mapping ' , pub_data [ 0 ] [ ' name ' ] )
# frappe.db.sql(
# f"""UPDATE `tabModule Publish Mapping` set training_information='1',publish_type='{publish_type}'
# where name ='{pub_data[0]['name']}'; """, as_dict=1)
# frappe.db.commit()
else :
doc = frappe . get_doc ( {
' doctype ' : ' Module Publish Mapping ' ,
" vehicle " : vehicle ,
" variant " : vari [ ' name ' ] ,
" language " : language ,
" publish_type " : publish_type
} )
if module == ' Repair service ' :
doc . repairservice_check_sheet = 1
doc . tsb = 1
doc . fsa = 1
doc . tekalert = 1
# frappe.db.sql(
# f"""UPDATE `tabModule Publish Mapping` set training_information='1',publish_type='{publish_type}'
# where name ='{pub_data[0]['name']}'; """, as_dict=1)
# frappe.db.commit()
elif module == ' Training Information ' :
doc . training_information = 1
doc . tsb = 1
doc . fsa = 1
doc . tekalert = 1
elif module == ' Special Tool ' :
doc . mahindra_special_tool_information = 1
doc . tsb = 1
doc . fsa = 1
doc . tekalert = 1
doc . save ( )
elif module == ' Automotive System ' or module == ' Feature Finder ' or module == ' Qwik Service ' or module == ' Torque Manual ' :
frappe . log_error ( str ( variant_list ) )
for v in variant_list :
variant = v [ ' variant ' ]
pub_data = frappe . db . get_list ( ' Module Publish Mapping ' , filters = {
" vehicle " : vehicle ,
" variant " : variant ,
" language " : language ,
" publish_type " : publish_type
} , 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 ' ,
pub_data = frappe . db . get_list ( ' Module Publish Mapping ' , filters = {
" vehicle " : vehicle ,
" variant " : variant ,
" language " : language ,
" publish_type " : publish_type
} )
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
} , fields = [ ' name ' ] )
elif module == ' Qwik Service ' :
doc . qwik_service = 1
elif module == ' Torque Manual ' :
doc . torque_information_nm = 1
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 ,
" publish_type " : publish_type
} )
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
doc . tsb = 1
doc . fsa = 1
doc . tekalert = 1
elif module == ' Qwik Service ' :
doc . qwik_service = 1
doc . tsb = 1
doc . fsa = 1
doc . tekalert = 1
elif module == ' Torque Manual ' :
doc . torque_information_nm = 1
doc . tsb = 1
doc . fsa = 1
doc . tekalert = 1
doc . save ( )
# if module == 'Repair service':
# variant_list = None
# 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 repairservice_check_sheet='1',publish_type='{publish_type}'
# where name ='{d['name']}';""", as_dict=1)
# frappe.db.commit()
# elif module == 'Training Information':
# for vari in get_variant:
# pub_data = frappe.db.get_list('Module Publish Mapping', filters={
# "vehicle": vehicle,
# "language": language,
# "variant":vari['name'],
# "publish_type": publish_type
# }, fields=['name'])
# if len(pub_data) > 0:
# # for d in pub_data:
# if pub_data[0]['name']:
# frappe.db.sql(
# f"""UPDATE `tabModule Publish Mapping` set training_information='1',publish_type='{publish_type}'
# where name ='{pub_data[0]['name']}'; """, as_dict=1)
# frappe.db.commit()
# else:
# doc = frappe.get_doc({
# 'doctype': 'Module Publish Mapping',
# "vehicle": vehicle,
# "variant": vari['name'],
# "language": language,
# "publish_type": publish_type
# })
# doc.save()
# elif module == 'Special Tool':
# variant_list = None
# 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',publish_type='{publish_type}'
# where name ='{d['name']}';""", as_dict=1)
# frappe.db.commit()
doc . save ( )
except Exception as e :
frappe . throw ( str ( " Failed To Publish " ) )
frappe . log_error ( " update_publish_mapping " , str ( e ) )
@frappe . whitelist ( )
def cal_ver ( vehicle , lang , publish_type , doc , publish_module ) :
update_procedure ( vehicle , lang , publish_type , doc )
@ -917,7 +999,7 @@ def feature_finder_publish(vehicle=None, vehicle_id=None,
logger . info (
f ' Feature Data Append Start:: { vehicle } - { language } - { publish_type } ' )
""" update existing global json file """
if os . path . isfile ( global_file_path ) and publish_type == ' Internal ' :
if os . path . isfile ( check_glbl_full_updte ) and publish_type == ' Internal ' :
frappe . log_error ( ' internal ' )
if os . path . isfile ( check_glbl_full_updte ) :
with open ( check_glbl_full_updte ) as f :
@ -940,17 +1022,17 @@ def feature_finder_publish(vehicle=None, vehicle_id=None,
vehi_data = add_new_val (
vehi_data , new_variant_name , feature_finder_tmp )
elif os . path . isfile ( file_path ) and publish_type == ' Global ' :
elif os . path . isfile ( check_glbl_full_updte ) and publish_type == ' Global ' :
frappe . log_error ( ' gobal ' )
full_update_folder_url_internal = folder_url + " / " + " Internal_Full_Update "
# full_update_folder_url_internal = folder_url + "/" + "Internal_Full_Update "
""" Remove Internal Full Update File On Global Publish """
# """ Remove Internal Full Update File On Global Publish """
existing_internal_full_update = full_update_folder_url_internal + " / " + \
vehicle . replace ( ' ' , ' - ' ) + \
' -feature_finder_full_update ' + ' .json '
if os . path . isfile ( existing_internal_full_update ) :
os . remove ( existing_internal_full_update )
# existing_internal_full_update = full_update_folder_url_internal+"/" + \
# vehicle.replace(' ', '-') + \
# '-feature_finder_full_update' + '.json'
# if os.path.isfile(existing_internal_full_update) :
# os.remove(existing_internal_full_update )
with open ( check_glbl_full_updte ) as f :
published_data = json . load ( f )
for i in parent :
@ -1037,7 +1119,8 @@ def feature_finder_publish(vehicle=None, vehicle_id=None,
os . remove ( existing_internal_full_update )
""" Save publish file """
vehicle_data [ ' data ' ] = vehi_data
# update_publish_mapping(vehicle, vehi_data,
# language, 'Feature',publish_type)
with open ( file_path , ' w ' ) as outfile :
outfile . write ( json . dumps ( latest_pub_data , indent = 4 , default = str ) )
@ -1130,14 +1213,14 @@ def qwik_service_publish(vehicle=None, vehicle_id=None, variant=None,
elif os . path . isfile ( file_path ) and publish_type == ' Global ' :
full_update_folder_url_intern al = folder_url + " / " + " Intern al_Full_Update"
full_update_folder_url_glob al = folder_url + " / " + " Glob al_Full_Update"
""" Remove Internal Full Update File On Global Publish """
existing_internal_full_update = full_update_folder_url_intern al + " / " + \
existing_global_full_update = full_update_folder_url_glob al + " / " + \
vehicle . replace ( ' ' , ' - ' ) + \
' -qwik_service_full_update ' + ' .json '
if os . path . isfile ( existing_internal_full_update ) :
os . remove ( existing_internal_full_update )
with open ( check_glbl_full_upd te) as f :
with open ( existing_global_full_upda te) as f :
published_data = json . load ( f )
for i in parent :
qwik_service = qwik_service_data ( vehicle , language ,
@ -1223,7 +1306,8 @@ def qwik_service_publish(vehicle=None, vehicle_id=None, variant=None,
os . remove ( existing_internal_full_update )
""" Save publish file """
vehicle_data [ ' data ' ] = vehi_data
# update_publish_mapping(vehicle, vehi_data,
# language,'Qwik Service',publish_type)
with open ( file_path , ' w ' ) as outfile :
outfile . write ( json . dumps ( latest_pub_data , indent = 4 , default = str ) )
@ -1405,7 +1489,8 @@ def torque_manual_publish(vehicle=None, vehicle_id=None,
""" Append Published Data to Json """
""" update existing global json file """
if os . path . isfile ( global_file_path ) and publish_type == ' Internal ' :
if os . path . isfile ( check_glbl_full_updte ) and publish_type == ' Internal ' :
frappe . log_error ( str ( full_update_file ) )
if os . path . isfile ( check_glbl_full_updte ) :
with open ( check_glbl_full_updte ) as f :
published_data = json . load ( f )
@ -1418,8 +1503,11 @@ def torque_manual_publish(vehicle=None, vehicle_id=None,
torque_manual [ ' data ' ] [ 0 ] )
torque_manual_tmp = create_df ( torque_manual_tmp )
latest_pub_data [ ' data ' ] = torque_manual_tmp
vehi_data = compare_get_data ( { ' data ' : published_data [ ' data ' ] } , {
' data ' : torque_manual_tmp } )
if vehi_data :
find_distinct = set ( exisitng_var )
new_variant_name = [
@ -1427,7 +1515,9 @@ def torque_manual_publish(vehicle=None, vehicle_id=None,
vehi_data = add_new_val (
vehi_data , new_variant_name , torque_manual_tmp )
elif os . path . isfile ( file_path ) and publish_type == ' Global ' :
elif os . path . isfile ( check_glbl_full_updte ) and publish_type == ' Global ' :
frappe . log_error ( str ( ' Global ' ) )
full_update_folder_url_internal = folder_url + " / " + " Internal_Full_Update "
""" Remove Internal Full Update File On Global Publish """
@ -1447,6 +1537,7 @@ def torque_manual_publish(vehicle=None, vehicle_id=None,
torque_manual_tmp . append (
torque_manual [ ' data ' ] [ 0 ] )
torque_manual_tmp = create_df ( torque_manual_tmp )
frappe . log_error ( ' torque_manual_tmp ' + str ( torque_manual_tmp ) )
latest_pub_data [ ' data ' ] = torque_manual_tmp
vehi_data = compare_get_data ( { ' data ' : published_data [ ' data ' ] } , {
' data ' : torque_manual_tmp } )
@ -1494,6 +1585,7 @@ def torque_manual_publish(vehicle=None, vehicle_id=None,
else :
""" First Time Global Or Internal """
for i in parent :
torque_manual = torque_manual_data (
@ -1507,9 +1599,10 @@ def torque_manual_publish(vehicle=None, vehicle_id=None,
else :
frappe . throw ( ' failed to publish ' )
# torque_manual_tmp = get_latest_data(
# {'data': torque_manual_tmp}, {'data': []})
frappe . log_error ( ' before ' + str ( torque_manual_tmp ) )
torque_manual_tmp = get_latest_data (
{ ' data ' : torque_manual_tmp } , { ' data ' : [ ] } )
# frappe.log_error('after'+str(torque_manual_tmp))
vehi_data = create_df ( torque_manual_tmp )
latest_pub_data [ ' data ' ] = vehi_data
@ -1524,6 +1617,8 @@ def torque_manual_publish(vehicle=None, vehicle_id=None,
os . remove ( existing_internal_full_update )
""" Save publish file """
vehicle_data [ ' data ' ] = vehi_data
# update_publish_mapping(vehicle, vehi_data,
# language,'Torque Manual',publish_type)
with open ( file_path , ' w ' ) as outfile :
outfile . write ( json . dumps ( latest_pub_data , indent = 4 , default = str ) )
@ -1633,16 +1728,14 @@ def training_information_publish(vehicle, vehicle_id,
' data ' : training_information_tmp1 } )
else :
for i in parent :
training_information = training_information_data (
vehicle , language , publish_type , i . parent1 )
if training_information [ ' status ' ] == 1 :
publish_training_information = 1
if len ( training_information [ ' data ' ] ) :
training_information_tmp . append (
training_information [ ' data ' ] )
training_information [ ' data ' ] [ 0 ] )
training_information_tmp = get_latest_data (
{ ' data ' : training_information_tmp } , { ' data ' : [ ] } )
@ -1698,6 +1791,7 @@ def get_latest_data(prev_data, latest_data):
final_dic . update ( { d2 : data_dic2 [ d2 ] } )
final_list = list ( final_dic . values ( ) )
frappe . log_error ( " final_list " + str ( final_list ) )
logger . info ( " remove inactive end " )
return final_list
except Exception as e :
@ -1995,11 +2089,11 @@ def torque_manual_data(vehicle=None, language=None,
logger . info (
f " start of fetching torque manual data - { vehicle } - { language } - { variant } - { module_name } " )
torque_manual_details = frappe . db . sql ( ''' select name,variant,vehicle,language,active_status,category,sub_category,display_order,keywords,
my_id from ` tabTorque Manual ` where variant = ' %s ' & & language = ' %s ' ; ''' % (variant, language ),
my_id from ` tabTorque Manual ` where name = ' %s ' & & is_published = 0 ; ''' % (parent ),
as_dict = 1 )
for t in torque_manual_details :
t [ ' torque_table ' ] = frappe . db . sql ( ''' select name,col1,col2,col3,col4,col5,col6,col7,col8,col9,col10,idx as display_order from
` tabTorque Manual Details ` where parent = ' %s ' order by idx ; ''' % (t[ ' name ' ]), as_dict=1)
` tabTorque Manual Details ` where parent = ' %s ' order by idx ; ''' % (t[ ' name ' ]), as_dict=1)
logger . info (
f " end of Torque Manual data { variant } - { language } " )