@ -14,14 +14,16 @@ def get_parent_map(input_list, parameter):
for b in input_list :
parentChildMap . setdefault ( b [ parameter ] or None , [ ] ) . append ( b )
list1 = [ ]
steps_length = 0
for p in parentChildMap :
da = { " procedure_name " : p , ' steps ' : parentChildMap [ p ] }
da = { " procedure_name " : p , ' steps ' : parentChildMap [ p ] }
list1 . append ( da )
steps_length + = len ( parentChildMap [ p ] )
for i in parentChildMap [ p ] :
del i [ ' procedure_name ' ]
del i [ ' idx ' ]
return list1
return list1 , steps_length
@frappe . whitelist ( )
@ -37,17 +39,14 @@ def check_all_vehicle_updates(vehicle_list):
''' SELECT publish_type FROM {} .`tabApp Device` where name= ' {} ' ; ''' . format ( current_db_name , iid ) ,
as_list = True )
if publish_type [ 0 ] [ 0 ] != None :
if publish_type [ 0 ] [ 0 ] is not None :
for v in vehicle_data :
v_id = v [ ' Vehicle ' ]
current_version = float ( v [ ' CurrentVersion ' ] )
data1 = frappe . db . sql ( ''' SELECT name,max(version) as version,vehicle_id,language FROM {} .tabPublish where vehicle= ' {} ' and language= ' {} ' and publish_status= ' Published '
and publish_type = ' {} ' and vehicle_status = ' Active ' order by version ASC ; ''' .format(current_db_name, v_id,
lang ,
publish_type [ 0 ] [ 0 ] ) ,
as_dict = True )
and publish_type = ' {} ' and vehicle_status = ' Active ' order by version ASC ; ''' .format(current_db_name, v_id,lang,publish_type[0][0]),as_dict=True)
if data1 [ 0 ] [ ' version ' ] != None :
if data1 [ 0 ] [ ' version ' ] is not None :
if current_version == float ( data1 [ 0 ] [ ' version ' ] ) :
data1 [ 0 ] [ ' IsUpdateAvailable ' ] = " false "
Vehicle_req_list . append ( data1 )
@ -117,10 +116,10 @@ def check_vehicle_update(vehicle_list):
publish_docs = frappe . db . get_list ( ' Publish_Docs ' , filters = { ' parent ' : d [ ' name ' ] } ,
fields = [ ' variant_mapping ' , ' system ' , ' sub_system ' ,
' procedure_link ' , ' procedure_status ' ] )
if publish_docs != None :
if publish_docs is not None :
list1 . append ( publish_docs )
for d in list1 :
for f in d :
for e in list1 :
for f in e :
list2 . append ( f )
# Sort data according to variant, system and sub system
@ -163,55 +162,72 @@ def check_vehicle_update(vehicle_list):
appendDict [ f ] = ( g [ f ] )
final = [ ]
count = 0
active_status_case = " CASE WHEN active_status = ' Active ' THEN ' True ' ELSE ' False ' END AS active_status "
for d in appendDict :
total_count = 0
# count = 0
step_count = 0
variant_out = { }
# Variant data
# Variant data
vari = frappe . db . sql ( ''' SELECT name,variant, vehicle,family_code,vehicle_segment,fuel,transmission,drive, active_status
FROM % s . ` tabVariant Mapping ` WHERE name = ' %s ' ; ''' % (
current_db_name , d ) , as_dict = True )
FROM { } . ` tabVariant Mapping ` WHERE name = ' {} ' ; ''' .format(current_db_name, d),
as_dict = True ) [ 0 ]
var_asset = frappe . db . sql (
''' SELECT category, attach_file as file, %s ,idx as variant_asset_idx FROM %s .`tabVariant Mapping_Assets` where category<> ' Technical Manual '
and parent = ' %s ' and language = ' %s ' ; ''' % (active_status_case, current_db_name, d, l_id),
as_dict = True )
var_asset = frappe . db . sql ( ''' SELECT category, attach_file as file, {} ,idx as variant_asset_idx FROM {} .`tabVariant Mapping_Assets`
where category < > ' Technical Manual ' and parent = ' {} ' and language = ' {} ' ; ''' .format(
active_status_case , current_db_name , d , l_id ) , as_dict = True )
kms_mapping_status = frappe . db . sql (
''' SELECT active_status FROM {0} .`tabKilometer Mapping` where name LIKE ' {1} ' and substring(name,-5,2)= ' {2} ' ; '''
. format ( current_db_name , vari [ ' name ' ] + " % " , l_id ) ) [ 0 ] [ 0 ]
vari = vari [ 0 ]
if vari [ ' active_status ' ] == ' Active ' :
vari [ ' active_status ' ] = True
else :
vari [ ' active_status ' ] = False
if kms_mapping_status == ' Active ' :
kms_active_status = True
else :
kms_active_status = False
vari . update ( { ' kms_mapping_active_status ' : kms_active_status } )
vari [ ' Assets ' ] = var_asset
total_count + = len ( var_asset )
# -1 Due to NONE value in parent mapping
total_count + = len ( appendDict [ d ] ) - 1
variant_out [ ' Variant ' ] = vari
# System data
system_out = [ ]
for i in appendDict [ d ] :
if i != None :
if i is not None :
sys = frappe . db . sql ( ''' SELECT min(tmss.idx) as systemdisplayorder,ts.system_name,ts.icon_file,ts.myid,ts.active_status FROM
{ 0 } . ` tabSystem Mapping_Sub System ` as tmss inner join { 0 } . ` tabSystems ` as ts on tmss . systems = ts . system_name
where tmss . parent LIKE ' {1} ' and substring ( tmss . parent , - 5 , 2 ) = ' {2} ' and tmss . systems = ' {3} ' ; '''
. format ( current_db_name , str ( vari [ ' name ' ] + " % " ) , l_id , i ) ,
as_dict = True )
sys = sys [ 0 ]
. format ( current_db_name , str ( vari [ ' name ' ] + " % " ) , l_id , i ) , as_dict = True ) [ 0 ]
if sys [ ' active_status ' ] == ' Active ' :
sys [ ' active_status ' ] = True
else :
sys [ ' active_status ' ] = False
# System Assets
sysassets = frappe . db . sql (
''' SELECT idx as systemdisplayorder, system_asset,active_status FROM {3} .`tabSystem Mapping_System Assets` where parent like ' {0} % ' and language= ' {1} '
and systems = ' {2} ' ; ''' .format(d, l_id, i, current_db_name), as_dict=True)
sysassets = frappe . db . sql ( ''' SELECT idx as systemdisplayorder, system_asset,active_status FROM {3} .`tabSystem Mapping_System Assets`
where parent like ' {0} % ' and language = ' {1} ' and systems = ' {2} ' ; ''' .format(d,l_id,i,current_db_name),as_dict=True)
for sysasset in sysassets :
if sysasset [ ' active_status ' ] == ' Active ' :
sysasset [ ' active_status ' ] = True
else :
sysasset [ ' active_status ' ] = False
sys [ ' Assets ' ] = sysassets
total_count + = len ( sysassets )
total_count + = len ( appendDict [ d ] [ i ] )
# Sub system
# Sub system
subsystem_out = [ ]
for j in appendDict [ d ] [ i ] :
subsys = frappe . db . sql ( ''' select `tabSystem Mapping_Sub System`.idx as subSystemdisplayorder, systems,sub_systems, symptom,
@ -228,41 +244,40 @@ def check_vehicle_update(vehicle_list):
else :
subsys [ ' active_status ' ] = False
kms = frappe . db . sql (
''' SELECT kilometer as kilometer_name, idx as kilometer_IDX, applicable as kilometers_applicable FROM {} .`tabKilometer Mapping_Items`
where sub_systems = ' {} ' and parent Like ' {} ' and substring ( parent , - 5 , 2 ) = ' {} ' order by kilometer_IDX ; ''' .format(
current_db_name , j , d + " % " , l_id ) , as_dict = True )
kms = frappe . db . sql ( ''' SELECT kilometer as kilometer_name, idx as kilometer_IDX, applicable as kilometers_applicable
FROM { } . ` tabKilometer Mapping_Items ` where sub_systems = ' {} ' and parent Like ' {} ' and substring ( parent , - 5 , 2 ) = ' {} '
order by kilometer_IDX ; ''' .format(current_db_name, j, d + " % " , l_id),
as_dict = True )
total_count + = len ( kms )
subsys [ ' Config Kilometer ' ] = kms
for k in appendDict [ d ] [ i ] [ j ] :
proc_details = frappe . db . sql ( ''' select procedure_name, step_name, content_type,
GROUP_CONCAT ( case when content_type = ' Link ' Then system_id else content end ) as content ,
GROUP_CONCAT ( file ) as file , GROUP_CONCAT ( DISTINCT idx order by idx ) as display_order , idx from { } . tabProcedure_Details
where parent = ' {} ' group by procedure_name , step_name , content_type , content order by idx asc ; ''' .format(
current_db_name , k ) ,
as_dict = True )
GROUP_CONCAT ( case when content_type = ' Link ' Then system_id else content end ) as content ,
GROUP_CONCAT ( file ) as file , GROUP_CONCAT ( DISTINCT idx order by idx ) as display_order , idx from { } . tabProcedure_Details
where parent = ' {} ' group by procedure_name , step_name , content_type , content order by idx asc ; '''
. format ( current_db_name , k ) , as_dict = True )
tem p_data = get_parent_map ( proc_details , ' procedure_name ' )
proc _data , step_length = get_parent_map ( proc_details , ' procedure_name ' )
procedure_status = frappe . db . sql (
''' SELECT workflow_state FROM {1} .tabProcedure where name= ' {0} ' ; ''' . format (
k , current_db_name ) )
procedure_status = procedure_status [ 0 ] [ 0 ]
total_count + = len ( proc_data )
subsys [ ' procedure_link ' ] = k
subsys [ ' procedure_status ' ] = procedure_status
subsys [ ' Procedure_details ' ] = tem p_data
stepcount = frappe . db . sql (
''' SELECT count(*) as Stepcount FROM {1} .tabProcedure_Details where parent= '{0} ' ; '''. format (
k , current_db_name ) , as_dict = True )
stepcount = stepcount [ 0 ]
count = count + int ( stepcount [ ' Stepcount ' ] )
subsys [ ' procedure_status ' ] = procedure_status [ 0 ] [ 0 ]
subsys [ ' Procedure_details ' ] = proc _data
# stepcount = frappe.db.sql (
# '''SELECT count(*) as Stepcount FROM {1}.tabProcedure_Details where parent='{0}';'''.format(
# k, current_db_name), as_dict=True)[0]
# count = count + int(stepcount['Stepcount'])
step_count + = step_length
subsystem_out . append ( subsys )
sys [ ' Subsystems ' ] = subsystem_out
system_out . append ( sys )
variant_out [ ' StepCount ' ] = count
variant_out [ ' StepCount ' ] = step_ count
variant_out [ ' Variant ' ] [ ' Systems ' ] = system_out
variant_out [ ' TotalCount ' ] = total_count + step_count
final . append ( variant_out )
res = { ' Name ' : ' %s - %s _ %s ' % ( iid , vehicle , l_id ) , ' Language ' : l_id , ' IsUpdateAvailable ' : ' true ' ,
@ -289,7 +304,6 @@ def check_vehicle_update(vehicle_list):
res [ ' JsonURL ' ] = None
res [ ' FileSize ' ] = None
res [ ' Error ' ] = ' File failed to save '
Vehicle_req_list . append ( res )
else :
@ -300,10 +314,10 @@ def check_vehicle_update(vehicle_list):
return response
else :
response [ ' JSON ' ] = " Error "
response [ ' JSON ' ] = { " Error " : " Data Not available " }
return response
except :
response [ ' JSON ' ] = { " Error " : " Input Error" }
response [ ' JSON ' ] = { " Error " : " Data Error" }
return response
@ -318,9 +332,9 @@ def update_completed(FileName):
@frappe . whitelist ( )
def delete_complete ( doc = None , method = None ) :
site_name = cstr ( frappe . local . site )
base_url = os . path . expanduser ( " ~ " ) + " /frappe-bench/sites/ " + site_name + " /public "
path = base_url + ' /files/json_files/temp1/ '
# site_name1 = cstr(frappe.local.site )
base_url1 = os . path . expanduser ( " ~ " ) + " /frappe-bench/sites/ " + site_name + " /public "
path = base_url1 + ' /files/json_files/temp1/ '
path_file = os . listdir ( path )
if path_file :
for file in path_file :