Compare commits

...

3 Commits

  1. 80
      smart_service/add_ons/report/feedback_report/feedback_report.py
  2. 71
      smart_service/add_ons/report/installation_report/installation_report.py
  3. 86
      smart_service/add_ons/report/login_report/login_report.py
  4. 114
      smart_service/add_ons/report/model_download_report/model_download_report.py
  5. 253
      smart_service/add_ons/report/model_hit_report/model_hit_report.py
  6. 496
      smart_service/apis/app_user_login.py
  7. 86
      smart_service/masters/report/drive_translation/drive_translation.py
  8. 66
      smart_service/masters/report/fuel_translation/fuel_translation.py
  9. 98
      smart_service/masters/report/sub_systems_translation/sub_systems_translation.py
  10. 87
      smart_service/masters/report/systems_translation/systems_translation.py
  11. 82
      smart_service/masters/report/transmission_translation/transmission_translation.py
  12. 66
      smart_service/masters/report/variant_translation/variant_translation.py
  13. 106
      smart_service/masters/report/vehicle_segment_translation/vehicle_segment_translation.py
  14. 82
      smart_service/masters/report/vehicle_translation/vehicle_translation.py

80
smart_service/add_ons/report/feedback_report/feedback_report.py

@ -3,47 +3,61 @@
from __future__ import unicode_literals
import frappe
from frappe.utils import cstr, cint, getdate
from frappe import msgprint, _
import sys
sys.tracebacklimit=0
sys.tracebacklimit = 0
def execute(filters=None):
columns, data = [], []
columns = get_columns()
data = get_data(filters)
return columns, data
columns, data = [], []
columns = get_columns()
data = get_data(filters)
return columns, data
def get_data(filters):
current_db_name = frappe.conf.get("db_name")
data = frappe.db.sql("""select uf.name,uf.date,uf.subject,uf.user_name,uf.status,uf.attachments,uf.closure_date,uf.closed_by,
current_db_name = frappe.conf.get("db_name")
data = frappe.db.sql("""select uf.name,uf.date,uf.subject,uf.user_name,uf.status,uf.attachments,uf.closure_date,uf.closed_by,
uf.description,uf.feedback_type,dealer.dealer_code,dealer.zone,dealer.dealer_name,uf.closure_date,uf.closed_by,
dealer.area,au.user_id,concat_ws(' ',au.first_name,au.last_name) as user_name from {0}.`tabUser Feedback` uf,{0}.`tabApp Dealer` dealer,{0}.`tabApp Users` au
where uf.user_name = au.name and
(date(uf.modified) between '{1}' and '{2}') group by uf.name""".format(current_db_name,filters.get('from_date'), filters.get('to_date')), as_dict=1)
if data:
return data
else:
frappe.msgprint('No Data for Selected Filters.')
(date(uf.modified) between '{1}' and '{2}') group by uf.name ORDER BY uf.date DESC""".format(current_db_name, filters.get('from_date'), filters.get('to_date')), as_dict=1)
if data:
return data
else:
frappe.msgprint('No Data for Selected Filters.')
def get_columns():
columns = [
{"label": _("<b>Date</b>"), "fieldname": "date", "fieldtype": "Date", "width": 100},
{"label": _("<b>Feedback ID</b>"), "fieldname": "name", "fieldtype": "Link", "options":"User Feedback","width": 120},
{"label": _("<b>Feedback Type</b>"), "fieldname": "feedback_type", "fieldtype": "Data", "width": 120},
{"label": _("<b>Feedback Title</b>"), "fieldname": "subject", "fieldtype": "Data", "width": 120},
{"label": _("<b>Feedback Description</b>"), "fieldname": "description", "fieldtype": "Text Editor", "width": 250},
{"label": _("<b>Attachments</b>"), "fieldname": "attachments", "fieldtype": "Data", "width": 100},
{"label": _("<b>Feedback Status</b>"), "fieldname": "status", "fieldtype": "Data", "width": 100},
{"label": _("<b>User ID</b>"), "fieldname": "user_id", "fieldtype":"Data","width": 100},
{"label": _("<b>User Name</b>"), "fieldname": "user_name", "fieldtype": "Data", "width": 150},
{"label": _("<b>Zone</b>"), "fieldname": "zone", "fieldtype": "Data", "width": 100},
{"label": _("<b>Area Office</b>"), "fieldname": "area", "fieldtype": "Data", "width": 140},
{"label": _("<b>Dealer Code</b>"), "fieldname": "dealer_code", "fieldtype": "Data", "width": 120},
{"label": _("<b>Dealer Name</b>"), "fieldname": "dealer_name", "fieldtype": "Data", "width": 150},
{"label": _("<b>Closure Date</b>"), "fieldname": "closure_date", "fieldtype": "Data", "width": 150},
{"label": _("<b>Closed By</b>"), "fieldname": "closed_by", "fieldtype": "Data", "width": 120}
]
return columns
def get_columns():
columns = [
{"label": _("<b>User ID</b>"), "fieldname": "user_id",
"fieldtype": "Data", "width": 100},
{"label": _("<b>User Name</b>"), "fieldname": "user_name",
"fieldtype": "Data", "width": 150},
{"label": _("<b>Date</b>"), "fieldname": "date",
"fieldtype": "Date", "width": 100},
{"label": _("<b>Feedback ID</b>"), "fieldname": "name",
"fieldtype": "Link", "options": "User Feedback", "width": 120},
{"label": _("<b>Feedback Type</b>"), "fieldname": "feedback_type",
"fieldtype": "Data", "width": 120},
{"label": _("<b>Feedback Title</b>"), "fieldname": "subject",
"fieldtype": "Data", "width": 120},
{"label": _("<b>Feedback Description</b>"), "fieldname": "description",
"fieldtype": "Text Editor", "width": 250},
{"label": _("<b>Attachments</b>"), "fieldname": "attachments",
"fieldtype": "Data", "width": 100},
{"label": _("<b>Feedback Status</b>"), "fieldname": "status",
"fieldtype": "Data", "width": 100},
{"label": _("<b>Zone</b>"), "fieldname": "zone",
"fieldtype": "Data", "width": 100},
{"label": _("<b>Area Office</b>"), "fieldname": "area",
"fieldtype": "Data", "width": 140},
{"label": _("<b>Dealer Code</b>"), "fieldname": "dealer_code",
"fieldtype": "Data", "width": 120},
{"label": _("<b>Dealer Name</b>"), "fieldname": "dealer_name",
"fieldtype": "Data", "width": 150},
{"label": _("<b>Closure Date</b>"), "fieldname": "closure_date",
"fieldtype": "Data", "width": 150},
{"label": _("<b>Closed By</b>"), "fieldname": "closed_by",
"fieldtype": "Data", "width": 120}
]
return columns

71
smart_service/add_ons/report/installation_report/installation_report.py

@ -5,47 +5,54 @@
from __future__ import unicode_literals
import frappe
from frappe.utils import cstr, cint, getdate
from frappe import msgprint, _
def execute(filters=None):
columns, data = [], []
columns = get_columns()
data = get_data(filters)
return columns, data
columns, data = [], []
columns = get_columns()
data = get_data(filters)
return columns, data
def get_data(filters):
current_db_name = frappe.conf.get("db_name")
data = frappe.db.sql("""select dealer.zone,au.user_id,concat_ws(' ',au.first_name,au.last_name) as user_name,dealer.dealer_code,dealer.dealer_name,dealer.area,ad.os,ad.os_version,
current_db_name = frappe.conf.get("db_name")
data = frappe.db.sql("""select dealer.zone,au.user_id,concat_ws(' ',au.first_name,au.last_name) as user_name,dealer.dealer_code,dealer.dealer_name,dealer.area,ad.os,ad.os_version,
al.device,ad.device_id,ad.app_current_version,al.type as type,ad.device_type,al.date_time_stamp,al.creation,ad.last_login as date,al.date_time_stamp as time,time(al.date_time_stamp) as last_time
from {0}.`tabApp Log` al, {0}.`tabApp Device` ad, {0}.`tabApp Users` au, {0}.`tabApp Dealer` dealer
where
al.device = ad.name and al.user = au.name and au.dealer = dealer.name and (al.type = 'Installed' or al.type = 'Reinstalled') and
(date(al.modified) between '{1}' and '{2}')""".format(current_db_name,filters.get('from_date'), filters.get('to_date')), as_dict=1)
(date(al.modified) between '{1}' and '{2}') ORDER BY ad.last_login DESC""".format(current_db_name, filters.get('from_date'), filters.get('to_date')), as_dict=1)
if data:
return data
else:
frappe.msgprint('No Data for Selected Filters.')
if data:
return data
else:
frappe.msgprint('No Data for Selected Filters.')
def get_columns():
columns = [
{"label": _("<b>Zone</b>"), "fieldname": "zone", "fieldtype": "Data", "width": 100},
{"label": _("<b>Area Office</b>"), "fieldname": "area", "fieldtype":"Data","width": 150},
{"label": _("<b>Dealer Code</b>"), "fieldname": "dealer_code", "fieldtype": "Data", "width": 100},
{"label": _("<b>Dealer Name</b>"), "fieldname": "dealer_name", "fieldtype":"Data","width": 150},
{"label": _("<b>Installation</b>"), "fieldname": "device", "fieldtype": "Data","width": 100},
{"label": _("<b>Device</b>"), "fieldname": "device_type", "fieldtype": "Data","width": 100},
{"label": _("<b>Device ID</b>"), "fieldname": "device_id", "fieldtype": "Data", "width": 100},
{"label": _("<b>Device OS</b>"), "fieldname": "os", "fieldtype": "Data", "width": 100},
{"label": _("<b>OS Version</b>"), "fieldname": "os_version", "fieldtype": "Data", "width": 100},
{"label": _("<b>User ID</b>"), "fieldname": "user_id", "fieldtype": "Data", "width": 100},
{"label": _("<b>User Name</b>"), "fieldname": "user_name", "fieldtype": "Data", "width": 100},
{"label": _("<b>Activity Type</b>"), "fieldname": "type", "fieldtype": "Data","width": 100},
{"label": _("<b>App Installation Date</b>"), "fieldname": "date_time_stamp", "fieldtype": "DateTime","width": 200},
{"label": _("<b>App Last Accessed Date</b>"), "fieldname": "date", "fieldtype": "DateTime","width": 200},
{"label": _("<b>App Version No</b>"), "fieldname": "app_current_version", "fieldtype": "Data", "width": 150},
]
return columns
def get_columns():
columns = [
{"label": _("<b>User ID</b>"), "fieldname": "user_id",
"fieldtype": "Data", "width": 100},
{"label": _("<b>User Name</b>"), "fieldname": "user_name",
"fieldtype": "Data", "width": 150},
{"label": _("<b>Installation</b>"), "fieldname": "device",
"fieldtype": "Data", "width": 100},
{"label": _("<b>App Version No</b>"), "fieldname": "app_current_version",
"fieldtype": "Data", "width": 150},
{"label": _("<b>Activity Type</b>"), "fieldname": "type",
"fieldtype": "Data", "width": 150},
{"label": _("<b>Device</b>"), "fieldname": "device_type",
"fieldtype": "Data", "width": 100},
{"label": _("<b>Device ID</b>"), "fieldname": "device_id",
"fieldtype": "Data", "width": 150},
{"label": _("<b>Device OS</b>"), "fieldname": "os",
"fieldtype": "Data", "width": 100},
{"label": _("<b>OS Version</b>"), "fieldname": "os_version",
"fieldtype": "Data", "width": 100},
{"label": _("<b>App Installation Date</b>"),
"fieldname": "date_time_stamp", "fieldtype": "DateTime", "width": 200},
{"label": _("<b>App Last Accessed Date</b>"),
"fieldname": "date", "fieldtype": "DateTime", "width": 200}
]
return columns

86
smart_service/add_ons/report/login_report/login_report.py

@ -3,64 +3,58 @@
from __future__ import unicode_literals
import frappe
from frappe.utils import cstr, cint, getdate
from frappe import msgprint, _
from frappe.utils import cstr, flt, cint,TIME_FORMAT,DATE_FORMAT,DATETIME_FORMAT, now_datetime
from datetime import date, time, datetime, timedelta
from frappe.utils import now
import datetime
def execute(filters=None):
columns, data = [], []
columns = get_columns()
data = get_data(filters)
return columns, data
columns, data = [], []
columns = get_columns()
data = get_data(filters)
return columns, data
def get_data(filters):
current_db_name = frappe.conf.get("db_name")
from_date = filters.get('from_date')
to_date = filters.get('to_date')
data_test = frappe.db.sql("""select count(al.name) as count,dealer.zone,au.user_id,concat_ws(' ',au.first_name,au.last_name) as user_name,
dealer.dealer_code,dealer.dealer_name,dealer.area,ad.os,ad.os_version,
ad.device_type,ad.device_id,ad.app_current_version,al.type,al.latitude,al.longitude,al.date_time_stamp,al.creation,
date(al.date_time_stamp) as date,time(ad.last_login) as time
from {0}.`tabApp Log` al,{0}.`tabApp Device` ad,{0}.`tabApp Users` au,{0}.`tabApp Dealer` dealer
where
al.device = ad.name and al.user = au.name and au.dealer = dealer.name and al.type = 'Logged in' and
(date(al.modified) between '{1}' and '{2}') group by al.user,ad.device_id,date(al.date_time_stamp)""".format(current_db_name,from_date,to_date), as_dict=1)
def get_data(filters):
current_db_name = frappe.conf.get("db_name")
from_date = filters.get('from_date')
to_date = filters.get('to_date')
data = frappe.db.sql("""select dealer.zone,au.user_id,concat_ws(' ',au.first_name,au.last_name) as user_name,
data = frappe.db.sql("""select dealer.zone,au.user_id,concat_ws(' ',au.first_name,au.last_name) as user_name,
dealer.dealer_code,dealer.dealer_name,dealer.area,ad.os,ad.os_version,
ad.device_type,ad.device_id,ad.app_current_version,al.type,date(al.date_time_stamp) as date,
al.latitude, al.longitude, au.name, al.device, time(al.date_time_stamp) as last_login_time, mal.count from {current_db_name}.`tabApp Log` al,{current_db_name}.`tabApp Device` ad, {current_db_name}.`tabApp Users` au,{current_db_name}.`tabApp Dealer` dealer,
al.latitude, al.longitude, au.name, al.device, time(al.date_time_stamp) as last_login_time, mal.count from {current_db_name}.`tabApp Log` al,
{current_db_name}.`tabApp Device` ad, {current_db_name}.`tabApp Users` au,{current_db_name}.`tabApp Dealer` dealer,
(select user,Max(date_time_stamp) as date_time_stam, count(date(date_time_stamp)) as count from {current_db_name}.`tabApp Log`
where date(date_time_stamp) between '{from_date}' and '{to_date}' group by user,date(date_time_stamp)) mal
where mal.user=al.user
and mal.user=au.name
and au.dealer = dealer.name
and al.device = ad.name
and mal.date_time_stam=al.date_time_stamp; """.format(current_db_name = current_db_name,from_date= from_date,to_date=to_date), as_dict=1)
if data:
return data
else:
frappe.msgprint('No Data for Selected Filters.')
def get_columns():
columns = [
{"label": _("<b>Date</b>"), "fieldname": "date", "fieldtype": "Date", "width": 100},
{"label": _("<b>Time</b>"), "fieldname": "last_login_time", "fieldtype": "DateTime", "width": 130},
{"label": _("<b>Zone</b>"), "fieldname": "zone", "fieldtype": "Data", "width": 100},
{"label": _("<b>Area Office</b>"), "fieldname": "area", "fieldtype": "Data", "width": 100},
{"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_type", "fieldtype": "Data", "width": 100},
{"label": _("<b>Device ID</b>"), "fieldname": "device_id", "fieldtype": "Data", "width": 150},
{"label": _("<b>User ID</b>"), "fieldname": "user_id", "fieldtype": "Data", "width": 150},
{"label": _("<b>User Name</b>"), "fieldname": "user_name", "fieldtype": "Data", "width": 100},
{"label": _("<b>Latitude</b>"), "fieldname": "latitude", "fieldtype": "Data", "width": 100},
{"label": _("<b>Longitude</b>"), "fieldname": "longitude", "fieldtype": "Data", "width": 100},
{"label": _("<b>Count</b>"), "fieldname": "count", "fieldtype": "Data", "width": 100},
]
return columns
and mal.date_time_stam=al.date_time_stamp ORDER BY date DESC; """.format(current_db_name=current_db_name, from_date=from_date, to_date=to_date), as_dict=1)
if data:
return data
else:
frappe.msgprint('No Data for Selected Filters.')
def get_columns():
columns = [
{"label": _("<b>User ID</b>"), "fieldname": "user_id",
"fieldtype": "Data", "width": 150},
{"label": _("<b>User Name</b>"), "fieldname": "user_name",
"fieldtype": "Data", "width": 150},
{"label": _("<b>Date</b>"), "fieldname": "date",
"fieldtype": "Date", "width": 100},
{"label": _("<b>Time</b>"), "fieldname": "last_login_time",
"fieldtype": "DateTime", "width": 130},
{"label": _("<b>Count</b>"), "fieldname": "count",
"fieldtype": "Data", "width": 100},
{"label": _("<b>Device ID</b>"), "fieldname": "device_id",
"fieldtype": "Data", "width": 100},
{"label": _("<b>Device</b>"), "fieldname": "device_type",
"fieldtype": "Data", "width": 130},
{"label": _("<b>Latitude</b>"), "fieldname": "latitude",
"fieldtype": "Data", "width": 100},
{"label": _("<b>Longitude</b>"), "fieldname": "longitude",
"fieldtype": "Data", "width": 100}
]
return columns

114
smart_service/add_ons/report/model_download_report/model_download_report.py

@ -3,65 +3,79 @@
from __future__ import unicode_literals
import frappe
from frappe.utils import cstr, cint, getdate
from frappe import msgprint, _
import datetime
current_db_name = frappe.conf.get("db_name")
def execute(filters=None):
columns, data = [], []
columns = get_columns()
data = get_data(filters)
return columns, data
columns, data = [], []
columns = get_columns()
data = get_data(filters)
return columns, data
def get_data(filters):
if filters.get('model'):
from_date=filters['from_date']
to_date=filters['to_date']
modelfilter=filters['model']
data = frappe.db.sql("""SELECT date(date) as date, device_id, device_type, app_version, download_vehicle_id, download_vehicle_version,
download_vehicle_date, download_vehicle_language_id, download_vehicle_current_version, user_id
FROM {0}.`tabModel Hit` WHERE download_vehicle_id='{1}' and (date(date) between '{2}' and '{3}') order by download_vehicle_id;""".format(current_db_name,
modelfilter, from_date, to_date), as_dict=1)
for d in data:
d['download_vehicle_id']=modelfilter
if d['user_id']:
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=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)
dealer_details=dealer_details[-1]
d['dealer_code']=dealer_details['dealer_code']
d['dealer_name']=dealer_details['dealer_name']
d['area']=dealer_details['location']
d['zone']=dealer_details['zone']
except:
pass
if data:
return data
else:
frappe.msgprint('No Data for Selected Filters.')
if filters.get('model'):
from_date = filters['from_date']
to_date = filters['to_date']
modelfilter = filters['model']
data = frappe.db.sql("""SELECT date(date) as date, device_id, device_type, app_version, download_vehicle_id, download_vehicle_version,
download_vehicle_date, download_vehicle_language_id, download_vehicle_current_version, mh.user_id,
login_name,concat(first_name,' ',last_name) as user_name
FROM `tabModel Hit` mh
left join `tabApp Users` au on mh.user_id = au.user_id
WHERE download_vehicle_id='{1}' and (date(date) between '{2}' and '{3}') ORDER BY download_vehicle_id,date DESC;""".format(current_db_name,
modelfilter, from_date, to_date), as_dict=1)
for d in data:
d['download_vehicle_id'] = modelfilter
if d['user_id']:
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 = 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)
dealer_details = dealer_details[-1]
d['dealer_code'] = dealer_details['dealer_code']
d['dealer_name'] = dealer_details['dealer_name']
d['area'] = dealer_details['location']
d['zone'] = dealer_details['zone']
except:
pass
if data:
return data
else:
frappe.msgprint('No Data for Selected Filters.')
def get_columns():
columns = [
{"label": _("<b>Date</b>"), "fieldname": "date", "fieldtype": "Date", "width": 100},
{"label": _("<b>Downloaded Vehicle</b>"), "fieldname": "download_vehicle_id", "fieldtype": "Data", "width": 170},
{"label": _("<b>Downloaded Version</b>"), "fieldname": "download_vehicle_current_version", "fieldtype": "Data", "width": 150},
{"label": _("<b>Downloaded Language</b>"), "fieldname": "download_vehicle_language_id", "fieldtype": "Data", "width": 150},
{"label": _("<b>App Version</b>"), "fieldname": "app_version", "fieldtype": "Data", "width": 150},
{"label": _("<b>Zone</b>"), "fieldname": "zone", "fieldtype": "Data", "width": 100},
{"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": 100},
{"label": _("<b>Device Type</b>"), "fieldname": "device_type", "fieldtype": "Data", "width": 130}
]
return columns
columns = [
{"label": _("<b>Date</b>"), "fieldname": "date",
"fieldtype": "Date", "width": 150},
{"label": _("<b>User ID</b>"), "fieldname": "login_name",
"fieldtype": "Data", "width": 125},
{"label": _("<b>User Name</b>"), "fieldname": "user_name",
"fieldtype": "Data", "width": 125},
{"label": _("<b>Downloaded Vehicle</b>"),
"fieldname": "download_vehicle_id", "fieldtype": "Data", "width": 150},
{"label": _("<b>Downloaded Language</b>"),
"fieldname": "download_vehicle_language_id", "fieldtype": "Data", "width": 150},
{"label": _("<b>Downloaded Version</b>"),
"fieldname": "download_vehicle_current_version", "fieldtype": "Data", "width": 150},
{"label": _("<b>App Version</b>"), "fieldname": "app_version",
"fieldtype": "Data", "width": 150},
# {"label": _("<b>Zone</b>"), "fieldname": "zone", "fieldtype": "Data", "width": 100},
# {"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

253
smart_service/add_ons/report/model_hit_report/model_hit_report.py

@ -4,142 +4,167 @@
from __future__ import unicode_literals
import frappe
from frappe.utils import cstr, cint, getdate
from frappe import msgprint, _
import datetime
current_db_name = frappe.conf.get("db_name")
def execute(filters=None):
columns, data = [], []
columns = get_columns()
data = get_data(filters)
return columns, data
columns, data = [], []
columns = get_columns()
data = get_data(filters)
return columns, data
def get_data(filters):
if filters.get('variant') and filters.get('model'):
from_date=filters['from_date']
to_date=filters['to_date']
modelfilter=filters['model']
variantfilter=filters['variant']
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,
if filters.get('variant') and filters.get('model'):
from_date = filters['from_date']
to_date = filters['to_date']
modelfilter = filters['model']
variantfilter = filters['variant']
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 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,
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, variantfilter[1], from_date, to_date), as_dict=1)
for d in data:
if d['user_id']:
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=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)
dealer_details=dealer_details[-1]
d['dealer_code']=dealer_details['dealer_code']
d['dealer_name']=dealer_details['dealer_name']
d['area']=dealer_details['location']
d['zone']=dealer_details['zone']
except:
pass
if data:
return data
else:
frappe.msgprint('No Data for Selected Filters.')
elif filters.get('model'):
from_date=filters['from_date']
to_date=filters['to_date']
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,
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)
for d in data:
if d['user_id']:
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 = 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)
dealer_details = dealer_details[-1]
d['dealer_code'] = dealer_details['dealer_code']
d['dealer_name'] = dealer_details['dealer_name']
d['area'] = dealer_details['location']
d['zone'] = dealer_details['zone']
except:
pass
if data:
return data
else:
frappe.msgprint('No Data for Selected Filters.')
elif filters.get('model'):
from_date = filters['from_date']
to_date = filters['to_date']
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}')
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;
;""".format(current_db_name, modelfilter, from_date, to_date), as_dict=1)
for d in data:
if d['user_id']:
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=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)
dealer_details=dealer_details[-1]
d['dealer_code']=dealer_details['dealer_code']
d['dealer_name']=dealer_details['dealer_name']
d['area']=dealer_details['location']
d['zone']=dealer_details['zone']
except:
pass
if data:
return data
else:
frappe.msgprint('No Data for Selected Filters.')
elif filters.get('variant'):
from_date=filters['from_date']
to_date=filters['to_date']
variantfilter=filters['variant']
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 FROM {0}.`tabModel Usage` WHERE vehicle_id='{1}' and variant_id='{2}'
for d in data:
if d['user_id']:
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 = 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)
dealer_details = dealer_details[-1]
d['dealer_code'] = dealer_details['dealer_code']
d['dealer_name'] = dealer_details['dealer_name']
d['area'] = dealer_details['location']
d['zone'] = dealer_details['zone']
except:
pass
if data:
return data
else:
frappe.msgprint('No Data for Selected Filters.')
elif filters.get('variant'):
from_date = filters['from_date']
to_date = filters['to_date']
variantfilter = filters['variant']
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,
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
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, 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)
for d in data:
if d['user_id']:
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=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)
dealer_details=dealer_details[-1]
d['dealer_code']=dealer_details['dealer_code']
d['dealer_name']=dealer_details['dealer_name']
d['area']=dealer_details['location']
d['zone']=dealer_details['zone']
except:
pass
if data:
return data
else:
frappe.msgprint('No Data for Selected Filters.')
;""".format(current_db_name, variantfilter[0], variantfilter[1], from_date, to_date), as_dict=1)
for d in data:
if d['user_id']:
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 = 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)
dealer_details = dealer_details[-1]
d['dealer_code'] = dealer_details['dealer_code']
d['dealer_name'] = dealer_details['dealer_name']
d['area'] = dealer_details['location']
d['zone'] = dealer_details['zone']
except:
pass
if data:
return data
else:
frappe.msgprint('No Data for Selected Filters.')
def get_columns():
columns = [
{"label": _("<b>Date</b>"), "fieldname": "date", "fieldtype": "Date", "width": 150},
{"label": _("<b>Module</b>"), "fieldname": "module_id", "fieldtype": "Data", "width": 150},
{"label": _("<b>Model</b>"), "fieldname": "vehicle_id", "fieldtype": "Data", "width": 150},
{"label": _("<b>Variant Mapping</b>"), "fieldname": "variant_mapping_id", "fieldtype": "Data", "width": 150},
{"label": _("<b>Variant</b>"), "fieldname": "variant_id", "fieldtype": "Data", "width": 80},
{"label": _("<b>System</b>"), "fieldname": "system_id", "fieldtype": "Data", "width": 150},
{"label": _("<b>Sub System</b>"), "fieldname": "sub_system_id", "fieldtype": "Data", "width": 150},
{"label": _("<b>Procedure</b>"), "fieldname": "procedure_id", "fieldtype": "Data", "width": 150},
{"label": _("<b>Steps</b>"), "fieldname": "steps_id", "fieldtype": "Data", "width": 150},
{"label": _("<b>Language</b>"), "fieldname": "language", "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
columns = [
{"label": _("<b>Date</b>"), "fieldname": "date",
"fieldtype": "Date", "width": 150},
# {"label": _("<b>User ID</b>"), "fieldname": "login_name", "fieldtype": "Data", "width": 125},
# {"label": _("<b>User Name</b>"), "fieldname": "user_name", "fieldtype": "Data", "width": 125},
{"label": _("<b>Model</b>"), "fieldname": "vehicle_id",
"fieldtype": "Data", "width": 150},
{"label": _("<b>Variant Mapping</b>"), "fieldname": "variant_mapping_id",
"fieldtype": "Data", "width": 150},
{"label": _("<b>Variant</b>"), "fieldname": "variant_id",
"fieldtype": "Data", "width": 80},
{"label": _("<b>Module</b>"), "fieldname": "module_id",
"fieldtype": "Data", "width": 150},
{"label": _("<b>System</b>"), "fieldname": "system_id",
"fieldtype": "Data", "width": 150},
{"label": _("<b>Sub System</b>"), "fieldname": "sub_system_id",
"fieldtype": "Data", "width": 150},
{"label": _("<b>Procedure</b>"), "fieldname": "procedure_id",
"fieldtype": "Data", "width": 150},
{"label": _("<b>Steps</b>"), "fieldname": "steps_id",
"fieldtype": "Data", "width": 150},
{"label": _("<b>Language</b>"), "fieldname": "language",
"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()
def variant(doctype,txt,searchfield,start,page_len,filters):
model = filters.get('name')
variant = frappe.db.sql("""select name from `tabVariant` where name like %s""",model+'%',as_list=True)
return variant
def variant(doctype, txt, searchfield, start, page_len, filters):
model = filters.get('name')
variant = frappe.db.sql(
"""select name from `tabVariant` where name like %s""", model+'%', as_list=True)
return variant

496
smart_service/apis/app_user_login.py

@ -32,18 +32,16 @@ def custom_rate_limit(limit, seconds):
return 1
# Temporary Login
@frappe.whitelist(allow_guest=True)
def app_user_validation_test():
dicData = {}
try:
doc = frappe.get_doc("Fish", None)
dicData['token'] = doc.apple
dicData['status'] = 1
except:
return {'status': 0, 'error': 'Site Error'}
return dicData
# @frappe.whitelist(allow_guest=True)
# def app_user_validation_test():
# dicData = {}
# try:
# doc = frappe.get_doc("Fish", None)
# dicData['token'] = doc.apple
# dicData['status'] = 1
# except:
# return {'status': 0, 'error': 'Site Error'}
# return dicData
@frappe.whitelist(allow_guest=True)
@ -60,13 +58,12 @@ def app_user_validation(usr=None, pwd=None):
technician_login = preference.technician_login_api
# ISmartAuth API - Email available
try:
data = {'LoginID': usr, 'Password': pwd}
headers = {"Content-Type": "application/x-www-form-urlencoded"}
if technician_login == 1 and mahindra_login == 0:
response = requests.post(
"http://www.mahindramile.com/ISmartAuth/Service.asmx/ValidateCredential", data=data, headers=headers)
"https://www.mahindramile.com/ISmartAuth/Service.asmx/ValidateCredential", data=data, headers=headers)
decoded = response.content.decode('utf-8')
if len(decoded) > 165:
@ -85,7 +82,7 @@ def app_user_validation(usr=None, pwd=None):
return {'status': 0, 'error': 'Invalid Credentials'}
elif technician_login == 0 and mahindra_login == 1:
response1 = requests.post("http://www.mahindramile.com/WindowAuth/Service.asmx/ValidateCredential",
response1 = requests.post("https://www.mahindramile.com/WindowAuth/Service.asmx/ValidateCredential",
data=data, headers=headers)
decoded1 = response1.content.decode('utf-8')
node = ET.fromstring(decoded1)
@ -131,10 +128,10 @@ def app_user_validation(usr=None, pwd=None):
elif technician_login == 1 and mahindra_login == 1:
response = requests.post(
"http://www.mahindramile.com/ISmartAuth/Service.asmx/ValidateCredential", data=data, headers=headers)
"https://www.mahindramile.com/ISmartAuth/Service.asmx/ValidateCredential", data=data, headers=headers)
decoded = response.content.decode('utf-8')
response1 = requests.post("http://www.mahindramile.com/WindowAuth/Service.asmx/ValidateCredential",
response1 = requests.post("https://www.mahindramile.com/WindowAuth/Service.asmx/ValidateCredential",
data=data, headers=headers)
decoded1 = response1.content.decode('utf-8')
node = ET.fromstring(decoded1)
@ -218,7 +215,6 @@ def grant_user_access(userdata=None, iid=None):
area_name = userdata['AreaName']
zone = userdata['Zone']
dealer_code = userdata['Code']
dealer_name = userdata['DealerName']
app_current_version = userdata['AppCurrentVersion']
@ -234,9 +230,7 @@ def grant_user_access(userdata=None, iid=None):
frappe.set_user("Administrator")
user_name = frappe.db.sql('''SELECT name FROM {0}.tabUser where email='{1}';'''.format(
current_db_name, email), as_dict=1)
# return user_name
if user_name:
# token = generate_keys(user_name[0]['name'])
try:
""" New Refresh token update """
access_token = generate_access_token(user_name[0]['name'])
@ -259,7 +253,6 @@ def grant_user_access(userdata=None, iid=None):
user_name = frappe.db.sql('''SELECT name FROM {0}.tabUser where email='{1}';'''.format(
current_db_name, email), as_dict=1)
if user_name:
# token = generate_keys(user_name[0]['name'])
try:
""" New Refresh token update """
access_token = generate_access_token(user_name[0]['name'])
@ -306,16 +299,6 @@ def grant_user_access(userdata=None, iid=None):
'''Inserting Device data'''
if iid == 'None' or iid == 'null':
app_device = frappe.new_doc('App Device')
app_device.device_id = device_id
app_device.publish_type = "Global"
app_device.device_type = device_type
app_device.os = os
app_device.os_version = os_version
app_device.app_current_version = app_current_version
app_device.last_login = now()
app_device.insert()
if frappe.db.exists({'doctype': 'App Device', 'device_id': device_id}):
frappe.db.sql(
'''UPDATE {2}.`tabApp Device` SET active_status= "{1}" where device_id = "{0}";'''.format(device_id,
@ -328,21 +311,27 @@ def grant_user_access(userdata=None, iid=None):
app_device1 = frappe.get_last_doc(
'App Device', filters={"device_id": device_id})
app_device = frappe.new_doc('App Device')
app_device.device_id = device_id
app_device.publish_type = "Global"
app_device.device_type = device_type
app_device.os = os
app_device.os_version = os_version
app_device.app_current_version = app_current_version
app_device.last_login = now()
app_device.insert()
app_logs = frappe.new_doc('App Log')
app_logs.user = app_user1.name
app_logs.device = app_device.name
app_logs.type = 'Reinstalled'
app_logs.latitude = latitude
app_logs.longitude = longitude
# app_logs.active_status = 'Active'
app_logs.date_time_stamp = now()
app_logs.insert()
app_device_tmp = frappe.get_last_doc(
'App Device', filters={"device_id": device_id})
frappe.db.sql('''UPDATE {2}.`tabApp Device` SET active_status= "{1}" where name = "{0}";'''.format(
app_device_tmp.name, "Active", current_db_name))
frappe.db.commit()
app_logs3 = frappe.new_doc('App Log')
app_logs3.user = app_user1.name
@ -354,6 +343,16 @@ def grant_user_access(userdata=None, iid=None):
app_logs3.insert()
else:
app_device = frappe.new_doc('App Device')
app_device.device_id = device_id
app_device.publish_type = "Global"
app_device.device_type = device_type
app_device.os = os
app_device.os_version = os_version
app_device.app_current_version = app_current_version
app_device.last_login = now()
app_device.insert()
app_user1 = frappe.get_last_doc(
'App Users', filters={"email_id": email})
app_device1 = frappe.get_last_doc(
@ -362,7 +361,6 @@ def grant_user_access(userdata=None, iid=None):
app_logs.user = app_user1.name
app_logs.device = app_device.name
app_logs.type = 'Installed'
# app_logs.active_status = 'Active'
app_logs.latitude = latitude
app_logs.longitude = longitude
app_logs.date_time_stamp = now()
@ -378,9 +376,6 @@ def grant_user_access(userdata=None, iid=None):
app_logs4.save()
else:
# frappe.db.sql(
# '''UPDATE {4}.`tabApp Device` set last_login= '{0}', user_name = '{2}', device_type = '{3}' where name = "{1}";'''.format(
# now(), iid, email, user_type_desc, current_db_name))
frappe.db.sql(
'''UPDATE {3}.`tabApp Device` set last_login= '{0}', device_type = '{2}' where name = "{1}";'''.format(
now(), iid, device_type, current_db_name))
@ -406,7 +401,6 @@ def grant_user_access(userdata=None, iid=None):
user_details = {}
user_details['Installation ID'] = lst[0][0]
user_details['User ID'] = lst1[0][0]
# user_details['token'] = token
user_details['status'] = 1
user_details['token_details'] = token_details
return user_details
@ -416,16 +410,178 @@ def grant_user_access(userdata=None, iid=None):
@frappe.whitelist(allow_guest=True)
def new_grant_user_access(userdata=None, iid=None):
def data_invalidation(email, device_id, iid=None):
rate_res = custom_rate_limit(limit=5, seconds=15)
if rate_res != 1:
return rate_res
val = input_validation(userdata=userdata, iid=iid)
try:
# User validation
frappe.set_user("Administrator")
user_name = frappe.db.sql('''SELECT name FROM {0}.tabUser where email='{1}';'''.format(
current_db_name, email), as_dict=1)
token_details = []
if user_name:
""" New Refresh token update """
access_token = generate_access_token(user_name[0]['name'])
refresh_token = generate_refresh_token()
token_details = update_tokens_in_doc(
user_name[0]['name'], access_token, refresh_token)
return {'status': 1, 'data': token_details, 'error': None}
except Exception as e1:
return {'status': 0, 'data': [], 'error': 'Failed to verify user'}
@frappe.whitelist(allow_guest=True)
def new_app_user_validation(usr=None, pwd=None, iid=None, device_data=None):
rate_res = custom_rate_limit(limit=5, seconds=15)
if rate_res != 1:
return rate_res
val = input_validation(usr=usr, pwd=pwd, iid=iid, device_data=device_data)
if val != '':
return {'status': 0, 'error': "Parameter's missing: " + val}
preference = frappe.get_last_doc('App Preference')
mahindra_login = preference.mahindra_login_api
technician_login = preference.technician_login_api
# ISmartAuth API - Email available
device_data = json.loads(device_data)
try:
data = {'LoginID': usr, 'Password': pwd}
headers = {"Content-Type": "application/x-www-form-urlencoded"}
if technician_login == 1 and mahindra_login == 0:
response = requests.post(
"https://www.mahindramile.com/ISmartAuth/Service.asmx/ValidateCredential", data=data, headers=headers)
decoded = response.content.decode('utf-8')
if len(decoded) > 165:
frappe.set_user("Administrator")
da = re.search("{", decoded)
da1 = re.search("}", decoded)
trunData = decoded[da.span()[0]:da1.span()[1]]
dicData = json.loads(trunData)
if dicData['ID'] == "":
dicData['ID'] = "100"
dicData.update(device_data)
return new_grant_user_access(dicData, iid)
else:
return {'status': 0, 'error': 'Invalid Credentials'}
elif technician_login == 0 and mahindra_login == 1:
response1 = requests.post("https://www.mahindramile.com/WindowAuth/Service.asmx/ValidateCredential",
data=data, headers=headers)
decoded1 = response1.content.decode('utf-8')
node = ET.fromstring(decoded1)
dictValue = xml_to_dict(node)
frappe.set_user("Administrator")
dicData = {
"ID": "{}@email.com".format(usr),
"LoginName": usr,
"FirstName": usr,
"LastName": "",
"IsActive": "True",
"UserType": "",
"SkillID": "",
"SkillName": "",
"UserTypeDesc": "",
"PasswordChanged": "",
"AreaName": "",
"Zone": "",
"Code": "",
"LocationName": "",
"ChannelNo": "",
"ServerDate": "",
"ServerTime": "",
"DealerName": "",
"EmailId": "{}@email.com".format(usr),
"isLDAPAuthenticated": ""}
dicData.update(device_data)
msgDic = {}
try:
msgDic['UserName'] = dictValue['children']['UserName']['text']
msgDic['IsSuccessfull'] = dictValue['children']['IsSuccessfull']['text']
if dicData['ID'] == "":
dicData['ID'] = "100"
return new_grant_user_access(dicData, iid)
except:
msgDic['IsSuccessfull'] = node.text
return {'status': 0, 'error': 'Invalid Credentials'}
elif technician_login == 1 and mahindra_login == 1:
response = requests.post(
"https://www.mahindramile.com/ISmartAuth/Service.asmx/ValidateCredential", data=data, headers=headers)
decoded = response.content.decode('utf-8')
response1 = requests.post("https://www.mahindramile.com/WindowAuth/Service.asmx/ValidateCredential",
data=data, headers=headers)
decoded1 = response1.content.decode('utf-8')
node = ET.fromstring(decoded1)
dictValue = xml_to_dict(node)
dicData = {
"ID": "",
"LoginName": usr,
"FirstName": usr,
"LastName": "",
"IsActive": "True",
"UserType": "",
"SkillID": "",
"SkillName": "",
"UserTypeDesc": "Mahindra User",
"PasswordChanged": "",
"AreaName": "Mahindra",
"Zone": "Mahindra",
"LocationName": "Mahindra",
"ChannelNo": "",
"ServerDate": "",
"ServerTime": "",
"DealerName": "Mahindra",
"EmailId": "{}@mahindra.com".format(usr),
"isLDAPAuthenticated": ""}
msgDic = {}
if len(decoded) > 165:
frappe.set_user("Administrator")
da = re.search("{", decoded)
da1 = re.search("}", decoded)
trunData = decoded[da.span()[0]:da1.span()[1]]
dicData = json.loads(trunData)
dicData['Code'] = ""
if dicData['ID'] == "":
dicData['ID'] = "100"
dicData.update(device_data)
return new_grant_user_access(dicData, iid)
else:
frappe.set_user("Administrator")
msgDic['UserName'] = dictValue['children']['UserName']['text']
msgDic['IsSuccessfull'] = dictValue['children']['IsSuccessfull']['text']
if dicData['ID'] == "":
dicData['ID'] = "100"
dicData['Code'] = ''
dicData.update(device_data)
return new_grant_user_access(dicData, iid)
else:
return {'status': 0, 'error': 'Login Blocked'}
except:
return {'status': 0, 'error': 'Site Error'}
def new_grant_user_access(userdata=None, iid=None):
rate_res = custom_rate_limit(limit=5, seconds=15)
if rate_res != 1:
return rate_res
try:
userdata = json.loads(userdata)
user_id = userdata['ID']
email = userdata['EmailId']
first_name = userdata['FirstName']
@ -456,17 +612,15 @@ def new_grant_user_access(userdata=None, iid=None):
frappe.set_user("Administrator")
user_name = frappe.db.sql('''SELECT name FROM {0}.tabUser where email='{1}';'''.format(
current_db_name, email), as_dict=1)
# return user_name
if user_name:
# token = generate_keys(user_name[0]['name'])
try:
""" New Refresh token update """
access_token = generate_access_token(user_name[0]['name'])
refresh_token = generate_refresh_token()
token_details = update_tokens_in_doc(
user_name[0]['name'], access_token, refresh_token)
except:
return {'status': 0, 'error': "Failed to Create token"}
token = generate_keys(user_name[0]['name'])
""" New Refresh token update """
access_token = generate_access_token(user_name[0]['name'])
refresh_token = generate_refresh_token()
token_details = update_tokens_in_doc(
user_name[0]['name'], access_token, refresh_token)
else:
user = frappe.new_doc('User')
@ -481,15 +635,13 @@ def new_grant_user_access(userdata=None, iid=None):
user_name = frappe.db.sql('''SELECT name FROM {0}.tabUser where email='{1}';'''.format(
current_db_name, email), as_dict=1)
if user_name:
# token = generate_keys(user_name[0]['name'])
try:
""" New Refresh token update """
access_token = generate_access_token(user_name[0]['name'])
refresh_token = generate_refresh_token()
token_details = update_tokens_in_doc(
user_name[0]['name'], access_token, refresh_token)
except:
return {'status': 0, 'error': "Failed to Create token"}
token = generate_keys(user_name[0]['name'])
""" New Refresh token update """
access_token = generate_access_token(user_name[0]['name'])
refresh_token = generate_refresh_token()
token_details = update_tokens_in_doc(
user_name[0]['name'], access_token, refresh_token)
'''Inserting Dealer Data'''
if frappe.db.exists({'doctype': 'App Dealer', 'dealer_code': dealer_code}):
@ -528,16 +680,6 @@ def new_grant_user_access(userdata=None, iid=None):
'''Inserting Device data'''
if iid == 'None' or iid == 'null':
app_device = frappe.new_doc('App Device')
app_device.device_id = device_id
app_device.publish_type = "Global"
app_device.device_type = device_type
app_device.os = os
app_device.os_version = os_version
app_device.app_current_version = app_current_version
app_device.last_login = now()
app_device.insert()
if frappe.db.exists({'doctype': 'App Device', 'device_id': device_id}):
frappe.db.sql(
'''UPDATE {2}.`tabApp Device` SET active_status= "{1}" where device_id = "{0}";'''.format(device_id,
@ -549,6 +691,15 @@ def new_grant_user_access(userdata=None, iid=None):
'App Users', filters={"email_id": email})
app_device1 = frappe.get_last_doc(
'App Device', filters={"device_id": device_id})
app_device = frappe.new_doc('App Device')
app_device.device_id = device_id
app_device.publish_type = "Global"
app_device.device_type = device_type
app_device.os = os
app_device.os_version = os_version
app_device.app_current_version = app_current_version
app_device.last_login = now()
app_device.insert()
app_logs = frappe.new_doc('App Log')
app_logs.user = app_user1.name
@ -556,16 +707,9 @@ def new_grant_user_access(userdata=None, iid=None):
app_logs.type = 'Reinstalled'
app_logs.latitude = latitude
app_logs.longitude = longitude
# app_logs.active_status = 'Active'
app_logs.date_time_stamp = now()
app_logs.insert()
app_device_tmp = frappe.get_last_doc(
'App Device', filters={"device_id": device_id})
frappe.db.sql('''UPDATE {2}.`tabApp Device` SET active_status= "{1}" where name = "{0}";'''.format(
app_device_tmp.name, "Active", current_db_name))
frappe.db.commit()
app_logs3 = frappe.new_doc('App Log')
app_logs3.user = app_user1.name
app_logs3.device = app_device.name
@ -576,6 +720,16 @@ def new_grant_user_access(userdata=None, iid=None):
app_logs3.insert()
else:
app_device = frappe.new_doc('App Device')
app_device.device_id = device_id
app_device.publish_type = "Global"
app_device.device_type = device_type
app_device.os = os
app_device.os_version = os_version
app_device.app_current_version = app_current_version
app_device.last_login = now()
app_device.insert()
app_user1 = frappe.get_last_doc(
'App Users', filters={"email_id": email})
app_device1 = frappe.get_last_doc(
@ -584,7 +738,6 @@ def new_grant_user_access(userdata=None, iid=None):
app_logs.user = app_user1.name
app_logs.device = app_device.name
app_logs.type = 'Installed'
# app_logs.active_status = 'Active'
app_logs.latitude = latitude
app_logs.longitude = longitude
app_logs.date_time_stamp = now()
@ -600,9 +753,6 @@ def new_grant_user_access(userdata=None, iid=None):
app_logs4.save()
else:
# frappe.db.sql(
# '''UPDATE {4}.`tabApp Device` set last_login= '{0}', user_name = '{2}', device_type = '{3}' where name = "{1}";'''.format(
# now(), iid, email, user_type_desc, current_db_name))
frappe.db.sql(
'''UPDATE {3}.`tabApp Device` set last_login= '{0}', device_type = '{2}' where name = "{1}";'''.format(
now(), iid, device_type, current_db_name))
@ -628,155 +778,12 @@ def new_grant_user_access(userdata=None, iid=None):
user_details = {}
user_details['Installation ID'] = lst[0][0]
user_details['User ID'] = lst1[0][0]
# user_details['token'] = token
user_details['status'] = 1
user_details['token_details'] = token_details
user_details['token'] = token
return user_details
except Exception as e1:
return {'status': 0, 'error': "Invalid Inputs"}
@frappe.whitelist(allow_guest=True)
def new_app_user_validation(usr=None, pwd=None, iid=None, device_data=None):
rate_res = custom_rate_limit(limit=5, seconds=15)
if rate_res != 1:
return rate_res
val = input_validation(usr=usr, pwd=pwd, iid=iid, device_data=device_data)
if val != '':
return {'status': 0, 'error': "Parameter's missing: " + val}
preference = frappe.get_last_doc('App Preference')
mahindra_login = preference.mahindra_login_api
technician_login = preference.technician_login_api
return {'status': 0, 'error': 'Failed to verify user'}
# ISmartAuth API - Email available
device_data = json.loads(device_data)
try:
data = {'LoginID': usr, 'Password': pwd}
headers = {"Content-Type": "application/x-www-form-urlencoded"}
if technician_login == 1 and mahindra_login == 0:
response = requests.post(
"http://www.mahindramile.com/ISmartAuth/Service.asmx/ValidateCredential", data=data, headers=headers)
decoded = response.content.decode('utf-8')
if len(decoded) > 165:
frappe.set_user("Administrator")
da = re.search("{", decoded)
da1 = re.search("}", decoded)
trunData = decoded[da.span()[0]:da1.span()[1]]
dicData = json.loads(trunData)
if dicData['ID'] == "":
dicData['ID'] = "100"
dicData.update(device_data)
return new_grant_user_access(dicData, iid)
else:
return {'status': 0, 'error': 'Invalid Credentials'}
elif technician_login == 0 and mahindra_login == 1:
response1 = requests.post("http://www.mahindramile.com/WindowAuth/Service.asmx/ValidateCredential",
data=data, headers=headers)
decoded1 = response1.content.decode('utf-8')
node = ET.fromstring(decoded1)
dictValue = xml_to_dict(node)
frappe.set_user("Administrator")
dicData = {
"ID": "{}@email.com".format(usr),
"LoginName": usr,
"FirstName": usr,
"LastName": "",
"IsActive": "True",
"UserType": "",
"SkillID": "",
"SkillName": "",
"UserTypeDesc": "",
"PasswordChanged": "",
"AreaName": "",
"Zone": "",
"Code": "",
"LocationName": "",
"ChannelNo": "",
"ServerDate": "",
"ServerTime": "",
"DealerName": "",
"EmailId": "{}@email.com".format(usr),
"isLDAPAuthenticated": ""}
dicData.update(device_data)
msgDic = {}
try:
msgDic['UserName'] = dictValue['children']['UserName']['text']
msgDic['IsSuccessfull'] = dictValue['children']['IsSuccessfull']['text']
if dicData['ID'] == "":
dicData['ID'] = "100"
return new_grant_user_access(dicData, iid)
except:
msgDic['IsSuccessfull'] = node.text
return {'status': 0, 'error': 'Invalid Credentials'}
elif technician_login == 1 and mahindra_login == 1:
response = requests.post(
"http://www.mahindramile.com/ISmartAuth/Service.asmx/ValidateCredential", data=data, headers=headers)
decoded = response.content.decode('utf-8')
response1 = requests.post("http://www.mahindramile.com/WindowAuth/Service.asmx/ValidateCredential",
data=data, headers=headers)
decoded1 = response1.content.decode('utf-8')
node = ET.fromstring(decoded1)
dictValue = xml_to_dict(node)
dicData = {
"ID": "",
"LoginName": usr,
"FirstName": usr,
"LastName": "",
"IsActive": "True",
"UserType": "",
"SkillID": "",
"SkillName": "",
"UserTypeDesc": "Mahindra User",
"PasswordChanged": "",
"AreaName": "Mahindra",
"Zone": "Mahindra",
"LocationName": "Mahindra",
"ChannelNo": "",
"ServerDate": "",
"ServerTime": "",
"DealerName": "Mahindra",
"EmailId": "{}@mahindra.com".format(usr),
"isLDAPAuthenticated": ""}
msgDic = {}
if len(decoded) > 165:
frappe.set_user("Administrator")
da = re.search("{", decoded)
da1 = re.search("}", decoded)
trunData = decoded[da.span()[0]:da1.span()[1]]
dicData = json.loads(trunData)
dicData['Code'] = ""
if dicData['ID'] == "":
dicData['ID'] = "100"
dicData.update(device_data)
return new_grant_user_access(dicData, iid)
else:
frappe.set_user("Administrator")
msgDic['UserName'] = dictValue['children']['UserName']['text']
msgDic['IsSuccessfull'] = dictValue['children']['IsSuccessfull']['text']
if dicData['ID'] == "":
dicData['ID'] = "100"
dicData['Code'] = ''
dicData.update(device_data)
return new_grant_user_access(dicData, iid)
else:
return {'status': 0, 'error': 'Login Blocked'}
except:
return {'status': 0, 'error': 'Site Error'}
@frappe.whitelist(allow_guest=1)
def generate_keys(user_name):
@ -796,30 +803,27 @@ def generate_keys(user_name):
return token
@frappe.whitelist()
def login_generate_token(doc=None, method=None):
rate_res = custom_rate_limit(limit=5, seconds=15)
if rate_res != 1:
return rate_res
new_tok = generate_keys('cms@guidedsmartservice.com')
water = frappe.get_doc("Fish", None)
water.apple = new_tok
water.save()
return water.apple
# @frappe.whitelist()
# def login_generate_token(doc=None, method=None):
# rate_res = custom_rate_limit(limit=5, seconds=15)
# if rate_res != 1:
# return rate_res
# new_tok = generate_keys('cms@guidedsmartservice.com')
# water = frappe.get_doc("Fish", None)
# water.apple = new_tok
# water.save()
# return water.apple
def input_validation(**kwargs):
sts = ""
i = 0
for key, value in kwargs.items():
# frappe.log_error("key"+str(key))
# frappe.log_error("value"+str(value))
if value is None or value == "" or value == '':
if value is None or value == "":
if i != 0:
sts += ','
sts += str(key) + ""
i += 1
# frappe.log_error(sts)
return sts
@ -893,9 +897,7 @@ def refresh_token():
refresh_token = generate_refresh_token()
token_details = update_tokens_in_doc(
d['user'], access_token, refresh_token)
# token_details['status'] = 1
return {'status': 1, 'token_details': token_details}
# return token_details
return {'status': 0, "error": 'Invalid token'}
@ -958,8 +960,6 @@ def deactivate_account(refresh_token):
def update_tokens_in_doc(user_email, access, refresh):
# access_exp_hours = 15 * 60
# refresh_exp_hrs = 60 * 60 * 24
token_settings = frappe.get_doc('Token Settings')
access_exp_hours = token_settings.access_expiry_time
@ -982,9 +982,6 @@ def update_tokens_in_doc(user_email, access, refresh):
refresh_doc.access_token = encrypt(access)
refresh_doc.refresh_token = encrypt(refresh)
# access_exp_time = datetime.now() + timedelta(seconds=access_exp_hours)
# refresh_exp_time = datetime.now() + timedelta(seconds=refresh_exp_hrs)
access_exp_time = datetime.now() + timedelta(minutes=access_exp_hours)
refresh_exp_time = datetime.now() + timedelta(hours=refresh_exp_hrs)
@ -1060,3 +1057,4 @@ def deactivate_tokens():
except Exception as e:
return e

86
smart_service/masters/report/drive_translation/drive_translation.py

@ -5,62 +5,68 @@
from __future__ import unicode_literals
import frappe
from frappe.utils import cstr, cint, getdate
from frappe.utils import cstr
from frappe import msgprint, _
current_db_name = frappe.conf.get("db_name")
def execute(filters=None):
columns, data = [], []
columns,lang = get_columns()
data = get_data()
return columns, data
columns, data = [], []
columns, lang = get_columns()
data = get_data()
return columns, data
def get_data():
custom_lang = frappe.db.sql("""SELECT lang_code FROM %s.`tabCustom Languages` where lang_code <> "en" order by lang_name"""%(current_db_name),as_list=True)
queryAppendLang = ""
for d in custom_lang:
q = ", (CASE WHEN tabLang.languageCode = '%s' THEN %s.tabTranslation.translated_text ELSE null END) as %s" %(d[0],current_db_name,d[0])
queryAppendLang += q
custom_lang = frappe.db.sql(
"""SELECT lang_code FROM `tabCustom Languages` where lang_code <> "en" order by lang_name;""", as_list=1)
queryAppendLang = ""
for d in custom_lang:
q = ", (CASE WHEN tabLang.languageCode = '%s' THEN tabTranslation.translated_text ELSE null END) as %s" % (
d[0], d[0])
queryAppendLang += q
sel = ""
for d in custom_lang:
r = ",tabTranslation.%s as %s"%(d[0],d[0])
sel+= r
sel = ""
for d in custom_lang:
r = ",tabTranslation.%s as %s" % (d[0], d[0])
sel += r
actualQuery = """Select
actualQuery = """Select
`tabDrive`.modified as "Modified On",
`tabDrive`.active_status as "Status",
`tabDrive`.drive as 'Drive'
%s
From %s.`tabDrive`
LEFT JOIN %s.`tabTranslation` as tabTrans
ON %s.`tabDrive`.drive = tabTrans.source_text
From `tabDrive`
LEFT JOIN `tabTranslation` as tabTrans
ON `tabDrive`.drive = tabTrans.source_text
LEFT JOIN (Select tabLang.languageCode as languageCode
,%s.tabTranslation.source_text as sourceText
, %s.tabTranslation.translated_text as translated_text
,tabTranslation.source_text as sourceText
,tabTranslation.translated_text as translated_text
%s
From %s.tabTranslation
From tabTranslation
INNER JOIN (SELECT tanLang.language_name as language_name
, tanLang.language_code as languageCode
FROM %s.tabLanguage as tanLang) as tabLang
ON %s.tabTranslation.language = tabLang.languageCode) as tabTranslation
ON %s.`tabDrive`.drive = tabTranslation.sourceText;""" % (sel,current_db_name,current_db_name,current_db_name,current_db_name,current_db_name,queryAppendLang,current_db_name,current_db_name,current_db_name,current_db_name)
FROM tabLanguage as tanLang) as tabLang
ON tabTranslation.language = tabLang.languageCode) as tabTranslation
ON `tabDrive`.drive = tabTranslation.sourceText
ORDER BY `tabDrive`.modified DESC;""" % (sel, queryAppendLang)
data = frappe.db.sql(actualQuery, as_list=True)
return data
data = frappe.db.sql(actualQuery,as_list=True)
return data
def get_columns():
columns = []
columns += [
_("<b>Modified On</b>") + ":Datetime/:200", _("<b>Status</b>") + ":Data/:100",_("<b>Drive</b>") + ":Data/:220",
]
lang = []
custom_lang = frappe.db.sql("""SELECT lang_code,lang_name,active_status FROM %s.`tabCustom Languages` where lang_code <> "en" order by lang_name"""%(current_db_name),as_dict=1)
for d in custom_lang:
lang.append("<b>"+cstr(d["lang_name"])+"</b>"+ "::220")
columns += lang
return columns,lang
columns = []
columns += [
_("<b>Modified On</b>") + ":Datetime/:200", _("<b>Status</b>") +
":Data/:100", _("<b>Drive</b>") + ":Data/:220",
]
lang = []
custom_lang = frappe.db.sql("""SELECT lang_code,lang_name,active_status FROM `tabCustom Languages` where lang_code <> "en"
order by lang_name""", as_dict=1)
for d in custom_lang:
lang.append("<b>"+cstr(d["lang_name"])+"</b>" + "::220")
columns += lang
return columns, lang

66
smart_service/masters/report/fuel_translation/fuel_translation.py

@ -5,31 +5,34 @@
from __future__ import unicode_literals
import frappe
from frappe.utils import cstr, cint, getdate
from frappe.utils import cstr
from frappe import msgprint, _
def execute(filters=None):
columns, data = [], []
columns,lang = get_columns()
data = get_data()
return columns, data
columns, data = [], []
columns, lang = get_columns()
data = get_data()
return columns, data
def get_data():
custom_lang = frappe.db.sql("""SELECT lang_code FROM `tabCustom Languages` where lang_code <> "en" order by lang_name""",as_list=True)
custom_lang = frappe.db.sql(
"""SELECT lang_code FROM `tabCustom Languages` where lang_code <> "en" order by lang_name""", as_list=1)
queryAppendLang = ""
for d in custom_lang:
q = ", (CASE WHEN tabLang.languageCode = '%s' THEN tabTranslation.translated_text ELSE null END) as %s" %(d[0],d[0])
queryAppendLang += q
queryAppendLang = ""
for d in custom_lang:
q = ", (CASE WHEN tabLang.languageCode = '%s' THEN tabTranslation.translated_text ELSE null END) as %s" % (
d[0], d[0])
queryAppendLang += q
sel = ""
for d in custom_lang:
r = ",tabTranslation.%s as %s"%(d[0],d[0])
sel+= r
sel = ""
for d in custom_lang:
r = ",tabTranslation.%s as %s" % (d[0], d[0])
sel += r
actualQuery = """Select
actualQuery = """Select
`tabFuel`.modified as "Modified On",
`tabFuel`.active_status as "Status",
`tabFuel`.fuel as 'Fuel'
@ -46,24 +49,25 @@ def get_data():
, tanLang.language_code as languageCode
FROM tabLanguage as tanLang) as tabLang
ON tabTranslation.language = tabLang.languageCode) as tabTranslation
ON `tabFuel`.fuel = tabTranslation.sourceText;""" % (sel ,queryAppendLang)
ON `tabFuel`.fuel = tabTranslation.sourceText ORDER BY `tabFuel`.modified DESC;""" % (sel, queryAppendLang)
data = frappe.db.sql(actualQuery, as_list=True)
data = frappe.db.sql(actualQuery,as_list=True)
return data
return data
def get_columns():
current_db_name = frappe.conf.get("db_name")
current_db_name = frappe.conf.get("db_name")
columns = []
columns += [
_("<b>Modified On</b>") + ":Datetime/:200", _("<b>Status</b>") + ":Data/:100",_("<b>Fuel</b>") + ":Data/:220",
]
lang = []
custom_lang = frappe.db.sql("""SELECT lang_code,lang_name,active_status FROM {}.`tabCustom Languages` where lang_code <> "en" order by lang_name """.format(current_db_name),as_dict=1)
for d in custom_lang:
lang.append("<b>"+cstr(d["lang_name"])+"</b>"+ "::220")
columns += lang
return columns,lang
columns = []
columns += [
_("<b>Modified On</b>") + ":Datetime/:200", _("<b>Status</b>") +
":Data/:100", _("<b>Fuel</b>") + ":Data/:220",
]
lang = []
custom_lang = frappe.db.sql("""SELECT lang_code,lang_name,active_status FROM `tabCustom Languages` where lang_code <> "en"
order by lang_name; """, as_dict=1)
for d in custom_lang:
lang.append("<b>"+cstr(d["lang_name"])+"</b>" + "::220")
columns += lang
return columns, lang

98
smart_service/masters/report/sub_systems_translation/sub_systems_translation.py

@ -5,66 +5,70 @@
from __future__ import unicode_literals
import frappe
from frappe.utils import cstr, cint, getdate
from frappe.utils import cstr
from frappe import msgprint, _
current_db_name = frappe.conf.get("db_name")
def execute(filters=None):
columns, data = [], []
columns,lang = get_columns()
data = get_data()
return columns, data
columns, data = [], []
columns, lang = get_columns()
data = get_data()
return columns, data
def get_data():
custom_lang = frappe.db.sql("""SELECT lang_code FROM {}.`tabCustom Languages` where lang_code <> "en" order by lang_name""".format(current_db_name),as_list=True)
queryAppendLang = ""
for d in custom_lang:
q = ", (CASE WHEN tabLang.languageCode = '%s' THEN %s.tabTranslation.translated_text ELSE null END) as %s" %(d[0],current_db_name,d[0])
queryAppendLang += q
sel = ""
for d in custom_lang:
r = ",tabTranslation.%s as %s"%(d[0],d[0])
sel+= r
custom_lang = frappe.db.sql(
"""SELECT lang_code FROM `tabCustom Languages` where lang_code <> "en" order by lang_name;""", as_list=1)
actualQuery = """Select
{0}.`tabSub Systems`.modified as "Modified On",
{0}.`tabSub Systems`.active_status as "Status",
{0}.`tabSub Systems`.sub_system_name as 'Vehicle Segment'
{1}
From {0}.`tabSub Systems`
LEFT JOIN {0}.`tabTranslation` as tabTrans
ON {0}.`tabSub Systems`.sub_system_name = tabTrans.source_text
queryAppendLang = ""
for d in custom_lang:
q = ", (CASE WHEN tabLang.languageCode = '%s' THEN tabTranslation.translated_text ELSE null END) as %s" % (
d[0], d[0])
queryAppendLang += q
sel = ""
for d in custom_lang:
r = ",tabTranslation.%s as %s" % (d[0], d[0])
sel += r
actualQuery = """Select
`tabSub Systems`.modified as "Modified On",
`tabSub Systems`.active_status as "Status",
`tabSub Systems`.sub_system_name as 'Vehicle Segment'
{0}
From `tabSub Systems`
LEFT JOIN `tabTranslation` as tabTrans
ON `tabSub Systems`.sub_system_name = tabTrans.source_text
LEFT JOIN (Select tabLang.languageCode as languageCode
,{0}.tabTranslation.source_text as sourceText
, {0}.tabTranslation.translated_text as translated_text
{2}
From {0}.tabTranslation
,tabTranslation.source_text as sourceText
, tabTranslation.translated_text as translated_text
{1}
From tabTranslation
INNER JOIN (SELECT tanLang.language_name as language_name
, tanLang.language_code as languageCode
FROM {0}.tabLanguage as tanLang) as tabLang
ON {0}.tabTranslation.language = tabLang.languageCode) as tabTranslation
ON {0}.`tabSub Systems`.sub_system_name = tabTranslation.sourceText;""" .format(current_db_name,sel ,queryAppendLang)
FROM tabLanguage as tanLang) as tabLang
ON tabTranslation.language = tabLang.languageCode) as tabTranslation
ON `tabSub Systems`.sub_system_name = tabTranslation.sourceText
ORDER BY `tabSub Systems`.modified DESC;""" .format(sel, queryAppendLang)
data = frappe.db.sql(actualQuery, as_list=True)
return data
data = frappe.db.sql(actualQuery,as_list=True)
return data
def get_columns():
columns = []
columns += [
_("<b>Modified On</b>") + ":Datetime/:200", _("<b>Status</b>") + ":Data/:100",_("<b>Sub Systems</b>") + ":Data/:300",
]
lang = []
custom_lang = frappe.db.sql("""SELECT lang_code,lang_name,active_status FROM {0}.`tabCustom Languages` where lang_code <> "en" order by lang_name""".format(current_db_name),as_dict=1)
for d in custom_lang:
lang.append("<b>"+cstr(d["lang_name"])+"</b>"+ "::300")
columns += lang
return columns,lang
columns = []
columns += [
_("<b>Modified On</b>") + ":Datetime/:200", _("<b>Status</b>") +
":Data/:100", _("<b>Sub Systems</b>") + ":Data/:300",
]
lang = []
custom_lang = frappe.db.sql(
"""SELECT lang_code,lang_name,active_status FROM `tabCustom Languages`
where lang_code <> "en" order by lang_name;""", as_dict=1)
for d in custom_lang:
lang.append("<b>"+cstr(d["lang_name"])+"</b>" + "::300")
columns += lang
return columns, lang

87
smart_service/masters/report/systems_translation/systems_translation.py

@ -5,63 +5,70 @@
from __future__ import unicode_literals
import frappe
from frappe.utils import cstr, cint, getdate
from frappe.utils import cstr
from frappe import msgprint, _
current_db_name = frappe.conf.get("db_name")
# = frappe.conf.get("db_name")
def execute(filters=None):
columns, data = [], []
columns,lang = get_columns()
data = get_data()
return columns, data
columns, data = [], []
columns, lang = get_columns()
data = get_data()
return columns, data
def get_data():
custom_lang = frappe.db.sql("""SELECT lang_code FROM %s.`tabCustom Languages` where lang_code <> "en" order by lang_name"""%(current_db_name),as_list=True)
queryAppendLang = ""
for d in custom_lang:
q = ", (CASE WHEN tabLang.languageCode = '%s' THEN %s.tabTranslation.translated_text ELSE null END) as %s" %(d[0],current_db_name,d[0])
queryAppendLang += q
custom_lang = frappe.db.sql("""SELECT lang_code FROM `tabCustom Languages` where lang_code <> "en"
order by lang_name;""", as_list=1)
sel = ""
for d in custom_lang:
r = ",tabTranslation.%s as %s"%(d[0],d[0])
sel+= r
queryAppendLang = ""
for d in custom_lang:
q = ", (CASE WHEN tabLang.languageCode = '%s' THEN tabTranslation.translated_text ELSE null END) as %s" % (
d[0], d[0])
queryAppendLang += q
actualQuery = """Select
sel = ""
for d in custom_lang:
r = ",tabTranslation.%s as %s" % (d[0], d[0])
sel += r
actualQuery = """Select
`tabSystems`.modified as "Modified On",
`tabSystems`.active_status as "Status",
`tabSystems`.system_name as 'Vehicle Segment'
%s
From %s.`tabSystems`
LEFT JOIN %s.`tabTranslation` as tabTrans
ON %s.`tabSystems`.system_name = tabTrans.source_text
From `tabSystems`
LEFT JOIN `tabTranslation` as tabTrans
ON `tabSystems`.system_name = tabTrans.source_text
LEFT JOIN (Select tabLang.languageCode as languageCode
,%s.tabTranslation.source_text as sourceText
, %s.tabTranslation.translated_text as translated_text
,tabTranslation.source_text as sourceText
,tabTranslation.translated_text as translated_text
%s
From %s.tabTranslation
From tabTranslation
INNER JOIN (SELECT tanLang.language_name as language_name
, tanLang.language_code as languageCode
FROM %s.tabLanguage as tanLang) as tabLang
ON %s.tabTranslation.language = tabLang.languageCode) as tabTranslation
ON %s.`tabSystems`.system_name = tabTranslation.sourceText;""" % (sel,current_db_name,current_db_name,current_db_name,current_db_name,current_db_name ,queryAppendLang,current_db_name,current_db_name,current_db_name,current_db_name)
FROM tabLanguage as tanLang) as tabLang
ON tabTranslation.language = tabLang.languageCode) as tabTranslation
ON `tabSystems`.system_name = tabTranslation.sourceText;""" % (sel, queryAppendLang)
data = frappe.db.sql(actualQuery, as_list=True)
return data
data = frappe.db.sql(actualQuery,as_list=True)
return data
def get_columns():
columns = []
columns += [
_("<b>Modified On</b>") + ":Datetime/:200", _("<b>Status</b>") + ":Data/:100",_("<b>Systems</b>") + ":Data/:300",
]
lang = []
custom_lang = frappe.db.sql("""SELECT lang_code,lang_name,active_status FROM %s.`tabCustom Languages` where lang_code <> "en" order by lang_name"""%(current_db_name),as_dict=1)
for d in custom_lang:
lang.append("<b>"+cstr(d["lang_name"])+"</b>"+ "::300")
columns += lang
return columns,lang
columns = []
columns += [
_("<b>Modified On</b>") + ":Datetime/:200", _("<b>Status</b>") +
":Data/:100", _("<b>Systems</b>") + ":Data/:300",
]
lang = []
custom_lang = frappe.db.sql("""SELECT lang_code,lang_name,active_status FROM `tabCustom Languages` where lang_code <> "en"
order by lang_name;""", as_dict=1)
for d in custom_lang:
lang.append("<b>"+cstr(d["lang_name"])+"</b>" + "::300")
columns += lang
return columns, lang

82
smart_service/masters/report/transmission_translation/transmission_translation.py

@ -5,61 +5,67 @@
from __future__ import unicode_literals
import frappe
from frappe.utils import cstr, cint, getdate
from frappe.utils import cstr
from frappe import msgprint, _
current_db_name = frappe.conf.get("db_name")
def execute(filters=None):
columns, data = [], []
columns,lang = get_columns()
data = get_data()
return columns, data
columns, data = [], []
columns, lang = get_columns()
data = get_data()
return columns, data
def get_data():
custom_lang = frappe.db.sql("""SELECT lang_code FROM %s.`tabCustom Languages` where lang_code <> "en" order by lang_name"""%(current_db_name),as_list=True)
queryAppendLang = ""
for d in custom_lang:
q = ", (CASE WHEN tabLang.languageCode = '%s' THEN %s.tabTranslation.translated_text ELSE null END) as %s" %(d[0],current_db_name,d[0])
queryAppendLang += q
custom_lang = frappe.db.sql(
"""SELECT lang_code FROM `tabCustom Languages` where lang_code <> "en" order by lang_name;""", as_list=True)
queryAppendLang = ""
for d in custom_lang:
q = ", (CASE WHEN tabLang.languageCode = '%s' THEN tabTranslation.translated_text ELSE null END) as %s" % (
d[0], d[0])
queryAppendLang += q
sel = ""
for d in custom_lang:
r = ",tabTranslation.%s as %s"%(d[0],d[0])
sel+= r
sel = ""
for d in custom_lang:
r = ",tabTranslation.%s as %s" % (d[0], d[0])
sel += r
actualQuery = """Select
actualQuery = """Select
`tabTransmission`.modified as "Modified On",
`tabTransmission`.active_status as "Status",
`tabTransmission`.transmission as 'Transmission'
%s
From %s.`tabTransmission`
LEFT JOIN %s.`tabTranslation` as tabTrans
ON %s.`tabTransmission`.transmission = tabTrans.source_text
From `tabTransmission`
LEFT JOIN `tabTranslation` as tabTrans
ON `tabTransmission`.transmission = tabTrans.source_text
LEFT JOIN (Select tabLang.languageCode as languageCode
,%s.tabTranslation.source_text as sourceText
, %s.tabTranslation.translated_text as translated_text
,tabTranslation.source_text as sourceText
, tabTranslation.translated_text as translated_text
%s
From %s.tabTranslation
From tabTranslation
INNER JOIN (SELECT tanLang.language_name as language_name
, tanLang.language_code as languageCode
FROM %s.tabLanguage as tanLang) as tabLang
ON %s.tabTranslation.language = tabLang.languageCode) as tabTranslation
ON %s.`tabTransmission`.transmission = tabTranslation.sourceText;""" % (sel,current_db_name,current_db_name,current_db_name,current_db_name,current_db_name ,queryAppendLang,current_db_name,current_db_name,current_db_name,current_db_name)
FROM tabLanguage as tanLang) as tabLang
ON tabTranslation.language = tabLang.languageCode) as tabTranslation
ON `tabTransmission`.transmission = tabTranslation.sourceText
ORDER BY `tabTransmission`.modified DESC;""" % (sel, queryAppendLang)
data = frappe.db.sql(actualQuery, as_list=True)
return data
data = frappe.db.sql(actualQuery,as_list=True)
return data
def get_columns():
columns = []
columns += [
_("<b>Modified On</b>") + ":Datetime/:200", _("<b>Status</b>") + ":Data/:100",_("<b>Transmission</b>") + ":Data/:220",
]
lang = []
custom_lang = frappe.db.sql("""SELECT lang_code,lang_name,active_status FROM %s.`tabCustom Languages` where lang_code <> "en" order by lang_name"""%(current_db_name),as_dict=1)
for d in custom_lang:
lang.append("<b>"+cstr(d["lang_name"])+"</b>"+ "::220")
columns += lang
return columns,lang
columns = []
columns += [
_("<b>Modified On</b>") + ":Datetime/:200", _("<b>Status</b>") +
":Data/:100", _("<b>Transmission</b>") + ":Data/:220",
]
lang = []
custom_lang = frappe.db.sql("""SELECT lang_code,lang_name,active_status FROM `tabCustom Languages` where lang_code <> "en"
order by lang_name;""", as_dict=1)
for d in custom_lang:
lang.append("<b>"+cstr(d["lang_name"])+"</b>" + "::220")
columns += lang
return columns, lang

66
smart_service/masters/report/variant_translation/variant_translation.py

@ -5,35 +5,37 @@
from __future__ import unicode_literals
import frappe
from frappe.utils import cstr, cint, getdate
from frappe.utils import cstr
from frappe import msgprint, _
current_db_name = frappe.conf.get("db_name")
def execute(filters=None):
columns, data = [], []
columns,lang = get_columns()
data = get_data()
return columns, data
columns, data = [], []
columns, lang = get_columns()
data = get_data()
return columns, data
def get_data():
custom_lang = frappe.db.sql("""SELECT lang_code FROM `tabCustom Languages` where lang_code <> "en" order by lang_name""",as_list=True)
queryAppendLang = ""
for d in custom_lang:
q = ", (CASE WHEN tabLang.languageCode = '%s' THEN tabTranslation.translated_text ELSE null END) as %s" %(d[0],d[0])
queryAppendLang += q
custom_lang = frappe.db.sql(
"""SELECT lang_code FROM `tabCustom Languages` where lang_code <> "en" order by lang_name;""", as_list=True)
queryAppendLang = ""
for d in custom_lang:
q = ", (CASE WHEN tabLang.languageCode = '%s' THEN tabTranslation.translated_text ELSE null END) as %s" % (
d[0], d[0])
queryAppendLang += q
sel = ""
for d in custom_lang:
r = ",tabTranslation.%s as %s"%(d[0],d[0])
sel+= r
sel = ""
for d in custom_lang:
r = ",tabTranslation.%s as %s" % (d[0], d[0])
sel += r
actualQuery = """Select
actualQuery = """Select
`tabVariant`.modified as "Modified On",
`tabVariant`.active_status as "Status",
`tabVariant`.vehicle as "Vehicle",
`tabVariant`.variant as 'Variant'
%s
From `tabVariant`
LEFT JOIN `tabTranslation` as tabTrans
@ -47,21 +49,25 @@ def get_data():
, tanLang.language_code as languageCode
FROM tabLanguage as tanLang) as tabLang
ON tabTranslation.language = tabLang.languageCode) as tabTranslation
ON `tabVariant`.variant = tabTranslation.sourceText;""" % (sel ,queryAppendLang)
ON `tabVariant`.variant = tabTranslation.sourceText ORDER BY `tabVariant`.modified DESC;""" % (sel, queryAppendLang)
data = frappe.db.sql(actualQuery,as_list=True)
return data
data = frappe.db.sql(actualQuery, as_list=True)
return data
def get_columns():
columns = []
columns += [
_("<b>Modified On</b>") + ":Data/:240", _("<b>Status</b>") + ":Data/:100", _("<b>Vehicle</b>") + ":Data/:200",_("<b>Variant</b>") + ":Data/:220",
]
lang = []
custom_lang = frappe.db.sql("""SELECT lang_code,lang_name,active_status FROM %s.`tabCustom Languages` where lang_code <> "en" order by lang_name"""%(current_db_name),as_dict=1)
for d in custom_lang:
lang.append("<b>"+cstr(d["lang_name"])+"</b>"+ "::220")
columns += lang
return columns,lang
columns = []
columns += [
_("<b>Modified On</b>") + ":Datetime/:240", _("<b>Status</b>") +
":Data/:100", _("<b>Vehicle</b>") +
":Data/:200", _("<b>Variant</b>") + ":Data/:220",
]
lang = []
custom_lang = frappe.db.sql(
"""SELECT lang_code,lang_name,active_status FROM `tabCustom Languages` where lang_code <> "en"
order by lang_name;""", as_dict=1)
for d in custom_lang:
lang.append("<b>"+cstr(d["lang_name"])+"</b>" + "::220")
columns += lang
return columns, lang

106
smart_service/masters/report/vehicle_segment_translation/vehicle_segment_translation.py

@ -5,67 +5,71 @@
from __future__ import unicode_literals
import frappe
from frappe.utils import cstr, cint, getdate
from frappe.utils import cstr
from frappe import msgprint, _
current_db_name = frappe.conf.get("db_name")
def execute(filters=None):
columns, data = [], []
columns,lang = get_columns()
data = get_data()
return columns, data
def get_data():
def execute(filters=None):
columns, data = [], []
columns, lang = get_columns()
data = get_data()
return columns, data
custom_lang = frappe.db.sql("""SELECT lang_code FROM %s.`tabCustom Languages` where lang_code <> "en" order by lang_name"""%(current_db_name),as_list=True)
queryAppendLang = ""
for d in custom_lang:
q = ", (CASE WHEN tabLang.languageCode = '%s' THEN %s.tabTranslation.translated_text ELSE null END) as %s" %(d[0],current_db_name,d[0])
queryAppendLang += q
def get_data():
try:
custom_lang = frappe.db.sql(
"""SELECT lang_code FROM `tabCustom Languages` where lang_code <> "en" order by lang_name;""", as_list=True)
sel = ""
for d in custom_lang:
r = ",tabTranslation.%s as %s"%(d[0],d[0])
sel+= r
queryAppendLang = ""
for d in custom_lang:
q = ", (CASE WHEN tabLang.languageCode = '%s' THEN tabTranslation.translated_text ELSE null END) as %s" % (
d[0], d[0])
queryAppendLang += q
actualQuery = """Select
`tabVehicle Segment`.modified as "Modified On",
`tabVehicle Segment`.active_status as "Status",
`tabVehicle Segment`.vehicle_segment as 'Vehicle Segment'
%s
From %s.`tabVehicle Segment`
LEFT JOIN %s.`tabTranslation` as tabTrans
ON %s.`tabVehicle Segment`.vehicle_segment = tabTrans.source_text
LEFT JOIN (Select tabLang.languageCode as languageCode
,%s.tabTranslation.source_text as sourceText
, %s.tabTranslation.translated_text as translated_text
%s
From %s.tabTranslation
INNER JOIN (SELECT tanLang.language_name as language_name
, tanLang.language_code as languageCode
FROM %s.tabLanguage as tanLang) as tabLang
ON %s.tabTranslation.language = tabLang.languageCode) as tabTranslation
ON %s.`tabVehicle Segment`.vehicle_segment = tabTranslation.sourceText;""" % (sel,current_db_name,current_db_name,current_db_name,current_db_name,current_db_name ,queryAppendLang,current_db_name,current_db_name,current_db_name,current_db_name)
sel = ""
for d in custom_lang:
r = ",tabTranslation.%s as %s" % (d[0], d[0])
sel += r
actualQuery = """Select
`tabVehicle Segment`.modified as "Modified On",
`tabVehicle Segment`.active_status as "Status",
`tabVehicle Segment`.vehicle_segment as 'Vehicle Segment'
%s
From `tabVehicle Segment`
LEFT JOIN `tabTranslation` as tabTrans
ON `tabVehicle Segment`.vehicle_segment = tabTrans.source_text
LEFT JOIN (Select tabLang.languageCode as languageCode
,tabTranslation.source_text as sourceText
, tabTranslation.translated_text as translated_text
%s
From tabTranslation
INNER JOIN (SELECT tanLang.language_name as language_name
, tanLang.language_code as languageCode
FROM tabLanguage as tanLang) as tabLang
ON tabTranslation.language = tabLang.languageCode) as tabTranslation
ON `tabVehicle Segment`.vehicle_segment = tabTranslation.sourceText
ORDER BY `tabVehicle Segment`.modified DESC;""" % (sel, queryAppendLang)
data = frappe.db.sql(actualQuery,as_list=True)
return data
data = frappe.db.sql(actualQuery, as_list=True)
return data
except Exception as e:
frappe.throw(str(frappe.get_traceback()))
def get_columns():
columns = []
columns += [
_("<b>Modified On</b>") + ":Datetime/:200", _("<b>Status</b>") + ":Data/:100",_("<b>Vehicle Segment</b>") + ":Data/:220",
]
lang = []
custom_lang = frappe.db.sql("""SELECT lang_code,lang_name,active_status FROM %s.`tabCustom Languages` where lang_code <> "en" order by lang_name"""%(current_db_name),as_dict=1)
for d in custom_lang:
lang.append("<b>"+cstr(d["lang_name"])+"</b>"+ "::220")
columns += lang
return columns,lang
columns = []
columns += [
_("<b>Modified On</b>") + ":Datetime/:200", _("<b>Status</b>") +
":Data/:100", _("<b>Vehicle Segment</b>") + ":Data/:220",
]
lang = []
custom_lang = frappe.db.sql(
"""SELECT lang_code,lang_name,active_status FROM `tabCustom Languages` where lang_code <> "en"
order by lang_name;""", as_dict=1)
for d in custom_lang:
lang.append("<b>"+cstr(d["lang_name"])+"</b>" + "::220")
columns += lang
return columns, lang

82
smart_service/masters/report/vehicle_translation/vehicle_translation.py

@ -5,61 +5,67 @@
from __future__ import unicode_literals
import frappe
from frappe.utils import cstr, cint, getdate
from frappe.utils import cstr
from frappe import msgprint, _
current_db_name = frappe.conf.get("db_name")
def execute(filters=None):
columns, data = [], []
columns,lang = get_columns()
data = get_data()
return columns, data
columns, data = [], []
columns, lang = get_columns()
data = get_data()
return columns, data
def get_data():
custom_lang = frappe.db.sql("""SELECT lang_code FROM %s.`tabCustom Languages` where lang_code <> "en" order by lang_name"""%(current_db_name),as_list=True)
queryAppendLang = ""
for d in custom_lang:
q = ", (CASE WHEN tabLang.languageCode = '%s' THEN %s.tabTranslation.translated_text ELSE null END) as %s" %(d[0],current_db_name,d[0])
queryAppendLang += q
custom_lang = frappe.db.sql(
"""SELECT lang_code FROM `tabCustom Languages` where lang_code <> "en" order by lang_name;""", as_list=1)
queryAppendLang = ""
for d in custom_lang:
q = ", (CASE WHEN tabLang.languageCode = '%s' THEN tabTranslation.translated_text ELSE null END) as %s" % (
d[0], d[0])
queryAppendLang += q
sel = ""
for d in custom_lang:
r = ",tabTranslation.%s as %s"%(d[0],d[0])
sel+= r
sel = ""
for d in custom_lang:
r = ",tabTranslation.%s as %s" % (d[0], d[0])
sel += r
actualQuery = """Select
actualQuery = """Select
`tabVehicle`.modified as "Modified On",
`tabVehicle`.active_status as "Status",
`tabVehicle`.vehicle as 'Vehicle'
%s
From %s.`tabVehicle`
LEFT JOIN %s.`tabTranslation` as tabTrans
ON %s.`tabVehicle`.vehicle = tabTrans.source_text
From `tabVehicle`
LEFT JOIN `tabTranslation` as tabTrans
ON `tabVehicle`.vehicle = tabTrans.source_text
LEFT JOIN (Select tabLang.languageCode as languageCode
,%s.tabTranslation.source_text as sourceText
, %s.tabTranslation.translated_text as translated_text
,tabTranslation.source_text as sourceText
, tabTranslation.translated_text as translated_text
%s
From %s.tabTranslation
From tabTranslation
INNER JOIN (SELECT tanLang.language_name as language_name
, tanLang.language_code as languageCode
FROM %s.tabLanguage as tanLang) as tabLang
ON %s.tabTranslation.language = tabLang.languageCode) as tabTranslation
ON %s.`tabVehicle`.vehicle = tabTranslation.sourceText;""" % (sel,current_db_name,current_db_name,current_db_name,current_db_name,current_db_name ,queryAppendLang,current_db_name,current_db_name,current_db_name,current_db_name)
FROM tabLanguage as tanLang) as tabLang
ON tabTranslation.language = tabLang.languageCode) as tabTranslation
ON `tabVehicle`.vehicle = tabTranslation.sourceText ORDER BY `tabVehicle`.modified DESC;""" % (sel, queryAppendLang)
data = frappe.db.sql(actualQuery, as_list=True)
return data
data = frappe.db.sql(actualQuery,as_list=True)
return data
def get_columns():
columns = []
columns += [
_("<b>Modified On</b>") + ":Datetime/:200", _("<b>Status</b>") + ":Data/:100",_("<b>Vehicle</b>") + ":Data/:220",
]
lang = []
custom_lang = frappe.db.sql("""SELECT lang_code,lang_name,active_status FROM %s.`tabCustom Languages` where lang_code <> "en" order by lang_name"""%(current_db_name),as_dict=1)
for d in custom_lang:
lang.append("<b>"+cstr(d["lang_name"])+"</b>"+ "::220")
columns += lang
return columns,lang
columns = []
columns += [
_("<b>Modified On</b>") + ":Datetime/:200", _("<b>Status</b>") +
":Data/:100", _("<b>Vehicle</b>") + ":Data/:220",
]
lang = []
custom_lang = frappe.db.sql(
"""SELECT lang_code,lang_name,active_status FROM `tabCustom Languages` where lang_code <> "en"
order by lang_name;""", as_dict=1)
for d in custom_lang:
lang.append("<b>"+cstr(d["lang_name"])+"</b>" + "::220")
columns += lang
return columns, lang

Loading…
Cancel
Save