@ -4,92 +4,94 @@
from __future__ import unicode_literals
from __future__ import unicode_literals
import frappe
import frappe
from frappe . utils import cstr , cint , getdate
from frappe import msgprint , _
from frappe import msgprint , _
import datetime
import datetime
current_db_name = frappe . conf . get ( " db_name " )
current_db_name = frappe . conf . get ( " db_name " )
def execute ( filters = None ) :
def execute ( filters = None ) :
columns , data = [ ] , [ ]
columns , data = [ ] , [ ]
columns = get_columns ( )
columns = get_columns ( )
data = get_data ( filters )
data = get_data ( filters )
return columns , data
return columns , data
def get_data ( filters ) :
def get_data ( filters ) :
if filters . get ( ' variant ' ) and filters . get ( ' model ' ) :
if filters . get ( ' variant ' ) and filters . get ( ' model ' ) :
from_date = filters [ ' from_date ' ]
from_date = filters [ ' from_date ' ]
to_date = filters [ ' to_date ' ]
to_date = filters [ ' to_date ' ]
modelfilter = filters [ ' model ' ]
modelfilter = filters [ ' model ' ]
variantfilter = filters [ ' variant ' ]
variantfilter = filters [ ' variant ' ]
variantfilter = variantfilter . split ( " . " )
variantfilter = variantfilter . split ( " . " )
data = frappe . db . sql ( """ SELECT date as date, device_id, device_type, module_id, vehicle_id, variant_id,variant_mapping_id, system_id, sub_system_id, procedure_id, steps_id,
data = frappe . db . sql ( """ SELECT date as date, device_id, device_type, module_id, vehicle_id, variant_id,variant_mapping_id, system_id, sub_system_id, procedure_id, steps_id,
count ( * ) as count , user_id , language FROM { 0 } . ` tabModel Usage ` WHERE vehicle_id = ' {1} ' and variant_id = ' {2} ' and ( date ( date ) between ' {3} ' and ' {4} ' )
count ( * ) as count , user_id , language FROM { 0 } . ` tabModel Usage ` WHERE vehicle_id = ' {1} ' and variant_id = ' {2} ' and ( date ( date ) between ' {3} ' and ' {4} ' )
GROUP BY date ( date ) , user_id , module_id , device_id , vehicle_id , variant_id , variant_mapping_id , system_id , sub_system_id , procedure_id , steps_id ,
GROUP BY date ( date ) , user_id , module_id , device_id , vehicle_id , variant_id , variant_mapping_id , system_id , sub_system_id , procedure_id , steps_id ,
language
language
order by module_id , vehicle_id , variant_id , variant_mapping_id , system_id , sub_system_id , procedure_id , steps_id , language , date DESC ;
order by module_id , vehicle_id , variant_id , variant_mapping_id , system_id , sub_system_id , procedure_id , steps_id , language , date DESC ;
""" .format(current_db_name, modelfilter, variantfilter[1], from_date, to_date), as_dict=1)
""" .format(current_db_name, modelfilter, variantfilter[1], from_date, to_date), as_dict=1)
for d in data :
for d in data :
if d [ ' user_id ' ] :
if d [ ' user_id ' ] :
try :
try :
dealer_info = frappe . db . sql ( """ SELECT dealer FROM {0} .`tabApp Users` where user_id= ' {1} ' ; """ . format ( current_db_name , d [ ' user_id ' ] ) , as_dict = 1 )
dealer_info = frappe . db . sql ( """ SELECT dealer FROM {0} .`tabApp Users` where user_id= ' {1} ' ; """ . format (
dealer_info = dealer_info [ - 1 ] [ ' dealer ' ]
current_db_name , d [ ' user_id ' ] ) , as_dict = 1 )
dealer_details = frappe . db . sql ( """ SELECT dealer_name,dealer_code,area as location,zone FROM {0} .`tabApp Dealer` where name= ' {1} ' ; """ . format ( current_db_name , dealer_info ) , as_dict = 1 )
dealer_info = dealer_info [ - 1 ] [ ' dealer ' ]
dealer_details = dealer_details [ - 1 ]
dealer_details = frappe . db . sql ( """ SELECT dealer_name,dealer_code,area as location,zone FROM {0} .`tabApp Dealer` where name= ' {1} ' ; """ . format (
d [ ' dealer_code ' ] = dealer_details [ ' dealer_code ' ]
current_db_name , dealer_info ) , as_dict = 1 )
d [ ' dealer_name ' ] = dealer_details [ ' dealer_name ' ]
dealer_details = dealer_details [ - 1 ]
d [ ' area ' ] = dealer_details [ ' location ' ]
d [ ' dealer_code ' ] = dealer_details [ ' dealer_code ' ]
d [ ' zone ' ] = dealer_details [ ' zone ' ]
d [ ' dealer_name ' ] = dealer_details [ ' dealer_name ' ]
except :
d [ ' area ' ] = dealer_details [ ' location ' ]
pass
d [ ' zone ' ] = dealer_details [ ' zone ' ]
except :
if data :
pass
return data
else :
if data :
frappe . msgprint ( ' No Data for Selected Filters. ' )
return data
else :
elif filters . get ( ' model ' ) :
frappe . msgprint ( ' No Data for Selected Filters. ' )
from_date = filters [ ' from_date ' ]
to_date = filters [ ' to_date ' ]
elif filters . get ( ' model ' ) :
modelfilter = filters [ ' model ' ]
from_date = filters [ ' from_date ' ]
to_date = filters [ ' to_date ' ]
data = frappe . db . sql ( """ SELECT date(date) as date, device_id, device_type, module_id, vehicle_id, variant_id,variant_mapping_id, system_id, sub_system_id, procedure_id,
modelfilter = filters [ ' model ' ]
data = frappe . db . sql ( """ SELECT date(date) as date, device_id, device_type, module_id, vehicle_id, variant_id,variant_mapping_id, system_id, sub_system_id, procedure_id,
steps_id , count ( * ) as count , user_id , language FROM { 0 } . ` tabModel Usage ` WHERE vehicle_id = ' {1} ' and ( date ( date ) between ' {2} ' and ' {3} ' )
steps_id , count ( * ) as count , user_id , language FROM { 0 } . ` tabModel Usage ` WHERE vehicle_id = ' {1} ' and ( date ( date ) between ' {2} ' and ' {3} ' )
GROUP BY date ( date ) , user_id , module_id , device_id , vehicle_id , variant_id , variant_mapping_id , system_id , sub_system_id , procedure_id , steps_id , language
GROUP BY date ( date ) , user_id , module_id , device_id , vehicle_id , variant_id , variant_mapping_id , system_id , sub_system_id , procedure_id , steps_id , language
order by module_id , vehicle_id , variant_id , variant_mapping_id , system_id , sub_system_id , procedure_id , steps_id , language ;
order by module_id , vehicle_id , variant_id , variant_mapping_id , system_id , sub_system_id , procedure_id , steps_id , language ;
; """ .format(current_db_name, modelfilter, from_date, to_date), as_dict=1)
; """ .format(current_db_name, modelfilter, from_date, to_date), as_dict=1)
for d in data :
for d in data :
if d [ ' user_id ' ] :
if d [ ' user_id ' ] :
try :
try :
dealer_info = frappe . db . sql ( """ SELECT dealer FROM {0} .`tabApp Users` where user_id= ' {1} ' ; """ . format ( current_db_name , d [ ' user_id ' ] ) , as_dict = 1 )
dealer_info = frappe . db . sql ( """ SELECT dealer FROM {0} .`tabApp Users` where user_id= ' {1} ' ; """ . format (
dealer_info = dealer_info [ - 1 ] [ ' dealer ' ]
current_db_name , d [ ' user_id ' ] ) , as_dict = 1 )
dealer_details = frappe . db . sql ( """ SELECT dealer_name,dealer_code,area as location,zone FROM {0} .`tabApp Dealer` where name= ' {1} ' ; """ . format ( current_db_name , dealer_info ) , as_dict = 1 )
dealer_info = dealer_info [ - 1 ] [ ' dealer ' ]
dealer_details = dealer_details [ - 1 ]
dealer_details = frappe . db . sql ( """ SELECT dealer_name,dealer_code,area as location,zone FROM {0} .`tabApp Dealer` where name= ' {1} ' ; """ . format (
d [ ' dealer_code ' ] = dealer_details [ ' dealer_code ' ]
current_db_name , dealer_info ) , as_dict = 1 )
d [ ' dealer_name ' ] = dealer_details [ ' dealer_name ' ]
dealer_details = dealer_details [ - 1 ]
d [ ' area ' ] = dealer_details [ ' location ' ]
d [ ' dealer_code ' ] = dealer_details [ ' dealer_code ' ]
d [ ' zone ' ] = dealer_details [ ' zone ' ]
d [ ' dealer_name ' ] = dealer_details [ ' dealer_name ' ]
except :
d [ ' area ' ] = dealer_details [ ' location ' ]
pass
d [ ' zone ' ] = dealer_details [ ' zone ' ]
except :
if data :
pass
return data
else :
if data :
frappe . msgprint ( ' No Data for Selected Filters. ' )
return data
else :
frappe . msgprint ( ' No Data for Selected Filters. ' )
elif filters . get ( ' variant ' ) :
from_date = filters [ ' from_date ' ]
elif filters . get ( ' variant ' ) :
to_date = filters [ ' to_date ' ]
from_date = filters [ ' from_date ' ]
variantfilter = filters [ ' variant ' ]
to_date = filters [ ' to_date ' ]
variantfilter = variantfilter . split ( " . " )
variantfilter = filters [ ' variant ' ]
data = frappe . db . sql ( """ SELECT date as date, device_id, device_type, module_id, vehicle_id, variant_id,variant_mapping_id, system_id, sub_system_id,
variantfilter = variantfilter . split ( " . " )
data = frappe . db . sql ( """ SELECT date as date, device_id, device_type, module_id, vehicle_id, variant_id,variant_mapping_id, system_id, sub_system_id,
procedure_id , steps_id , count ( * ) as count , user_id , language ,
procedure_id , steps_id , count ( * ) as count , user_id , language ,
login_name , concat ( first_name , ' ' , last_name ) as user_name
login_name , concat ( first_name , ' ' , last_name ) as user_name
FROM ` tabModel Usage ` mu left join ` tabApp Users ` au on mu . user_id = au . user_id
FROM ` tabModel Usage ` mu left join ` tabApp Users ` au on mu . user_id = au . user_id
@ -99,54 +101,70 @@ def get_data(filters):
order by module_id , vehicle_id , variant_id , variant_mapping_id , system_id , sub_system_id , procedure_id , steps_id , language ;
order by module_id , vehicle_id , variant_id , variant_mapping_id , system_id , sub_system_id , procedure_id , steps_id , language ;
; """ .format(current_db_name, variantfilter[0], variantfilter[1], from_date, to_date), as_dict=1)
; """ .format(current_db_name, variantfilter[0], variantfilter[1], from_date, to_date), as_dict=1)
for d in data :
for d in data :
if d [ ' user_id ' ] :
if d [ ' user_id ' ] :
try :
try :
dealer_info = frappe . db . sql ( """ SELECT dealer FROM {0} .`tabApp Users` where user_id= ' {1} ' ; """ . format ( current_db_name , d [ ' user_id ' ] ) , as_dict = 1 )
dealer_info = frappe . db . sql ( """ SELECT dealer FROM {0} .`tabApp Users` where user_id= ' {1} ' ; """ . format (
dealer_info = dealer_info [ - 1 ] [ ' dealer ' ]
current_db_name , d [ ' user_id ' ] ) , as_dict = 1 )
dealer_details = frappe . db . sql ( """ SELECT dealer_name,dealer_code,area as location,zone FROM {0} .`tabApp Dealer`
dealer_info = dealer_info [ - 1 ] [ ' dealer ' ]
dealer_details = frappe . db . sql ( """ SELECT dealer_name,dealer_code,area as location,zone FROM {0} .`tabApp Dealer`
where name = ' {1} ' ; """ .format(current_db_name, dealer_info), as_dict=1)
where name = ' {1} ' ; """ .format(current_db_name, dealer_info), as_dict=1)
dealer_details = dealer_details [ - 1 ]
dealer_details = dealer_details [ - 1 ]
d [ ' dealer_code ' ] = dealer_details [ ' dealer_code ' ]
d [ ' dealer_code ' ] = dealer_details [ ' dealer_code ' ]
d [ ' dealer_name ' ] = dealer_details [ ' dealer_name ' ]
d [ ' dealer_name ' ] = dealer_details [ ' dealer_name ' ]
d [ ' area ' ] = dealer_details [ ' location ' ]
d [ ' area ' ] = dealer_details [ ' location ' ]
d [ ' zone ' ] = dealer_details [ ' zone ' ]
d [ ' zone ' ] = dealer_details [ ' zone ' ]
except :
except :
pass
pass
if data :
if data :
return data
return data
else :
else :
frappe . msgprint ( ' No Data for Selected Filters. ' )
frappe . msgprint ( ' No Data for Selected Filters. ' )
def get_columns ( ) :
def get_columns ( ) :
columns = [
columns = [
{ " label " : _ ( " <b>Date</b> " ) , " fieldname " : " date " , " fieldtype " : " Date " , " width " : 150 } ,
{ " label " : _ ( " <b>Date</b> " ) , " fieldname " : " date " ,
# {"label": _("<b>User ID</b>"), "fieldname": "login_name", "fieldtype": "Data", "width": 125},
" fieldtype " : " Date " , " width " : 150 } ,
# {"label": _("<b>User Name</b>"), "fieldname": "user_name", "fieldtype": "Data", "width": 125},
# {"label": _("<b>User ID</b>"), "fieldname": "login_name", "fieldtype": "Data", "width": 125},
{ " label " : _ ( " <b>Model</b> " ) , " fieldname " : " vehicle_id " , " fieldtype " : " Data " , " width " : 150 } ,
# {"label": _("<b>User Name</b>"), "fieldname": "user_name", "fieldtype": "Data", "width": 125},
{ " label " : _ ( " <b>Variant Mapping</b> " ) , " fieldname " : " variant_mapping_id " , " fieldtype " : " Data " , " width " : 150 } ,
{ " label " : _ ( " <b>Model</b> " ) , " fieldname " : " vehicle_id " ,
{ " label " : _ ( " <b>Variant</b> " ) , " fieldname " : " variant_id " , " fieldtype " : " Data " , " width " : 80 } ,
" fieldtype " : " Data " , " width " : 150 } ,
{ " label " : _ ( " <b>Module</b> " ) , " fieldname " : " module_id " , " fieldtype " : " Data " , " width " : 150 } ,
{ " label " : _ ( " <b>Variant Mapping</b> " ) , " fieldname " : " variant_mapping_id " ,
{ " label " : _ ( " <b>System</b> " ) , " fieldname " : " system_id " , " fieldtype " : " Data " , " width " : 150 } ,
" fieldtype " : " Data " , " width " : 150 } ,
{ " label " : _ ( " <b>Sub System</b> " ) , " fieldname " : " sub_system_id " , " fieldtype " : " Data " , " width " : 150 } ,
{ " label " : _ ( " <b>Variant</b> " ) , " fieldname " : " variant_id " ,
{ " label " : _ ( " <b>Procedure</b> " ) , " fieldname " : " procedure_id " , " fieldtype " : " Data " , " width " : 150 } ,
" fieldtype " : " Data " , " width " : 80 } ,
{ " label " : _ ( " <b>Steps</b> " ) , " fieldname " : " steps_id " , " fieldtype " : " Data " , " width " : 150 } ,
{ " label " : _ ( " <b>Module</b> " ) , " fieldname " : " module_id " ,
{ " label " : _ ( " <b>Language</b> " ) , " fieldname " : " language " , " fieldtype " : " Data " , " width " : 80 } ,
" fieldtype " : " Data " , " width " : 150 } ,
{ " label " : _ ( " <b>Count</b> " ) , " fieldname " : " count " , " fieldtype " : " Data " , " width " : 80 } ,
{ " label " : _ ( " <b>System</b> " ) , " fieldname " : " system_id " ,
" fieldtype " : " Data " , " width " : 150 } ,
# {"label": _("<b>Zone</b>"), "fieldname": "zone", "fieldtype": "Data", "width": 150},
{ " label " : _ ( " <b>Sub System</b> " ) , " fieldname " : " sub_system_id " ,
# {"label": _("<b>Area Office</b>"), "fieldname": "area", "fieldtype": "Data", "width": 150},
" fieldtype " : " Data " , " width " : 150 } ,
# {"label": _("<b>Dealer Code</b>"), "fieldname": "dealer_code", "fieldtype": "Data", "width": 150},
{ " label " : _ ( " <b>Procedure</b> " ) , " fieldname " : " procedure_id " ,
# {"label": _("<b>Dealer Name</b>"), "fieldname": "dealer_name", "fieldtype": "Data", "width": 150},
" fieldtype " : " Data " , " width " : 150 } ,
{ " label " : _ ( " <b>Device</b> " ) , " fieldname " : " device_id " , " fieldtype " : " Data " , " width " : 150 } ,
{ " label " : _ ( " <b>Steps</b> " ) , " fieldname " : " steps_id " ,
{ " label " : _ ( " <b>Device Type</b> " ) , " fieldname " : " device_type " , " fieldtype " : " Data " , " width " : 150 }
" fieldtype " : " Data " , " width " : 150 } ,
]
{ " label " : _ ( " <b>Language</b> " ) , " fieldname " : " language " ,
return columns
" fieldtype " : " Data " , " width " : 80 } ,
{ " label " : _ ( " <b>Count</b> " ) , " fieldname " : " count " ,
" fieldtype " : " Data " , " width " : 80 } ,
# {"label": _("<b>Zone</b>"), "fieldname": "zone", "fieldtype": "Data", "width": 150},
# {"label": _("<b>Area Office</b>"), "fieldname": "area", "fieldtype": "Data", "width": 150},
# {"label": _("<b>Dealer Code</b>"), "fieldname": "dealer_code", "fieldtype": "Data", "width": 150},
# {"label": _("<b>Dealer Name</b>"), "fieldname": "dealer_name", "fieldtype": "Data", "width": 150},
{ " label " : _ ( " <b>Device</b> " ) , " fieldname " : " device_id " ,
" fieldtype " : " Data " , " width " : 150 } ,
{ " label " : _ ( " <b>Device Type</b> " ) , " fieldname " : " device_type " ,
" fieldtype " : " Data " , " width " : 150 }
]
return columns
@frappe . whitelist ( )
@frappe . whitelist ( )
def variant ( doctype , txt , searchfield , start , page_len , filters ) :
def variant ( doctype , txt , searchfield , start , page_len , filters ) :
model = filters . get ( ' name ' )
model = filters . get ( ' name ' )
variant = frappe . db . sql ( """ select name from `tabVariant` where name like %s """ , model + ' % ' , as_list = True )
variant = frappe . db . sql (
return variant
""" select name from `tabVariant` where name like %s """ , model + ' % ' , as_list = True )
return variant