@ -12,19 +12,19 @@ current_db_name = frappe.conf.get("db_name")
custom_lang = frappe . db . sql (
''' SELECT lang_code,lang_name FROM {0} .`tabCustom Languages` where lang_code <> ' en ' ; ''' . format (
current_db_name ) , as_dict = True )
activeStatusQuerycase = " case when active_status = ' Active ' then ' A ' else ' IA ' end as active_status "
active_status_querycase = " case when active_status = ' Active ' then ' A ' else ' IA ' end as active_status "
def execute ( filters = None ) :
data = getD ata ( filters )
data = get_d ata ( filters )
if not data :
data = [ ]
columns = getC olumns ( )
columns = get_c olumns ( )
return columns , data
def getD ata ( filters ) :
def get_d ata ( filters ) :
data = [ ]
if filters . variant_mapping != None :
fil = filters . variant_mapping + " % "
@ -43,93 +43,110 @@ def getData(filters):
and substring ( ` tabProcedure_Details ` . parent , - 2 ) = ' en '
order by ` tabSystem Mapping_Sub System ` . systems , ` tabSystem Mapping_Sub System ` . sub_systems , ` procedure ` , idx ;
""" .format(current_db_name, fil), as_dict=True)
filterData = filters . variant_mapping
if filterData != None and len ( data ) > 0 :
data = modifyData ( data , filterData )
filter_data = filters . variant_mapping
if filter_data != None and len ( data ) > 0 :
validation_flag , data = modify_data ( data , filter_data )
if validation_flag :
return data
else :
frappe . log_error ( ' Audit report ' , str ( data ) )
return [ ]
return data
def statusLengthAppend ( dicVal , parameter ) :
if len ( dicVal ) == 1 :
systemSize = str ( len ( dicVal ) ) + " " + parameter
else :
systemSize = str ( len ( dicVal ) ) + " " + parameter + " s "
return systemSize
def modifyData ( dataInput , filterParent ) :
list1 = [ ]
inputData = modifyChildData ( dataInput , indent = 5 , header = 0 )
parentAppend = addParent ( filterParent , indent = 0 , header = 1 )
sMap , sSize = getParentMap ( inputData , ' systems ' )
systemSize = statusLengthAppend ( sSize , ' System ' )
parentAppend [ 0 ] [ ' active_status ' ] = systemSize
for pa in parentAppend :
list1 . append ( pa )
for i in sMap :
sMap1 , sSize1 = getParentMap ( sMap [ i ] , ' systems ' )
sMapAppend = appendToDic1 ( sMap1 , indent = 1 , header = 0 )
ssMap , ssSize = getParentMap ( sMap [ i ] , ' sub_systems ' )
ssMapAppend = appendToDic2 ( ssMap , indent = 2 , header = 1 )
sMapAppend [ 0 ] [ ' active_status ' ] = statusLengthAppend ( ssSize , ' Sub System ' )
list1 . append ( sMapAppend [ 0 ] )
sys_assets = frappe . db . sql ( ''' SELECT system_asset as description, {0}
FROM { 1 } . ` tabSystem Mapping_System Assets `
where parent like ' {2} ' and systems = ' {3} ' and language = ' en ' order by idx ; ''' .format(activeStatusQuerycase,current_db_name,list1[0][ ' procedure_name ' ]+ " % " ,
sMapAppend [ 0 ] [ ' procedure_name ' ] ) , as_dict = True )
for sa in sys_assets :
list1 . append ( sa . update ( { ' procedure_name ' : " System Asset " , ' indent ' : 2 , ' header ' : ' ' , ' type ' : ' Asset ' } ) )
for j in ssMapAppend :
val = j [ ' procedure_name ' ]
proc = j [ ' procedure ' ]
procMap , procSize = getParentMap ( ssMap [ val ] , ' procedure_name ' )
procValuesDic = appendToDic3 (
procMap , procSize , j , indent = 3 , header = 0 , procedure = proc )
procLength = statusLengthAppend ( procValuesDic , ' Procedure ' )
j [ ' active_status ' ] = j [ ' active_status ' ] + ' / ' + procLength
list1 . append ( j )
for pm in procMap :
step_list , steps_size = getParentMap ( procMap [ pm ] , ' step_name ' )
stepLength = statusLengthAppend ( steps_size , ' Step ' )
list1 . append ( { ' procedure_name ' : pm , ' indent ' : 3 , ' header ' : 0 , ' active_status ' : stepLength , ' modified ' : ' ' } )
def status_length_append ( dic_val , parameter ) :
if len ( dic_val ) == 1 :
system_size = str ( len ( dic_val ) ) + " " + parameter
else :
system_size = str ( len ( dic_val ) ) + " " + parameter + " s "
return system_size
def modify_data ( data_input , filter_parent ) :
try :
list1 = [ ]
input_data = modify_child_data ( data_input , indent = 5 , header = 0 )
parent_append = add_parent ( filter_parent , indent = 0 , header = 1 )
s_map , s_size = get_parent_map ( input_data , ' systems ' )
system_size = status_length_append ( s_size , ' System ' )
if parent_append :
parent_append [ 0 ] [ ' active_status ' ] = system_size
for pa in parent_append :
list1 . append ( pa )
for i in s_map :
s_map1 , s_size1 = get_parent_map ( s_map [ i ] , ' systems ' )
s_map_append = append_to_dic1 ( s_map1 , indent = 1 , header = 0 )
ss_map , ss_size = get_parent_map ( s_map [ i ] , ' sub_systems ' )
ss_map_append = append_to_dic2 ( ss_map , indent = 2 , header = 1 )
if s_map_append :
s_map_append [ 0 ] [ ' active_status ' ] = status_length_append (
ss_size , ' Sub System ' )
list1 . append ( s_map_append [ 0 ] )
sys_assets = frappe . db . sql ( ''' SELECT system_asset as description, {0} FROM {1} .`tabSystem Mapping_System Assets`
where parent like ' {2} ' and systems = ' {3} ' and language = ' en ' order by idx ; ''' .format(
active_status_querycase , current_db_name , list1 [ 0 ] [ ' procedure_name ' ] + " % " ,
s_map_append [ 0 ] [ ' procedure_name ' ] ) , as_dict = True )
for sa in sys_assets :
list1 . append ( sa . update (
{ ' procedure_name ' : " System Asset " , ' indent ' : 2 , ' header ' : ' ' , ' type ' : ' Asset ' } ) )
for j in ss_map_append :
val = j [ ' procedure_name ' ]
proc = j [ ' procedure ' ]
proc_map , proc_size = get_parent_map ( ss_map [ val ] , ' procedure_name ' )
proc_values_dic = append_to_dic3 (
proc_map , proc_size , j , indent = 3 , header = 0 , procedure = proc )
proc_length = status_length_append ( proc_values_dic , ' Procedure ' )
j [ ' active_status ' ] = j [ ' active_status ' ] + ' / ' + proc_length
list1 . append ( j )
for pm in proc_map :
step_list , steps_size = get_parent_map (
proc_map [ pm ] , ' step_name ' )
step_length = status_length_append ( steps_size , ' Step ' )
list1 . append ( { ' procedure_name ' : pm , ' indent ' : 3 , ' header ' : 0 ,
' active_status ' : step_length , ' modified ' : ' ' } )
for sl in step_list :
list1 . append ( { ' procedure_name ' : sl , ' indent ' : 4 , ' header ' : 0 , ' active_status ' : ' ' , ' modified ' : ' ' } )
for ss in step_list [ sl ] :
ss . update ( { ' procedure_name ' : ss [ ' content_type ' ] } )
list1 . append ( { ' procedure_name ' : sl , ' indent ' : 4 ,
' header ' : 0 , ' active_status ' : ' ' , ' modified ' : ' ' } )
for ss in step_list [ sl ] :
ss . update ( { ' procedure_name ' : ss [ ' content_type ' ] } )
list1 . append ( ss )
appendData = addDuplicateData ( list1 )
appendData = removeDuplicateAndHeader ( appendData )
return appendData
def appendToDic1 ( mapData , indent , header ) :
mapDataAppend = [ ]
for d in mapData :
keyDict = {
' procedure_name ' : d ,
' active_status ' : mapData [ d ] [ 0 ] [ ' active_status ' ] ,
' indent ' : indent ,
' header ' : header ,
' type ' : ' System '
}
mapDataAppend . append ( keyDict )
return mapDataAppend
append_data = add_duplicate_data ( list1 )
append_data = remove_duplicate_and_header ( append_data )
return True , append_data
except Exception as e :
frappe . log_error ( ' Audit report_modify ' , str ( e ) )
return False , str ( e )
def append_to_dic1 ( map_data , indent , header ) :
map_data_append = [ ]
for d in map_data :
if d :
key_dict = {
' procedure_name ' : d ,
' active_status ' : map_data [ d ] [ 0 ] [ ' active_status ' ] ,
' indent ' : indent ,
' header ' : header ,
' type ' : ' System '
}
map_data_append . append ( key_dict )
return map_data_append
def appendToDic2 ( mapData , indent , header ) :
mapDataA ppend = [ ]
for d in mapD ata :
da = mapD ata [ d ] [ 0 ]
keyD ict = {
def append_to_dic2 ( map_d ata , indent , header ) :
map_data_a ppend = [ ]
for d in map_d ata :
da = map_d ata [ d ] [ 0 ]
key_d ict = {
' systems ' : da [ ' systems ' ] ,
' sub_systems ' : da [ ' sub_systems ' ] ,
' parent ' : da [ ' parent ' ] ,
@ -148,8 +165,8 @@ def appendToDic2(mapData, indent, header):
other_proc = other_proc [ : - 2 ] + c [ ' lang_code ' ]
others = frappe . db . sql ( ''' select case when `tabProcedure`.active_status = ' Active ' then ' A ' WHEN `tabProcedure`.active_status = ' InActive ' then ' IA ' end as active_status,count(distinct(`tabProcedure_Details`.procedure_name)) as syscount,`tabProcedure`.workflow_state
from ( { 0 } . ` tabProcedure_Details ` inner join { 0 } . ` tabProcedure ` on ` tabProcedure_Details ` . ` parent ` = ` tabProcedure ` . ` name ` )
where ` tabProcedure ` . ` name ` = ' {1} ' ; ''' .format(current_db_name, other_proc,activeStatusQ uerycase), as_dict=True)
where ` tabProcedure ` . ` name ` = ' {1} ' ; ''' .format(current_db_name, other_proc, active_status_q uerycase), as_dict=True)
if len ( others ) > 0 :
others = others [ 0 ]
if others [ ' active_status ' ] is not None :
@ -161,15 +178,16 @@ def appendToDic2(mapData, indent, header):
c [ ' lang_code ' ] ) ] = others [ ' active_status ' ] + ' / ' + str ( others [ ' syscount ' ] ) + ' Procedures '
dic1 [ ' {} _workflow_state ' . format (
c [ ' lang_code ' ] ) ] = others [ ' workflow_state ' ]
keyD ict . update ( dic1 )
key_d ict . update ( dic1 )
mapDataA ppend . append ( keyD ict )
return mapDataA ppend
map_data_a ppend . append ( key_d ict )
return map_data_a ppend
def appendToDic3 ( mapData , procS ize , j , indent , header , procedure ) :
mapDataA ppend = [ ]
def append_to_dic3 ( map_data , proc_s ize , j , indent , header , procedure ) :
map_data_a ppend = [ ]
i = 0
dic1 = { }
list1 = [ ]
@ -185,32 +203,35 @@ def appendToDic3(mapData, procSize, j, indent, header, procedure):
list2 . append ( l )
list1 . append ( list2 )
for u in mapData :
dateList = [ ]
for k in mapData [ u ] :
dateList . append ( str ( k [ ' modified ' ] ) )
dateList . sort ( key = lambda date : datetime . strptime ( date , " % Y- % m- %d % H: % M: % S. %f " ) )
for u in map_data :
date_list = [ ]
for k in map_data [ u ] :
date_list . append ( str ( k [ ' modified ' ] ) )
date_list . sort ( key = lambda date : datetime . strptime (
date , " % Y- % m- %d % H: % M: % S. %f " ) )
if len ( mapD ata [ u ] ) == 1 :
stepL ength = str ( len ( mapD ata [ u ] ) ) + " Step "
if len ( map_d ata [ u ] ) == 1 :
step_l ength = str ( len ( map_d ata [ u ] ) ) + " Step "
else :
stepL ength = str ( len ( mapD ata [ u ] ) ) + " Steps "
step_l ength = str ( len ( map_d ata [ u ] ) ) + " Steps "
procD ict = {
' systems ' : mapD ata [ u ] [ 0 ] [ ' systems ' ] ,
' sub_systems ' : mapD ata [ u ] [ 0 ] [ ' sub_systems ' ] ,
proc_d ict = {
' systems ' : map_d ata [ u ] [ 0 ] [ ' systems ' ] ,
' sub_systems ' : map_d ata [ u ] [ 0 ] [ ' sub_systems ' ] ,
' parent ' : j [ " parent " ] ,
' procedure_name ' : u ,
' indent ' : indent ,
' header ' : header ,
' active_status ' : stepL ength ,
' active_status ' : step_l ength ,
' type ' : ' Title ' ,
' modified ' : dateL ist [ - 1 ]
' modified ' : date_l ist [ - 1 ]
}
dic2 = { }
for cus in range ( len ( custom_lang ) ) :
if len ( list1 [ cus ] ) > 0 :
if list1 [ cus ] [ i ] [ 0 ] == 1 :
dic1 [ ' {} _active_status ' . format ( custom_lang [ cus ] [ ' lang_code ' ] ) ] = str (
list1 [ cus ] [ i ] [ 0 ] ) + " Step "
@ -219,66 +240,71 @@ def appendToDic3(mapData, procSize, j, indent, header, procedure):
list1 [ cus ] [ i ] [ 0 ] ) + " Steps "
# Append modified date
dic1 [ ' {} _modified ' . format ( custom_lang [ cus ] [ ' lang_code ' ] ) ] = list1 [ cus ] [ i ] [ 1 ]
dic1 [ ' {} _modified ' . format (
custom_lang [ cus ] [ ' lang_code ' ] ) ] = list1 [ cus ] [ i ] [ 1 ]
dic2 . update ( dic1 )
procD ict . update ( dic1 )
proc_d ict . update ( dic1 )
i + = 1
mapDataA ppend . append ( procD ict )
return mapDataA ppend
map_data_a ppend . append ( proc_d ict )
return map_data_a ppend
def modifyChildData ( childD ata , indent , header ) :
for a in childD ata :
def modify_child_data ( child_d ata , indent , header ) :
for a in child_d ata :
a . update ( { ' indent ' : indent } )
a . update ( { ' header ' : header } )
a . update ( { ' type ' : " Step " } )
return childD ata
return child_d ata
def addParent ( variantP arent , indent , header ) :
def add_parent ( variant_p arent , indent , header ) :
list1 = [ ]
varParD ict = {
' procedure_name ' : variantP arent ,
var_par_d ict = {
' procedure_name ' : variant_p arent ,
' indent ' : indent ,
' header ' : header ,
}
list1 . append ( varParDict )
variant_assests = frappe . db . sql ( '''
SELECT category as procedure_name , attach_file as description , { 2 } FROM { 0 } . ` tabVariant Mapping_Assets ` where parent = ' {1} ' ; ''' .format(current_db_name,variantParent,activeStatusQuerycase),as_dict = True)
list1 . append ( var_par_dict )
variant_assests = frappe . db . sql ( ''' SELECT category as procedure_name,attach_file as description, {2}
FROM { 0 } . ` tabVariant Mapping_Assets `
where parent = ' {1} ' ; ''' .format(current_db_name, variant_parent,
active_status_querycase ) , as_dict = True )
for va in variant_assests :
list1 . append ( va . update ( { ' indent ' : 1 , ' header ' : header , ' type ' : ' Asset ' } ) )
list1 . append (
va . update ( { ' indent ' : 1 , ' header ' : header , ' type ' : ' Asset ' } ) )
return list1
def getParentMap ( input_list , parameter ) :
sizeList = [ ]
parentChildMap = { }
def get_parent_map ( input_list , parameter ) :
size_list = [ ]
parent_child_map = { }
for b in input_list :
parentChildM ap . setdefault ( b [ parameter ] or None , [ ] ) . append ( b )
for c in parentChildM ap :
sizeL ist . append ( len ( parentChildM ap [ c ] ) )
return parentChildMap , sizeL ist
parent_child_m ap . setdefault ( b [ parameter ] or None , [ ] ) . append ( b )
for c in parent_child_m ap :
size_l ist . append ( len ( parent_child_m ap [ c ] ) )
return parent_child_map , size_l ist
def addDuplicateD ata ( data1 ) :
prevV alue = " "
def add_duplicate_d ata ( data1 ) :
prev_v alue = " "
for i in data1 :
if i [ ' procedure_name ' ] == prevV alue :
if i [ ' procedure_name ' ] == prev_v alue :
dup = { " duplicate " : " yes " }
else :
dup = { " duplicate " : " no " }
i . update ( dup )
prevV alue = i [ ' procedure_name ' ]
prev_v alue = i [ ' procedure_name ' ]
return data1
def removeDuplicateAndH eader ( data1 ) :
def remove_duplicate_and_h eader ( data1 ) :
for k in data1 :
if k [ ' header ' ] == 0 :
k [ ' workflow_state ' ] = None
if k [ ' indent ' ] == 4 or k [ ' indent ' ] == 5 :
if k [ ' indent ' ] == 4 or k [ ' indent ' ] == 5 :
k . pop ( ' active_status ' )
k . pop ( ' modified ' )
if k [ ' indent ' ] == 6 :
@ -288,7 +314,7 @@ def removeDuplicateAndHeader(data1):
return data1
def getC olumns ( ) :
def get_c olumns ( ) :
columns = [
{
" fieldname " : " procedure_name " ,
@ -306,7 +332,7 @@ def getColumns():
" fieldname " : " description " ,
" label " : _ ( " <b>Description</b> " ) ,
" fieldtype " : " Data " ,
" width " : 200
} ,
{
@ -360,10 +386,11 @@ def getColumns():
lang . append ( lang_modified )
columns + = lang
return columns
@frappe . whitelist ( )
def variant ( doctype , txt , searchfield , start , page_len , filters ) :
current_db_name = frappe . conf . get ( " db_name " )
return frappe . db . sql ( """ select name,family_code,fuel,transmission,vehicle_segment,active_status
current_db_name = frappe . conf . get ( " db_name " )
return frappe . db . sql ( """ select name,family_code,fuel,transmission,vehicle_segment,active_status
FROM { 0 } . ` tabVariant Mapping ` where
( active_status like " %% %(txt)s %% " or vehicle_segment like " %% %(txt)s %% " or name like " %% %(txt)s %% " or variant like " %% %(txt)s %% " or family_code like " %% %(txt)s %% " or fuel like " %% %(txt)s %% " or transmission like " %% %(txt)s %% " ) order by modified desc limit % ( start ) s , % ( page_len ) s """ .format(current_db_name) % { ' txt ' : txt, ' start ' : start, ' page_len ' : page_len})
( active_status like " %% %(txt)s %% " or vehicle_segment like " %% %(txt)s %% " or name like " %% %(txt)s %% " or variant like " %% %(txt)s %% " or family_code like " %% %(txt)s %% " or fuel like " %% %(txt)s %% " or transmission like " %% %(txt)s %% " ) order by modified desc limit % ( start ) s , % ( page_len ) s """ .format(current_db_name) % { ' txt ' : txt, ' start ' : start, ' page_len ' : page_len})