Browse Source

Check vehicle and all vehicle update fixes

version2
venkataakhil 11 months ago
parent
commit
caca62111f
  1. 439
      smart_service/apis/check_update.py
  2. 7
      smart_service/apis/master_api.py
  3. 118
      smart_service/apis/publish_api.py
  4. 321
      smart_service/apis/test.py
  5. 1171
      smart_service/apis/update_validation.py
  6. 7
      smart_service/transactions/doctype/publish/publish.js
  7. 30
      smart_service/transactions/doctype/publish/publish.py

439
smart_service/apis/check_update.py

@ -0,0 +1,439 @@
import frappe
from frappe.model.document import Document
import json
import os
from frappe.utils import cstr
from smart_service.apis.app_user_login import input_validation
""" Constants """
JSON_EXT = ".json"
JSON_INT_PATH = "/files/json_files/internal/"
JSON_FULL_INT_PATH = "/files/json_files/full_update/internal/"
JSON_GLOABL_PATH = "/files/json_files/global/"
JSON_FULL_GLOBAL_PATH = "/files/json_files/full_update/"
STATUS = "status"
ERROR = "error"
UPDATE_AVAILABLE = 'IsUpdateAvailable'
UPDATE_FAILED = "Update checking Failed"
PARAM_MISSING = "Parameter missing :"
VERSION = 'Version'
CUR_VERSION = 'CurrentVersion'
DIS = 'Discription'
FILE_ERROR = 'File failed to load'
LANGUAGE = 'Language'
FILE_SIZE = 'FileSize'
JSON_URL = 'JsonURL'
site_name = cstr(frappe.local.site)
base_url = os.path.expanduser(
"~") + "/frappe-bench/sites/" + site_name + "/public"
@frappe.whitelist(allow_guest=1)
def check_vehicle_update(vehicle_list=None):
""" Rate Limiting """
# rate_res = custom_rate_limit(limit=5, seconds=15)
# if rate_res != 1:
# return rate_res
""" Validate Inputs """
val = input_validation(vehicle_list=vehicle_list)
""" Validate Input response """
if val != '':
return {"Vehicle": None,
"VehicleReqList": [],
STATUS: 0, ERROR: PARAM_MISSING+val}
response = {}
""" Iterate Vehicle List """
if vehicle_list:
try:
""" Read Request Body """
req_list = json.loads(vehicle_list)
response['Vehicle'] = req_list['Vehicle']
vehicle = req_list['Vehicle']
iid = req_list['InstallationId']
vehicle_data = req_list['VehicleReqList']
""" Get Publish Type based on IID """
publish_type = frappe.db.get_list(
'App Device', filters={'name': iid}, fields='publish_type')
if publish_type:
publish_type = publish_type[0]['publish_type']
VehicleReqList = []
for v in vehicle_data:
l_id = v['LanguageID']
current_version = float(v[CUR_VERSION])
""" New function to validate publish version and get file path """
pulish_response = get_vehicle_publish_data(vehicle=vehicle,
l_id=l_id, current_version=current_version, publish_type=publish_type)
""" Append to Main Vehicle Request Response List """
VehicleReqList.append(pulish_response)
return {
"Vehicle": vehicle, "VehicleReqList": VehicleReqList, STATUS: 1, ERROR: "No error"}
except Exception as e:
return {"Vehicle": None, "VehicleReqList": [], STATUS: 0, ERROR: str(e)}
else:
return {"Vehicle": None, "VehicleReqList": [], STATUS: 0, ERROR: "Check Parameter: vehicle list"}
def get_file_size(file_name):
return os.path.getsize(base_url + file_name)
def get_vehicle_publish_data(vehicle, l_id, current_version, publish_type):
""" Response Structure """
vehicle_response_data = {
"Name": None,
"Version": 0,
"Vehicle": None,
"Language": l_id,
"Description": None,
"JsonURL": None,
"FileSize": None,
"Error": None,
"IsUpdateAvailable": False,
"CurrentVersion": current_version
}
latest_global_version = frappe.db.sql('''SELECT name as Name,format(version,2) as version,vehicle_id,language,release_description as Description
FROM `tabPublish` where vehicle='{0}' and language='{1}' and publish_status='Published' and vehicle_status='Active'
and publish_module='Automotive System' and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System' and vehicle='{0}' and publish_type='Global' and language='{1}');
'''.format(vehicle, l_id), as_dict=1)
latest_publish_version = frappe.db.sql('''SELECT name as Name,format(version,2) as version,vehicle_id,language,release_description as Description
FROM `tabPublish` where vehicle='{0}' and language='{1}' and publish_status='Published' and vehicle_status='Active'
and publish_module='Automotive System' and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System' and vehicle='{0}' and language='{1}' and version >= {2});
'''.format(vehicle, l_id, current_version), as_dict=1)
if not latest_publish_version:
""" Latest File already downloaded Global/Internal """
vehicle_response_data['IsUpdateAvailable'] = False
vehicle_response_data['Remarks'] = "Latest Version"
else:
if not latest_global_version or (current_version >= float(latest_global_version[0]['version'])):
""" Only First Internal available """
if publish_type == 'Internal':
value = round(
float(latest_publish_version[0]['version']) - current_version, 2)
if value == 0.01:
# frappe.log_error('Inside 1 Internal')
""" 1 Internal File """
data = frappe.db.sql('''SELECT name as Name,format(version,2) as Version,vehicle_id as Vehicle,language as Language,
release_description as Description FROM `tabPublish` where vehicle='{0}' and language='{1}' and
publish_status='Published' and vehicle_status='Active' and publish_module='Automotive System'
and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System' and publish_type='Internal'
and vehicle='{0}' and language='{1}');
'''.format(vehicle, l_id), as_dict=1)
# frappe.log_error('data', str(data))
# data = latest_publish_version
# frappe.log_error("data",str(data))
if data:
file_name = JSON_INT_PATH+vehicle+"/"+vehicle + \
"-" + l_id + "_v" + \
str(data[0][VERSION]) + JSON_EXT
if os.path.exists(base_url + file_name):
vehicle_response_data['Name'] = data[0]['Name']
vehicle_response_data['Vehicle'] = data[0]['Vehicle']
vehicle_response_data['Version'] = data[0]['Version']
vehicle_response_data['Language'] = data[0]['Language']
vehicle_response_data['Description'] = data[0]['Description']
vehicle_response_data['FileSize'] = get_file_size(
file_name)
vehicle_response_data['JsonURL'] = file_name
vehicle_response_data['IsUpdateAvailable'] = True
vehicle_response_data['Remarks'] = "Internal available"
else:
vehicle_response_data['IsUpdateAvailable'] = False
vehicle_response_data['Remarks'] = "Internal available"
vehicle_response_data['Error'] = "Failed to read file"
else:
vehicle_response_data['IsUpdateAvailable'] = False
vehicle_response_data['Remarks'] = "Internal available"
vehicle_response_data['Error'] = "Failed to get Publish version"
else:
""" Full Internal File """
# same as latest_publish_version
data = frappe.db.sql('''SELECT name as Name,format(version,2) as Version,vehicle_id as Vehicle,language as Language,
release_description as Description FROM `tabPublish` where vehicle='{0}' and language='{1}' and
publish_status='Published' and vehicle_status='Active' and publish_module='Automotive System'
and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System' and publish_type='Internal'
and vehicle='{0}' and language='{1}' );
'''.format(vehicle, l_id), as_dict=1)
# data = latest_publish_version
if data:
file_name = JSON_FULL_INT_PATH+vehicle+"/"+vehicle + \
"-" + l_id + "-"+"full_v" + \
str(data[0][VERSION]
) + JSON_EXT
if os.path.exists(base_url + file_name):
vehicle_response_data['Name'] = data[0]['Name']
vehicle_response_data['Vehicle'] = data[0]['Vehicle']
vehicle_response_data['Version'] = data[0]['Version']
vehicle_response_data['Language'] = data[0]['Language']
vehicle_response_data['Description'] = data[0]['Description']
vehicle_response_data['FileSize'] = get_file_size(
file_name)
vehicle_response_data['JsonURL'] = file_name
vehicle_response_data['IsUpdateAvailable'] = True
vehicle_response_data['Remarks'] = "Internal Full Update available"
else:
vehicle_response_data['IsUpdateAvailable'] = False
vehicle_response_data['Remarks'] = "Internal Full Update available"
vehicle_response_data['Error'] = "Failed to read file"
else:
vehicle_response_data['IsUpdateAvailable'] = False
vehicle_response_data['Remarks'] = "Internal Full Update available"
vehicle_response_data['Error'] = "Failed to get Publish version"
else:
vehicle_response_data['IsUpdateAvailable'] = False
vehicle_response_data['Remarks'] = "No Update available"
elif current_version < float(latest_global_version[0]['version']):
""" Only Global available """
if (float(latest_global_version[0]['version']) - int(current_version)) > 1:
""" Full Global File """
data = frappe.db.sql('''SELECT name as Name,format(version,2) as Version,vehicle_id as Vehicle,language as Language,
release_description as Description FROM `tabPublish` where vehicle='{0}' and language='{1}' and
publish_status='Published' and vehicle_status='Active' and publish_module='Automotive System'
and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System'
and vehicle='{0}' and language='{1}' and publish_type ='Global');
'''.format(vehicle, l_id), as_dict=1)
if data:
file_name = JSON_FULL_GLOBAL_PATH + vehicle + "/" + vehicle + \
"-" + l_id + "-"+"full_v" + \
str(data[0][VERSION]
) + JSON_EXT
if os.path.exists(base_url + file_name):
vehicle_response_data['Name'] = data[0]['Name']
vehicle_response_data['Vehicle'] = data[0]['Vehicle']
vehicle_response_data['Version'] = data[0]['Version']
vehicle_response_data['Language'] = data[0]['Language']
vehicle_response_data['Description'] = data[0]['Description']
vehicle_response_data['FileSize'] = get_file_size(
file_name)
vehicle_response_data['JsonURL'] = file_name
vehicle_response_data['IsUpdateAvailable'] = True
vehicle_response_data['Remarks'] = "Global Full Update available"
else:
vehicle_response_data['IsUpdateAvailable'] = False
vehicle_response_data['Remarks'] = "Global Full Update available"
vehicle_response_data['Error'] = "Failed to read file"
else:
vehicle_response_data['IsUpdateAvailable'] = False
vehicle_response_data['Remarks'] = "Global Full Update available"
vehicle_response_data['Error'] = "Failed to get Publish version"
# vehicle_response_data['IsUpdateAvailable'] = True
# vehicle_response_data['Remarks'] = "Full Update Global available"
else:
""" Single Global File """
# vehicle_response_data['IsUpdateAvailable'] = True
# vehicle_response_data['Remarks'] = "Global available"
data = frappe.db.sql('''SELECT name as Name,format(version,2) as Version,vehicle_id as Vehicle,language as Language,
release_description as Description FROM `tabPublish` where vehicle='{0}' and language='{1}' and
publish_status='Published' and vehicle_status='Active' and publish_module='Automotive System'
and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System'
and vehicle='{0}' and language='{1}' and publish_type ='Global');
'''.format(vehicle, l_id), as_dict=1)
if data:
file_name = JSON_GLOABL_PATH+vehicle+"/"+vehicle + \
"-" + l_id + "_v" + \
str(data[0][VERSION]) + JSON_EXT
if os.path.exists(base_url + file_name):
vehicle_response_data['Name'] = data[0]['Name']
vehicle_response_data['Vehicle'] = data[0]['Vehicle']
vehicle_response_data['Version'] = data[0]['Version']
vehicle_response_data['Language'] = data[0]['Language']
vehicle_response_data['Description'] = data[0]['Description']
vehicle_response_data['FileSize'] = get_file_size(
file_name)
vehicle_response_data['JsonURL'] = file_name
vehicle_response_data['IsUpdateAvailable'] = True
vehicle_response_data['Remarks'] = "Global available"
else:
vehicle_response_data['IsUpdateAvailable'] = False
vehicle_response_data['Remarks'] = "Global available"
vehicle_response_data['Error'] = "Failed to read file"
else:
vehicle_response_data['IsUpdateAvailable'] = False
vehicle_response_data['Remarks'] = "Global available"
vehicle_response_data['Error'] = "Failed to get Publish version"
else:
""" Unknow condition Dont Know Yet """
value = {'latest_publish_version': latest_publish_version[0]['version'],
" latest_global_version": latest_global_version[0]['version']}
frappe.log_error('New check Update', str(
f'Unknow Condition{value}'))
vehicle_response_data['IsUpdateAvailable'] = True
vehicle_response_data['Remarks'] = "New Condition"
return vehicle_response_data
@frappe.whitelist(allow_guest=1)
def check_all_vehicle_updates(vehicle_list=None):
val = input_validation(vehicle_list=vehicle_list)
if val != '':
return {STATUS: 0, ERROR: PARAM_MISSING+val}
if vehicle_list:
try:
vehicle_req_list = []
response = {}
v_list = json.loads(vehicle_list)
lang = v_list['LanguageID']
iid = v_list['InstallationId']
vehicle_data = v_list['VehicleReqList']
publish_type = frappe.db.sql(
'''SELECT publish_type FROM `tabApp Device` where name='{}';'''.format(iid), as_list=1)
if publish_type[0][0] is not None:
if vehicle_data:
for v in vehicle_data:
v_id = v['Vehicle']
current_version = float(v[CUR_VERSION])
data1_global = frappe.db.sql('''SELECT name,format(version,2) as version,vehicle_id,language,release_description as description
FROM `tabPublish` where vehicle='{}' and language='{}' and publish_status='Published'
and publish_type='Global'
and vehicle_status='Active' and publish_module='Automotive System' and version = (select max(version) as version
from `tabPublish` where publish_module='Automotive System'
and vehicle='{}' and publish_type='Global' and language='{}');'''.format(v_id, lang, v_id, lang), as_dict=1)
data1 = frappe.db.sql('''SELECT name,format(max(version),2) as version,vehicle_id,language,release_description as description
FROM `tabPublish` where vehicle='{}' and language='{}'
and publish_status='Published' and vehicle_status='Active' and publish_module='Automotive System'
and vehicle='{}' and language='{}'
;'''.format(v_id, lang, v_id, lang), as_dict=1)
if data1[0]['version'] is not None:
if current_version == float(data1[0]['version']):
data1[0][CUR_VERSION] = current_version
data1[0][UPDATE_AVAILABLE] = "false"
vehicle_req_list.append(data1)
elif len(data1_global) == 0:
if current_version < float(data1[0]['version']):
data = frappe.db.sql('''SELECT name,format(version,2) as version,vehicle_id,language,release_description as description
FROM `tabPublish` where vehicle='{}' and language='{}' and publish_status='Published' and
publish_type='{}' and vehicle_status='Active' and publish_module='Automotive System' and
version = (select max(version) as version from `tabPublish` where publish_module='Automotive System'
and vehicle='{}' and language='{}')'''.format(v_id, lang, publish_type[0][0], v_id, lang), as_dict=1)
data_append = []
rd = []
try:
for d in data:
d[UPDATE_AVAILABLE] = 'true'
d[CUR_VERSION] = current_version
data_append.append(d)
vehicle_req_list.append(data_append)
except:
pass
else:
if current_version < float(data1_global[0]['version']):
data = frappe.db.sql('''SELECT name,format(version,2) as version,vehicle_id,language,release_description as description
FROM `tabPublish` where vehicle='{}' and language='{}'
and publish_status='Published' and publish_type='Global' and vehicle_status='Active'
and publish_module='Automotive System'
and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System'
and vehicle='{}' and language='{}')'''.format(v_id, lang, v_id, lang), as_dict=1)
elif current_version == float(data1_global[0]['version']):
if current_version < float(data1[0]['version']):
data = frappe.db.sql('''SELECT name,format(version,2) as version,vehicle_id,language,release_description as description
FROM `tabPublish` where vehicle='{}' and language='{}' and publish_status='Published' and publish_type='{}'
and vehicle_status='Active' and publish_module='Automotive System'
and version = (select max(version) as version from `tabPublish` where publish_module='Automotive System'
and vehicle='{}' and language='{}')'''.format(v_id, lang, publish_type[0][0], v_id, lang), as_dict=1)
elif current_version > float(data1_global[0]['version']):
if current_version < float(data1[0]['version']):
data = frappe.db.sql('''SELECT name,format(version,2) as version,vehicle_id,language,release_description as description
FROM `tabPublish` where vehicle='{}' and language='{}' and publish_status='Published' and
publish_type='{}' and vehicle_status='Active' and publish_module='Automotive System' and
version = (select max(version) as version from `tabPublish` where publish_module='Automotive System'
and vehicle='{}' and language='{}')'''.format(v_id, lang, publish_type[0][0], v_id, lang), as_dict=1)
# return data
data_append = []
rd = []
try:
for d in data:
d[UPDATE_AVAILABLE] = 'true'
d[CUR_VERSION] = current_version
data_append.append(d)
vehicle_req_list.append(data_append)
# for note in publish_dec:
# rd.append(note)
# vehicle_req_list.append(rd)
# for n in publish_dec:
# rd.append(n['release_description'])
# vehicle_req_list.append(rd)
except:
pass
response['LanguageID'] = lang
if len(vehicle_req_list) != 0:
data = [vu[0] for vu in vehicle_req_list]
# publish_dec_txt = [pd[0] for pd in publish_dec]
response['VehicleReqList'] = data
# response['release_description'] = publish_dec_txt['release_description']
return response
else:
return {STATUS: 0, ERROR: "No Vehicles in criteria"}
else:
return {STATUS: 0, ERROR: "Invalid Publish Details"}
else:
return {STATUS: 0, ERROR: "Invalid Publish Details"}
except Exception as e:
return {STATUS: 0, ERROR: str(e)}
else:
return {STATUS: 0, ERROR: "Check argument: vehicle list"}

7
smart_service/apis/master_api.py

@ -74,13 +74,13 @@ def masters(args=None, LSD=None, iid=None):
api = frappe.db.sql(f'''
select name as vehicle,vehicle_segment,vehicle_segment_id,image,active_status,display_order,
myid as vechile_id,display_order,modified from tabVehicle
where modified > '{LSD}' and global_publish = 1;
where modified > '{LSD}' and global_publish = 1;
''', as_dict=1)
else:
api = frappe.db.sql(f'''
select name as vehicle,vehicle_segment,vehicle_segment_id,image,active_status,display_order,
myid as vechile_id,display_order,modified from tabVehicle
where modified > '{LSD}' and internal_publish = 1;
where modified > '{LSD}' and internal_publish = 1;
''', as_dict=1)
for i in api:
if i["active_status"] == "Active":
@ -349,6 +349,7 @@ def old_variant(LSD, language):
@frappe.whitelist(methods=['POST'])
def variant(LSD, language, iid=None):
# frappe.log_error("variant")
date_format = "%Y-%m-%d %H:%M:%S.%f"
# if LSD != "null":
# try:
@ -359,7 +360,7 @@ def variant(LSD, language, iid=None):
try:
data = frappe.db.sql(f'''
select name,vehicle,vehicle_id,name as variant_name,variant,variant_id,fuel,fuel_id,transmission,transmission_id,
drive,drive_id,family_code,
drive,drive_id,family_code,
case when active_status= 'Active' Then true else false end as active_status
FROM `tabVariant Mapping` where modified >='{LSD}';''', as_dict=1)
for d in data:

118
smart_service/apis/publish_api.py

@ -246,8 +246,8 @@ def old_json_grouping(args, language):
final.append(variant_out)
dicfinal = {"JSON": final}
frappe.db.sql(""" UPDATE %s.tabPublish SET publish_status = "%s" where name = "%s" """ % (
current_db_name, "Published", args))
frappe.db.sql(""" UPDATE `tabPublish` SET publish_status = "%s" where name = "%s" """ % (
"Published", args))
frappe.db.commit()
return dicfinal
@ -294,7 +294,7 @@ def json_grouping(args, language):
variant_out = {}
vari = frappe.db.sql("""SELECT name,variant, vehicle,family_code,vehicle_segment,fuel,transmission,drive, active_status
FROM %s.`tabVariant Mapping` WHERE name ="%s" ; """ % (current_db_name, d),
as_dict=True)
as_dict=True)
var_asset = frappe.db.sql(
"""SELECT name,category, attach_file as file, %s FROM %s.`tabVariant Mapping_Assets` where category<>"Technical Manual"
@ -317,8 +317,8 @@ def json_grouping(args, language):
kms_active_status = True
else:
kms_active_status = False
vari.update({"kms_mapping_active_status": kms_active_status})
if kms_mapping_status:
vari.update({"kms_mapping_active_status": kms_active_status})
vari["Assets"] = var_asset
variant_out["Variant"] = vari
@ -351,7 +351,7 @@ def json_grouping(args, language):
sys["Assets"] = sysassets
subsystem_out = []
for j in subsystem[d][i]:
for j in subsystem[d][i]:
subsys = frappe.db.sql("""select tmss.idx as subSystemdisplayorder,
concat("{0}","-",systems) as sys_id,
concat("{0}","-",systems,"-",sub_systems) as subsys_id,
@ -360,7 +360,7 @@ def json_grouping(args, language):
from {4}.`tabSystem Mapping_Sub System` tmss inner join {4}.`tabSub Systems` ts on tmss.sub_systems = ts.name
where tmss.parent like "{0}-{3}%" and systems="{1}" and sub_systems="{2}";""".format(
d, i, j, lang["language"], current_db_name), as_dict=1)
subsys = subsys[0]
if subsys["active_status"] == "Active":
@ -406,12 +406,14 @@ def json_grouping(args, language):
final.append(variant_out)
dicfinal = {"JSON": final}
frappe.db.sql(""" UPDATE %s.tabPublish SET publish_status = "%s" where name = "%s" """ % (
current_db_name, "Published", args))
frappe.log_error('dicfinal' + str(dicfinal))
frappe.db.sql(""" UPDATE `tabPublish` SET publish_status = "%s" where name = "%s" """ % (
"Published", args))
frappe.db.commit()
return dicfinal
except Exception as e:
frappe.log_error('JSON Grouping',str(e))
frappe.log_error('JSON Grouping', str(e))
""" New Publish """
@ -441,6 +443,7 @@ def new_publish(args, publish_type, vehicle, language, version):
""" JSON generation """
json_file = json_grouping(args, language)
frappe.log_error('json grouping' + str(json_file))
file_name = ""
base_file_name = "%s-%s_v%s.json" % (vehicle, language, version)
@ -451,7 +454,7 @@ def new_publish(args, publish_type, vehicle, language, version):
file_name = global_path + vehicle + "/" + base_file_name
else:
return {STATUS: 0, ERROR: "Publish type not available"}
frappe.log_error('created file name' +str(file_name))
frappe.log_error('created file name' + str(file_name))
""" Save file (Internal/Global) """
with open(file_name, "w") as outfile:
@ -471,7 +474,7 @@ def new_publish(args, publish_type, vehicle, language, version):
prev_update_ver = None
check_if_global_exist = frappe.db.sql("""SELECT vehicle,language,format(version,2) as version,modified,publish_type FROM tabPublish where vehicle = "{}"
and publish_type = "Global" AND `language` = "{}" and publish_module="Automotive System" order by modified desc limit 1 ;""".format(vehicle, language), as_dict=1)
if publish_type.lower() == "global":
frappe.log_error(str("global"))
full_update_file_name = full_update_path + vehicle + "/" + \
@ -488,65 +491,68 @@ def new_publish(args, publish_type, vehicle, language, version):
pub_ver = frappe.db.sql(""" SELECT vehicle,language,format(version,2) as version,modified,publish_type FROM tabPublish where vehicle = "{}"
and publish_type = "Global" AND `language` = "{}" order by modified desc limit 2 ;""".format(vehicle, language), as_dict=1)
if pub_ver:
prev_update_ver = pub_ver[1]["version"]
prev_full_update_file = full_update_path + vehicle + "/" + \
"%s-%s-full_v%s.json" % (vehicle,
language, prev_update_ver)
language, prev_update_ver)
file_flag, final_update_file = merge_json_files(
prev_full_update_file, file_name, full_update_file_name)
get_step_total_count(final_update_file)
set_publish_flag(publish_type,vehicle,language)
set_publish_flag(publish_type, vehicle, language)
if file_flag:
return True, file_name.split("public")[1]
# return True, file_name
else:
return False, "File save issue"
if publish_type.lower() == "internal" and len(check_if_global_exist)>0:
if publish_type.lower() == "internal" and len(check_if_global_exist) > 0:
frappe.log_error(str('already global published'))
full_update_file_name = full_update_path_internal + vehicle + "/" + \
"%s-%s-full_v%s.json" % (vehicle, language, version)
frappe.log_error( 'update file' + str(full_update_file_name))
frappe.log_error('update file' + str(full_update_file_name))
pub_ver = frappe.db.sql(""" SELECT vehicle,language,format(version,2) as version,modified,publish_type FROM tabPublish where vehicle = "{}"
and publish_type = "Internal" AND `language` = "{}" and publish_module="Automotive System" order by modified desc limit 2 ;""".format(vehicle, language), as_dict=1)
if pub_ver:
frappe.log_error('inside')
prev_update_ver_internal = float(pub_ver[1]["version"])
frappe.log_error('version_internal' + str(prev_update_ver_internal))
frappe.log_error('version_internal' +
str(prev_update_ver_internal))
prev_full_internal_update_file = full_update_path_internal + vehicle + "/" + \
"%s-%s-full_v%s.json" % (vehicle,
language, prev_update_ver_internal)
"%s-%s-full_v%s.json" % (vehicle,
language, prev_update_ver_internal)
if check_if_global_exist:
frappe.log_error('inside1')
prev_global_update_ver = check_if_global_exist[0]["version"]
frappe.log_error('version_global' + str(prev_global_update_ver))
frappe.log_error('version_global' +
str(prev_global_update_ver))
prev_global_file = full_update_path + vehicle + "/" + \
"%s-%s-full_v%s.json" % (vehicle,
language, prev_global_update_ver)
"%s-%s-full_v%s.json" % (vehicle,
language, prev_global_update_ver)
frappe.log_error('prev_global' + str(prev_global_file))
file_flag, final_update_file = merge_json_files(
prev_global_file, file_name, full_update_file_name)
prev_global_file, file_name, full_update_file_name)
get_step_total_count(final_update_file)
set_publish_flag(publish_type,vehicle,language)
set_publish_flag(publish_type, vehicle, language)
if file_flag:
return True, file_name.split("public")[1]
# return True, file_name
else:
return False, "File save issue"
# frappe.log_error("global exists")
# last_fullupdate_file = frappe.db.sql(""" SELECT vehicle,language,format(version,2) as version,modified,publish_type FROM tabPublish where vehicle = "{}"
# last_fullupdate_file = frappe.db.sql(""" SELECT vehicle,language,format(version,2) as version,modified,publish_type FROM tabPublish where vehicle = "{}"
# and publish_type = "Internal" AND `language` = "{}" order by modified desc limit 2 ;""".format(vehicle, language), as_dict=1)
# if last_fullupdate_file:
# pass
else:
frappe.log_error(str('first time ionternal'))
full_update_file_name = full_update_path_internal + vehicle + "/" + \
"%s-%s-full_v%s.json" % (vehicle, language, version)
if str(version) == "0.01":
frappe.log_error(str('first time ionternal file creation'))
with open(full_update_file_name, "w") as outfile:
outfile.write(json.dumps(json_file))
get_step_total_count(full_update_file_name)
@ -557,32 +563,30 @@ def new_publish(args, publish_type, vehicle, language, version):
prev_update_ver = pub_ver[1]["version"]
prev_full_update_file = full_update_path_internal + vehicle + "/" + \
"%s-%s-full_v%s.json" % (vehicle,
language, prev_update_ver)
language, prev_update_ver)
file_flag, final_update_file = merge_json_files(
prev_full_update_file, file_name, full_update_file_name)
get_step_total_count(final_update_file)
set_publish_flag(publish_type,vehicle,language)
set_publish_flag(publish_type, vehicle, language)
if file_flag:
return True, file_name.split("public")[1]
# return True, file_name
else:
return False, "File save issue"
set_publish_flag(publish_type,vehicle,language)
frappe.log_error('file_name' +str(file_name))
set_publish_flag(publish_type, vehicle, language)
frappe.log_error('file_name' + str(file_name))
return True, file_name.split("public")[1]
# return True, file_name
except Exception as e:
# return "Failed to save file"
frappe.log_error("Publish",frappe.get_traceback())
frappe.log_error("Publish", frappe.get_traceback())
return False, str(frappe.get_traceback())
def set_publish_flag(publish_type,vehicle,language):
def set_publish_flag(publish_type, vehicle, language):
try:
if publish_type == 'Internal':
# Update vehicle master field
@ -590,7 +594,7 @@ def set_publish_flag(publish_type,vehicle,language):
SELECT * FROM tabVehicle where vehicle = '{vehicle}' and internal_publish=1;
''')
if not vehicle_data:
if not vehicle_data:
frappe.db.sql(f'''
update tabVehicle set internal_publish = 1 where vehicle = '{vehicle}';
''')
@ -601,7 +605,7 @@ def set_publish_flag(publish_type,vehicle,language):
SELECT * FROM `tabCustom Languages` where lang_code = '{language}' and internal_publish=1;
''')
if not lang_data:
if not lang_data:
frappe.db.sql(f'''
update `tabCustom Languages` set internal_publish = 1 where lang_code = '{language}';
''')
@ -622,15 +626,15 @@ def set_publish_flag(publish_type,vehicle,language):
lang_data = frappe.db.sql(f'''
SELECT * FROM `tabCustom Languages` where lang_code = '{language}' and global_publish=1;
''')
if not lang_data:
if not lang_data:
frappe.db.sql(f'''
update `tabCustom Languages` set global_publish = 1 where lang_code = '{language}';
''')
frappe.db.commit()
except Exception as e:
frappe.log_error('set_publish_flag' +str(e))
frappe.log_error('set_publish_flag' + str(e))
def merge_json_files(old_json_path, new_json_path, out_file_path):
@ -643,7 +647,8 @@ def merge_json_files(old_json_path, new_json_path, out_file_path):
data_new = json.load(json_file1)
for k in data_new["JSON"]:
old_var_key = check_key(k["Variant"]["name"], data_old["JSON"], "Variant")
old_var_key = check_key(
k["Variant"]["name"], data_old["JSON"], "Variant")
if old_var_key is not None and old_var_key >= 0:
var_dict = {}
var_dict["Variant"] = k["Variant"]
@ -654,7 +659,8 @@ def merge_json_files(old_json_path, new_json_path, out_file_path):
var_dict["Variant"]["Assets"] = data_old["JSON"][old_var_key]["Variant"]["Assets"]
for i in variant_systems:
old_sys_key = check_key(i["sys_id"], var_dict["Variant"]["Systems"], "System")
old_sys_key = check_key(
i["sys_id"], var_dict["Variant"]["Systems"], "System")
if old_sys_key is not None and old_sys_key >= 0:
var_dict["Variant"]["Systems"][old_sys_key]["systemdisplayorder"] = i["systemdisplayorder"]
@ -668,11 +674,12 @@ def merge_json_files(old_json_path, new_json_path, out_file_path):
old_sub_key = check_key(s["sub_systems"],
var_dict["Variant"]["Systems"][old_sys_key]["Subsystems"],
"Sub System")
if old_sub_key is not None and old_sub_key >= 0:
var_dict["Variant"]["Systems"][old_sys_key]["Subsystems"][old_sub_key] = s
else:
var_dict["Variant"]["Systems"][old_sys_key]["Subsystems"].append(s)
var_dict["Variant"]["Systems"][old_sys_key]["Subsystems"].append(
s)
else:
var_dict["Variant"]["Systems"].append(i)
@ -691,10 +698,10 @@ def merge_json_files(old_json_path, new_json_path, out_file_path):
data_old = []
json_object = []
data_new = []
return True, out_file_path
return True, out_file_path
except:
return False, frappe.log_error("Merge JSON:",frappe.get_traceback())
return False, frappe.log_error("Merge JSON:", frappe.get_traceback())
def check_key(key_name, old_data, type=None):
@ -706,22 +713,23 @@ def check_key(key_name, old_data, type=None):
if old_data[d]["Variant"]["name"] == key_name:
return d
except:
frappe.log_error("Check key System:",frappe.get_traceback())
frappe.log_error("Check key System:", frappe.get_traceback())
if type == "System":
try:
if old_data[d]["sys_id"] == key_name:
return d
except:
frappe.log_error("Check key System:",frappe.get_traceback())
frappe.log_error("Check key System:", frappe.get_traceback())
if type == "Sub System":
try:
if old_data[d]["sub_systems"] == key_name:
return d
except:
frappe.log_error("Check key subsystem:",frappe.get_traceback())
frappe.log_error("Check key subsystem:",
frappe.get_traceback())
@frappe.whitelist(allow_guest=True)
def new_update(vehicle_list=None):

321
smart_service/apis/test.py

@ -0,0 +1,321 @@
import frappe
from frappe.model.document import Document
import json
import os
from frappe.utils import cstr
from smart_service.apis.app_user_login import input_validation
JSON_EXT = ".json"
JSON_INT_PATH = "/files/json_files/internal/"
JSON_FULL_INT_PATH = "/files/json_files/full_update/internal/"
JSON_GLOABL_PATH = "/files/json_files/global/"
JSON_FULL_GLOBAL_PATH = "/files/json_files/full_update/"
STATUS = "status"
ERROR = "error"
UPDATE_AVAILABLE = 'IsUpdateAvailable'
UPDATE_FAILED = "Update checking Failed"
PARAM_MISSING = "Parameter missing :"
VERSION = 'version'
CUR_VERSION = 'CurrentVersion'
DIS = 'Discription'
FILE_ERROR = 'File failed to load'
LANGUAGE = 'language'
FILE_SIZE = 'FileSize'
JSON_URL = 'JsonURL'
REMARKS = 'remarks'
site_name = cstr(frappe.local.site)
base_url = os.path.expanduser(
"~") + "/frappe-bench/sites/" + site_name + "/public"
def custom_rate_limit(limit, seconds):
ip_based = True
ip = frappe.local.request_ip if ip_based is True else None
identity = None
identity = ip
cache_key = f"rl:{frappe.form_dict.cmd}:{identity}"
value = frappe.cache().get(cache_key) or 0
if not value:
frappe.cache().setex(cache_key, seconds, 0)
value = frappe.cache().incrby(cache_key, 1)
if value > limit:
frappe.local.response["http_status_code"] = 429
return "You hit the rate limit because of too many requests. Please try after sometime."
return 1
@frappe.whitelist(allow_guest=1)
def check_all_vehicle_updates(vehicle_list=None):
""" Validate Input's """
val = input_validation(vehicle_list=vehicle_list)
""" Error response based on missing Input arguements """
if val != '':
return {"LanguageID": None,
"VehicleReqList": [], STATUS: 0, ERROR: PARAM_MISSING+val}
if vehicle_list:
""" Validate Input keys """
try:
vehicle_req_list = []
v_list = json.loads(vehicle_list)
language = v_list['LanguageID']
iid = v_list['InstallationId']
vehicle_data = v_list['VehicleReqList']
publish_type = frappe.db.sql(
'''SELECT publish_type FROM `tabApp Device` where name='{}';'''.format(iid), as_list=1)
if not publish_type:
""" Error Response for Invalid Publish Type """
return {"LanguageID": None,
"VehicleReqList": [], STATUS: 0, ERROR: "Publish Type not set "}
for v in vehicle_data:
vehicle_id = get_vehicle_id(v['Vehicle'])
publish_response = get_all_vehicle_publish_data(
v['Vehicle'], language, float(v['CurrentVersion']), publish_type[0][0], vehicle_id)
vehicle_req_list.append(publish_response)
""" Vehicle List Response """
return {"LanguageID": language,
"VehicleReqList": vehicle_req_list, STATUS: 1, ERROR: 'No Error'}
except Exception as e:
""" Error Response for Input key's validation """
return {"LanguageID": None,
"VehicleReqList": [], STATUS: 0, ERROR: str(e)}
else:
""" Error Response for Empty Vehicle List """
return {"LanguageID": None,
"VehicleReqList": [], STATUS: 0, ERROR: "Check Arugument: vehicle list"}
def get_vehicle_id(vehicle):
vehicle_id = frappe.db.sql(
'''select myid as vehicle_id from `tabVehicle` where vehicle ='{0}'; '''.format(vehicle), as_dict=1)
if vehicle_id:
return vehicle_id[0]['vehicle_id']
else:
False
def get_all_vehicle_publish_data(vehicle, l_id, current_version, publish_type, vehicle_id):
""" Response Structure """
vehicle_response_data = {
"name": None,
"version": 0,
"vehicle_id": vehicle_id,
"language": l_id,
"description": None,
ERROR: None,
UPDATE_AVAILABLE: False,
"CurrentVersion": current_version
}
latest_global_version = frappe.db.sql('''SELECT name,format(version,2) as version,vehicle_id,language,release_description as description
FROM `tabPublish` where vehicle='{0}' and language='{1}' and publish_status='Published' and vehicle_status='Active'
and publish_module='Automotive System' and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System' and vehicle='{0}' and publish_type='Global' and language='{1}');
'''.format(vehicle, l_id), as_dict=1)
latest_publish_version = frappe.db.sql('''SELECT name,format(version,2) as version,vehicle_id,language,release_description as description
FROM `tabPublish` where vehicle='{0}' and language='{1}' and publish_status='Published' and vehicle_status='Active'
and publish_module='Automotive System' and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System' and vehicle='{0}' and language='{1}' and version > {2});
'''.format(vehicle, l_id, current_version), as_dict=1)
if not latest_publish_version:
""" Latest File already downloaded Global/Internal """
vehicle_response_data[UPDATE_AVAILABLE] = False
vehicle_response_data[REMARKS] = "Latest Version"
else:
if not latest_global_version or (current_version >= float(latest_global_version[0]['version'])):
""" Only Internal available """
if publish_type == 'Internal':
value = round(
float(latest_publish_version[0]['version']) - current_version, 2)
if value == 0.01:
""" 1 Internal File """
data = frappe.db.sql('''SELECT name, format(version,2) as version,vehicle_id, language,
release_description as description FROM `tabPublish` where vehicle='{0}' and language='{1}' and
publish_status='Published' and vehicle_status='Active' and publish_module='Automotive System'
and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System' and publish_type='Internal'
and vehicle='{0}' and language='{1}');
'''.format(vehicle, l_id), as_dict=1)
if data:
file_name = JSON_INT_PATH+vehicle+"/"+vehicle + \
"-" + l_id + "_v" + \
str(data[0][VERSION]) + JSON_EXT
if os.path.exists(base_url + file_name):
vehicle_response_data['name'] = data[0]['name']
vehicle_response_data['version'] = data[0]['version']
# vehicle_response_data['vehicle_id'] = data[0]['vehicle_id']
vehicle_response_data['language'] = data[0]['language']
vehicle_response_data['description'] = data[0]['description']
# vehicle_response_data['FileSize'] = get_file_size(
# file_name)
# vehicle_response_data['JsonURL'] = file_name
vehicle_response_data[UPDATE_AVAILABLE] = True
vehicle_response_data[REMARKS] = "Internal available"
else:
vehicle_response_data[UPDATE_AVAILABLE] = False
vehicle_response_data[REMARKS] = "Internal available"
vehicle_response_data[ERROR] = "Failed to read file"
else:
vehicle_response_data[UPDATE_AVAILABLE] = False
vehicle_response_data[REMARKS] = "Internal available"
vehicle_response_data[ERROR] = "Failed to get Publish version"
else:
""" Full Internal File """
data = frappe.db.sql('''SELECT name, format(version,2) as version,vehicle_id, language,
release_description as description FROM `tabPublish` where vehicle='{0}' and language='{1}' and
publish_status='Published' and vehicle_status='Active' and publish_module='Automotive System'
and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System' and publish_type='Internal'
and vehicle='{0}' and language='{1}' );
'''.format(vehicle, l_id), as_dict=1)
if data:
file_name = JSON_FULL_INT_PATH+vehicle+"/"+vehicle + \
"-" + l_id + "-"+"full_v" + \
str(data[0][VERSION]
) + JSON_EXT
if os.path.exists(base_url + file_name):
vehicle_response_data['name'] = data[0]['name']
vehicle_response_data['version'] = data[0]['version']
# vehicle_response_data['vehicle_id'] = data[0]['vehicle_id']
vehicle_response_data['language'] = data[0]['language']
vehicle_response_data['description'] = data[0]['description']
# vehicle_response_data['FileSize'] = get_file_size(
# file_name)
# vehicle_response_data['JsonURL'] = file_name
vehicle_response_data[UPDATE_AVAILABLE] = True
vehicle_response_data[REMARKS] = "Internal Full Update available"
else:
vehicle_response_data[UPDATE_AVAILABLE] = False
vehicle_response_data[REMARKS] = "Internal Full Update available"
vehicle_response_data[ERROR] = "Failed to read file"
else:
vehicle_response_data[UPDATE_AVAILABLE] = False
vehicle_response_data[REMARKS] = "Internal Full Update available"
vehicle_response_data[ERROR] = "Failed to get Publish version"
else:
vehicle_response_data[UPDATE_AVAILABLE] = False
vehicle_response_data[REMARKS] = "No Update available"
elif current_version < float(latest_global_version[0]['version']):
""" Only Global available """
if (float(latest_global_version[0]['version']) - int(current_version)) > 1:
""" Full Global File """
data = frappe.db.sql('''SELECT name,format(version,2) as version,vehicle_id, language,
release_description as description FROM `tabPublish` where vehicle='{0}' and language='{1}' and
publish_status='Published' and vehicle_status='Active' and publish_module='Automotive System'
and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System'
and vehicle='{0}' and language='{1}' and publish_type ='Global');
'''.format(vehicle, l_id), as_dict=1)
if data:
file_name = JSON_FULL_GLOBAL_PATH + vehicle + "/" + vehicle + \
"-" + l_id + "-"+"full_v" + \
str(data[0][VERSION]
) + JSON_EXT
if os.path.exists(base_url + file_name):
vehicle_response_data['name'] = data[0]['name']
vehicle_response_data['version'] = data[0]['version']
# vehicle_response_data['vehicle_id'] = data[0]['vehicle_id']
vehicle_response_data['language'] = data[0]['language']
vehicle_response_data['description'] = data[0]['description']
# vehicle_response_data['FileSize'] = get_file_size(
# file_name)
# vehicle_response_data['JsonURL'] = file_name
vehicle_response_data[UPDATE_AVAILABLE] = True
vehicle_response_data[REMARKS] = "Global Full Update available"
else:
vehicle_response_data[UPDATE_AVAILABLE] = False
vehicle_response_data[REMARKS] = "Global Full Update available"
vehicle_response_data[ERROR] = "Failed to read file"
else:
vehicle_response_data[UPDATE_AVAILABLE] = False
vehicle_response_data[REMARKS] = "Global Full Update available"
vehicle_response_data[ERROR] = "Failed to get Publish version"
# vehicle_response_data[UPDATE_AVAILABLE] = True
# vehicle_response_data[REMARKS] = "Full Update Global available"
else:
""" Single Global File """
# vehicle_response_data[UPDATE_AVAILABLE] = True
# vehicle_response_data[REMARKS] = "Global available"
data = frappe.db.sql('''SELECT name,format(version,2) as version,vehicle_id, language,
release_description as description FROM `tabPublish` where vehicle='{0}' and language='{1}' and
publish_status='Published' and vehicle_status='Active' and publish_module='Automotive System'
and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System'
and vehicle='{0}' and language='{1}' and publish_type ='Global');
'''.format(vehicle, l_id), as_dict=1)
if data:
file_name = JSON_GLOABL_PATH+vehicle+"/"+vehicle + \
"-" + l_id + "_v" + \
str(data[0][VERSION]) + JSON_EXT
if os.path.exists(base_url + file_name):
vehicle_response_data['name'] = data[0]['name']
vehicle_response_data['version'] = data[0]['version']
# vehicle_response_data['vehicle_id'] = data[0]['vehicle_id']
vehicle_response_data['language'] = data[0]['language']
vehicle_response_data['description'] = data[0]['description']
# vehicle_response_data['FileSize'] = get_file_size(
# file_name)
# vehicle_response_data['JsonURL'] = file_name
vehicle_response_data[UPDATE_AVAILABLE] = True
vehicle_response_data[REMARKS] = "Global available"
else:
vehicle_response_data[UPDATE_AVAILABLE] = False
vehicle_response_data[REMARKS] = "Global available"
vehicle_response_data[ERROR] = "Failed to read file"
else:
vehicle_response_data[UPDATE_AVAILABLE] = False
vehicle_response_data[REMARKS] = "Global available"
vehicle_response_data[ERROR] = "Failed to get Publish version"
else:
""" Unknow condition Dont Know Yet """
value = {'latest_publish_version': latest_publish_version[0]['version'],
" latest_global_version": latest_global_version[0]['version']}
frappe.log_error('New check Update', str(
f'Unknow Condition{value}'))
vehicle_response_data[UPDATE_AVAILABLE] = True
vehicle_response_data[REMARKS] = "New Condition"
return vehicle_response_data

1171
smart_service/apis/update_validation.py

File diff suppressed because it is too large

7
smart_service/transactions/doctype/publish/publish.js

@ -446,7 +446,8 @@ frappe.ui.form.on("Publish", {
version: frm.doc.version,
},
callback: function (r) {
// if (r.message[0]) {
debugger
if (r.message[0] == true) {
frm.set_value("publish_status", "Published");
frm.page.clear_primary_action("Publish");
frm.set_value(
@ -476,6 +477,10 @@ frappe.ui.form.on("Publish", {
},
},
});
}
else{
frappe.msgprint('Failed To Publish')
}
},
});
}

30
smart_service/transactions/doctype/publish/publish.py

@ -59,6 +59,7 @@ class Publish(Document):
str(km_mapping.name) + '\n'
def on_submit(self):
if self.docstatus == 1 and self.publish_status == 'To Publish' and self.publish_module == 'Repair service' and self.publish_type == 'Internal':
repair_res_obj = repair_checksheet_publish(self.vehicle, self.vehicle_id,
self.language, self.publish_type,
@ -110,7 +111,7 @@ class Publish(Document):
if self.docstatus == 1 and self.publish_status == 'To Publish' and self.publish_module == 'Special Tool' and self.publish_type == 'Internal':
special_tool_publish(self.vehicle, self.vehicle_id,
self.publish_type,
self.publish_type,
self.release_description,
self.special_tool_publish_docs)
update_publish_status = frappe.db.sql(
@ -128,6 +129,14 @@ class Publish(Document):
update_publish_mapping(self.vehicle, self.variant_mapping,
self.language, self.publish_module, self.publish_type)
if self.publish_type == 'Internal':
frappe.db.sql(
'''update tabVehicle set internal_publish = 1 where vehicle= '{0}'; '''.format(self.vehicle))
else:
frappe.db.sql(
'''update tabVehicle set global_publish = 1 where vehicle= '{0}'; '''.format(self.vehicle))
def on_cancel(self):
# Published document should not allow to cancel
if self.publish_status == "Published":
@ -201,21 +210,21 @@ def update_qwik_published_docs(self):
def update_publish_mapping(vehicle, variant, language, module, publish_type):
# frappe.set_user('Administrator')
try:
frappe.log_error("calling module",str(module))
frappe.log_error("calling module", str(module))
if module == 'Repair service':
pub_data = frappe.db.get_list('Module Publish Mapping', filters={
"vehicle": vehicle,
"language": language,
"publish_type": publish_type
}, fields=['name'])
frappe.log_error("pub_data",str(pub_data))
frappe.log_error("pub_data", str(pub_data))
if len(pub_data) > 0:
for d in pub_data:
if d['name']:
frappe.log_error("kkkkkkkkkk")
frappe.db.sql(
f"""UPDATE `tabModule Publish Mapping` set repairservice_check_sheet='1',publish_type='{publish_type}' where name ='{d['name']}'""")
frappe.db.commit()
elif module == 'Special Tool':
@ -239,7 +248,8 @@ def update_publish_mapping(vehicle, variant, language, module, publish_type):
}, fields=['name'])
if pub_data:
doc = frappe.get_doc('Module Publish Mapping', pub_data[0]['name'])
doc = frappe.get_doc(
'Module Publish Mapping', pub_data[0]['name'])
else:
doc = frappe.get_doc({
'doctype': 'Module Publish Mapping',
@ -262,7 +272,7 @@ def update_publish_mapping(vehicle, variant, language, module, publish_type):
doc.save()
except Exception as e:
frappe.log_error("update_publish_mapping",str(e))
frappe.log_error("update_publish_mapping", str(e))
# def update_publish_status(self):
# try:
@ -1296,8 +1306,8 @@ def qwik_service_data(language, publish_type, variant, parent, vehicle):
qwik_service_details = frappe.db.sql('''select name,variant,vehicle,kilometers,language,service_time,active_status,
pdf,display_order,keywords,my_id from `tabQwik Service` where name='%s';''' %
(parent), as_dict=1)
CLEANR = re.compile('<.*?>')
(parent), as_dict=1)
CLEANR = re.compile('<.*?>')
for q in qwik_service_details:
q['pre_work'] = frappe.db.sql('''select idx as 'display_order', content from `tabQwik Service Content` where parent='%s'
&& content_type = 'Pre-work' order by display_order;''' % (q['name']), as_dict=1)
@ -1413,9 +1423,9 @@ def cal_ver_new_module(vehicle, lang, publish_type, doc):
frappe.db.sql("""update {0}.`tabPublish` set version = "{1}" where name = "{2}";""".format(
current_db_name, v, doc.name))
frappe.db.commit()
return {"status":1,"data":v}
return {"status": 1, "data": v}
except Exception as e:
return {"status":0,"data":"None","error":str(e)}
return {"status": 0, "data": "None", "error": str(e)}
@frappe.whitelist()

Loading…
Cancel
Save