Browse Source

Exception messages handling

master
awsss 2 years ago
parent
commit
cdb7781dd4
  1. 10
      smart_service/apis/addon_api.py
  2. 4
      smart_service/apis/app_user_login.py
  3. 2
      smart_service/apis/master_api.py
  4. 285
      smart_service/apis/publish_api.py
  5. 12
      smart_service/apis/transaction_api.py
  6. 354
      smart_service/apis/update_validation.py
  7. 3
      smart_service/transactions/doctype/publish/publish.json

10
smart_service/apis/addon_api.py

@ -66,7 +66,7 @@ def addon(args=None):
api = {"status": 0, "error": "No such function. Check argument: args"}
except Exception as e:
api = {"status": 0, "error": e}
api = {"status": 0, "error": "Module not available"}
else:
api = {"status": 0, "error": "Parameter:args is null"}
@ -164,7 +164,7 @@ def feedback(args=None, request=None):
i['status'] = False
except Exception as e:
api = {"status": 0, "error": e}
api = {"status": 0, "error": "Failed to fetch feedback"}
return api
elif args == 'post_user_feedback':
@ -206,7 +206,7 @@ def feedback(args=None, request=None):
file_response.append(ret)
api = {"isSuccessful": True, "name": usr_fdbk.name, "files": file_response}
except Exception as e:
api = {"status": 0, "error": e}
api = {"status": 0, "error": "Failed to create Feedback"}
else:
api = {"status": 0, "error": "Check argument: args"}
else:
@ -249,7 +249,7 @@ def model_hit(args=None, request=None):
return {"isSuccessful": True}
except Exception as e:
api = {"status": 0, "error": e}
api = {"status": 0, "error": "Failed to fetch Model hit"}
else:
api = {"status": 0, "error": "Check argument: args"}
else:
@ -297,7 +297,7 @@ def model_usage(args=None, request=None):
return {"isSuccessful": True}
except Exception as e:
api = {"status": 0, "error": e}
api = {"status": 0, "error": "Failed to fetch Model Usage"}
else:
api = {"status": 0, "error": "Check argument: args"}
else:

4
smart_service/apis/app_user_login.py

@ -353,7 +353,7 @@ def grant_user_access(userdata=None, iid=None):
return user_details
except Exception as e1:
return {'status': 0, 'error': e1}
return {'status': 0, 'error': "Failed to verify user"}
@frappe.whitelist(allow_guest=True)
def new_app_user_validation(usr=None, pwd=None,iid=None,device_data=None):
@ -673,7 +673,7 @@ def new_grant_user_access(userdata=None, iid=None):
return user_details
except Exception as e1:
return {'status': 0, 'error': e1}
return {'status': 0, 'error': 'Failed to verify user'}
def generate_keys(user_name):
user_details = frappe.get_doc('User', user_name)

2
smart_service/apis/master_api.py

@ -249,6 +249,6 @@ def masters(args=None, LSD=None):
api = {"status": 0, "error": "Check argument: args"}
except Exception as e:
api = {"status": 0, "error": e}
api = {"status": 0, "error": "Failed to fetch data"}
return api

285
smart_service/apis/publish_api.py

@ -10,11 +10,14 @@ from smart_service.apis.app_user_login import input_validation
current_db_name = frappe.conf.get("db_name")
site_name = cstr(frappe.local.site)
base_url = os.path.expanduser("~") + "/frappe-bench/sites/" + site_name + "/public"
base_url = os.path.expanduser(
"~") + "/frappe-bench/sites/" + site_name + "/public"
internal_path = base_url + '/files/json_files/internal/'
global_path = base_url + '/files/json_files/global/'
full_update_path = base_url + '/files/json_files/full_update/'
class Publish(Document):
pass
@ -35,10 +38,11 @@ def get_parent_map(input_list, parameter):
@frappe.whitelist(allow_guest=True)
def api_procedure(args, publish_type, vehicle, language, version):
val=input_validation(args=args,publish_type=publish_type, vehicle=vehicle, language=language, version=version)
if val!='':
val = input_validation(args=args, publish_type=publish_type,
vehicle=vehicle, language=language, version=version)
if val != '':
return {'status': 0, 'error': "Parameter missing :"+val}
try:
dir1 = base_url + "/files/json_files/"
if not os.path.exists(dir1):
@ -69,7 +73,7 @@ def json_grouping(args, language):
docs_child = frappe.db.get_list('Publish_Docs', filters={'parent': args},
fields=['variant_mapping', 'system', 'sub_system', 'procedure_status',
'procedure_link'])
lang = {'language': language}
variant = set()
system = {}
@ -96,11 +100,11 @@ def json_grouping(args, language):
subsystem[i] = temp_set
final = []
count = 0
count = 0
active_status_case = "CASE WHEN active_status = 'Active' THEN 'True' ELSE 'False' END AS active_status"
for d in variant:
total_count = 0
total_count = 0
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),
@ -109,7 +113,7 @@ def json_grouping(args, language):
var_asset = frappe.db.sql(
'''SELECT category, attach_file as file, %s FROM %s.`tabVariant Mapping_Assets` where category<>'Technical Manual' and parent='%s' and language='%s';''' % (
active_status_case, current_db_name, d, lang['language']), as_dict=True)
vari = vari[0]
if vari['active_status'] == 'Active':
@ -118,8 +122,8 @@ def json_grouping(args, language):
vari['active_status'] = False
kms_mapping_status = None
kms_mapping_status = frappe.db.sql(
'''SELECT active_status FROM {0}.`tabKilometer Mapping` where name LIKE '{1}' and substring(name,-5,2)= '{2}';'''
.format(current_db_name, d + "%", language))
'''SELECT active_status FROM {0}.`tabKilometer Mapping` where name LIKE '{1}' and substring(name,-5,2)= '{2}';'''
.format(current_db_name, d + "%", language))
if kms_mapping_status:
kms_mapping_status = kms_mapping_status[0][0]
@ -133,7 +137,7 @@ def json_grouping(args, language):
variant_out['Variant'] = vari
total_count += len(var_asset)
# total_count += len(variant[d]) - 1
# total_count += len(variant[d]) - 1
system_out = []
for i in system[d]:
if i != None:
@ -215,18 +219,23 @@ def json_grouping(args, language):
frappe.db.commit()
return dicfinal
def print(sts):
frappe.msgprint(str(sts))
""" New Publish """
@frappe.whitelist(allow_guest=True)
def new_publish(args, publish_type, vehicle, language, version):
val=input_validation(args=args,publish_type=publish_type, vehicle=vehicle, language=language, version=version)
if val!='':
val = input_validation(args=args, publish_type=publish_type,
vehicle=vehicle, language=language, version=version)
if val != '':
return {'status': 0, 'error': "Parameter missing :"+val}
# Create Directory for internal,global and full_update publish
list1 = []
try:
try:
try:
if not os.path.exists(internal_path + vehicle + '/'):
os.makedirs(internal_path + vehicle + '/')
@ -238,8 +247,8 @@ def new_publish(args, publish_type, vehicle, language, version):
except Exception as e:
return {"status": 0, "error": "Failed to create Folders"}
#JSON generation
json_file = json_grouping(args,language)
# JSON generation
json_file = json_grouping(args, language)
file_name = '%s-%s_v%s.json' % (vehicle, language, version)
# File name generation
@ -255,22 +264,23 @@ def new_publish(args, publish_type, vehicle, language, version):
outfile.write(json.dumps(json_file))
get_step_total_count(file_name)
# Remove previous internal publish file
# Remove previous internal publish file
if publish_type.lower() == 'internal':
for fil in os.listdir(internal_path + vehicle):
file_val = internal_path + vehicle + '/' + fil
file_val = internal_path + vehicle + '/' + fil
if file_val != file_name:
if (fil.split('-')[1]).split('_')[0] == language:
os.remove(file_val)
# Generate full update file
# Generate full update file
pub_ver = None
prev_update_ver = None
if publish_type.lower() == 'global':
full_update_file_name = full_update_path + vehicle + '/'+ '%s-%s-full_v%s.json' % (vehicle, language, version)
# Since full update is not available for Global version 1
full_update_file_name = full_update_path + vehicle + '/' + \
'%s-%s-full_v%s.json' % (vehicle, language, version)
# Since full update is not available for Global version 1
if version == '1.00':
with open(full_update_file_name, 'w') as outfile:
outfile.write(json.dumps(json_file))
@ -278,24 +288,28 @@ def new_publish(args, publish_type, vehicle, language, version):
else:
pub_ver = frappe.db.sql(''' SELECT vehicle,`language`,version,publish_type FROM tabPublish where vehicle = '{}'
and publish_type = 'Global' AND `language` = '{}' order by version desc limit 2 ;'''.format(vehicle,language),as_dict=True)
and publish_type = 'Global' AND `language` = '{}' order by version desc limit 2 ;'''.format(vehicle, language), as_dict=True)
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)
prev_full_update_file = full_update_path + vehicle + '/' + \
'%s-%s-full_v%s.json' % (vehicle,
language, prev_update_ver)
list1.append(prev_full_update_file)
list1.append(file_name)
list1.append(full_update_file_name)
final_update_file = merge_json_files(prev_full_update_file,file_name,full_update_file_name)
final_update_file = merge_json_files(
prev_full_update_file, file_name, full_update_file_name)
get_step_total_count(final_update_file)
return file_name.split('public')[1]
except:
except:
return "Failed to save file"
@frappe.whitelist(allow_guest=True)
def new_update(vehicle_list=None):
val=input_validation(vehicle_list=vehicle_list)
if val!='':
val = input_validation(vehicle_list=vehicle_list)
if val != '':
return {'status': 0, 'error': "Parameter missing :"+val}
req_list = json.loads(vehicle_list)
vehicle = req_list['Vehicle']
@ -307,14 +321,15 @@ def new_update(vehicle_list=None):
lang = v['LanguageID']
cur_ver = v['CurrentVersion']
# publish_list = frappe.db.sql(''' SELECT vehicle,`language`,version,publish_type FROM tabPublish where vehicle = '{}'
# publish_list = frappe.db.sql(''' SELECT vehicle,`language`,version,publish_type FROM tabPublish where vehicle = '{}'
# and publish_type='Global' AND `language` = '{}';'''.format(vehicle,lang),as_dict=True)
# list_val.append(publish_list)
for f in os.listdir(internal_path + vehicle):
try:
if (f.split('-')[1]).split('_')[0] == lang:
json_data = json.load(open(internal_path + vehicle +'/'+f))
json_data = json.load(
open(internal_path + vehicle + '/'+f))
for d in json_data:
json_val.append(d)
except:
@ -323,36 +338,38 @@ def new_update(vehicle_list=None):
for i in os.listdir(global_path + vehicle):
try:
if (i.split('-')[1]).split('_')[0] == lang:
json_data = json.load(open(global_path + vehicle +'/'+f))
json_data = json.load(open(global_path + vehicle + '/'+f))
for d in json_data:
json_val.append(d)
except:
except:
pass
cumulative_update = global_path + vehicle+ '/' + 'global.json'
with open(cumulative_update,'w') as outfile:
cumulative_update = global_path + vehicle + '/' + 'global.json'
with open(cumulative_update, 'w') as outfile:
outfile.write(json.dumps(json_val))
return json_val
@frappe.whitelist(allow_guest=True)
def merge_json_files(old_json_path,new_json_path,out_file_path):
val=input_validation(old_json_path=old_json_path,new_json_path=new_json_path, out_file_path=out_file_path)
if val!='':
def merge_json_files(old_json_path, new_json_path, out_file_path):
val = input_validation(old_json_path=old_json_path,
new_json_path=new_json_path, out_file_path=out_file_path)
if val != '':
return {'status': 0, 'error': "Parameter missing :"+val}
try:
with open(old_json_path) as json_file:
data_old = json.load(json_file)
with open(new_json_path) as json_file:
data_new = json.load(json_file)
data_consolidated={'JSON':[]}
data_consolidated = {'JSON': []}
# print('Collecting Variants...')
variant_name=set()
sub_system_name=set()
procedure_name=set()
step_name=set()
variant_added=set()
variant_name = set()
sub_system_name = set()
procedure_name = set()
step_name = set()
variant_added = set()
for variant in data_old['JSON']:
variant_name.add(variant['Variant']['name'])
for variant in data_new['JSON']:
@ -361,16 +378,16 @@ def merge_json_files(old_json_path,new_json_path,out_file_path):
for variant_new in data_new['JSON']:
if variant_new['Variant']['name'] in variant_name and variant_new['Variant']['name'] not in variant_added:
system_name=set()
system_added=set()
system_list=[]
variant_asset_name=set()
variant_asset_added=set()
variant_asset_list=[]
system_name = set()
system_added = set()
system_list = []
variant_asset_name = set()
variant_asset_added = set()
variant_asset_list = []
# print(variant_new['Variant'])
try:
variant_new['Variant']['Assets']
for variant_asset in variant_new['Variant']['Assets']:
for variant_asset in variant_new['Variant']['Assets']:
variant_asset_name.add(variant_asset['file'])
if variant_asset['file'] not in variant_asset_added and variant_asset['file'] in variant_asset_name:
variant_asset_list.append(variant_asset)
@ -380,21 +397,21 @@ def merge_json_files(old_json_path,new_json_path,out_file_path):
# print('Assets not present in '+variant_new['Variant']['name'])
try:
variant_new['Variant']['Systems']
for system in variant_new['Variant']['Systems']:
system_asset_name=set()
system_asset_added=set()
system_asset_list=[]
for system in variant_new['Variant']['Systems']:
system_asset_name = set()
system_asset_added = set()
system_asset_list = []
system_name.add(system['system_name'])
if system['system_name'] not in system_added and system['system_name'] in system_name:
sub_system_name=set()
sub_system_added=set()
sub_system_list=[]
sub_system_name = set()
sub_system_added = set()
sub_system_list = []
for subsystem in system['Subsystems']:
sub_system_name.add(subsystem['sub_systems'])
if subsystem['sub_systems'] not in sub_system_added and subsystem['sub_systems'] in sub_system_name:
conf_km_name=set()
conf_km_added=set()
conf_km_list=[]
conf_km_name = set()
conf_km_added = set()
conf_km_list = []
for ck in subsystem['Config Kilometer']:
conf_km_name.add(ck['kilometer_name'])
if ck['kilometer_name'] not in conf_km_added and ck['kilometer_name'] in conf_km_name:
@ -403,40 +420,48 @@ def merge_json_files(old_json_path,new_json_path,out_file_path):
"kilometer_IDX": ck['kilometer_IDX'],
"kilometers_applicable": ck['kilometers_applicable']
})
conf_km_added.add(ck['kilometer_name'])
conf_km_added.add(
ck['kilometer_name'])
for old_variants in data_old['JSON']:
if old_variants['Variant']['name']==variant_new['Variant']['name']:
if old_variants['Variant']['name'] == variant_new['Variant']['name']:
for old_system in old_variants['Variant']['Systems']:
if old_system['system_name']==system['system_name']:
if old_system['system_name'] == system['system_name']:
for old_sub_system in old_system['Subsystems']:
if old_sub_system['sub_systems']==subsystem['sub_systems']:
if old_sub_system['sub_systems'] == subsystem['sub_systems']:
for old_ck in old_sub_system['Config Kilometer']:
conf_km_name.add(old_ck['kilometer_name'])
conf_km_name.add(
old_ck['kilometer_name'])
if old_ck['kilometer_name'] not in conf_km_added and old_ck['kilometer_name'] in conf_km_name:
sub_system_list.append(old_ck)
conf_km_added.add(old_ck['kilometer_name'])
proc_det_name=set()
proc_det_added=set()
proc_det_list=[]
sub_system_list.append(
old_ck)
conf_km_added.add(
old_ck['kilometer_name'])
proc_det_name = set()
proc_det_added = set()
proc_det_list = []
for pd in subsystem['Procedure_details']:
proc_det_name.add(pd['procedure_name'])
if pd['procedure_name'] not in proc_det_added and pd['procedure_name'] in proc_det_name:
proc_det_list.append({
"procedure_name": pd['procedure_name'],
"steps": pd['steps'],
})
proc_det_added.add(pd['procedure_name'])
"procedure_name": pd['procedure_name'],
"steps": pd['steps'],
})
proc_det_added.add(
pd['procedure_name'])
for old_variants in data_old['JSON']:
if old_variants['Variant']['name']==variant_new['Variant']['name']:
if old_variants['Variant']['name'] == variant_new['Variant']['name']:
for old_system in old_variants['Variant']['Systems']:
if old_system['system_name']==system['system_name']:
if old_system['system_name'] == system['system_name']:
for old_sub_system in old_system['Subsystems']:
if old_sub_system['sub_systems']==subsystem['sub_systems']:
if old_sub_system['sub_systems'] == subsystem['sub_systems']:
for old_pd in old_sub_system['Procedure_details']:
proc_det_name.add(old_pd['kilometer_name'])
proc_det_name.add(
old_pd['kilometer_name'])
if old_pd['procedure_name'] not in proc_det_added and old_pd['procedure_name'] in proc_det_name:
sub_system_list.append(old_pd)
proc_det_added.add(old_pd['kilometer_name'])
sub_system_list.append(
old_pd)
proc_det_added.add(
old_pd['kilometer_name'])
sub_system_list.append({"subSystemdisplayorder": subsystem['subSystemdisplayorder'],
"systems": subsystem['systems'],
"sub_systems": subsystem['sub_systems'],
@ -448,53 +473,61 @@ def merge_json_files(old_json_path,new_json_path,out_file_path):
"cover_image": subsystem['cover_image'],
"myid": subsystem['myid'],
"active_status": subsystem['active_status'],
"Config Kilometer":conf_km_list,
"Config Kilometer": conf_km_list,
"procedure_status": subsystem['procedure_status'],
"procedure_link": subsystem['procedure_link'],
"Procedure_details":proc_det_list,
"Procedure_details": proc_det_list,
})
sub_system_added.add(subsystem['sub_systems'])
sub_system_added.add(
subsystem['sub_systems'])
for old_variants in data_old['JSON']:
if old_variants['Variant']['name']==variant_new['Variant']['name']:
if old_variants['Variant']['name'] == variant_new['Variant']['name']:
for old_system in old_variants['Variant']['Systems']:
if old_system['system_name']==system['system_name']:
if old_system['system_name'] == system['system_name']:
for old_sub_system in old_system['Subsystems']:
sub_system_name.add(old_sub_system['sub_systems'])
sub_system_name.add(
old_sub_system['sub_systems'])
if old_sub_system['sub_systems'] not in sub_system_added and old_sub_system['sub_systems'] in sub_system_name:
sub_system_list.append(old_sub_system)
sub_system_added.add(old_sub_system['sub_systems'])
sub_system_list.append(
old_sub_system)
sub_system_added.add(
old_sub_system['sub_systems'])
for asset in system['Assets']:
system_asset_name.add(asset['system_asset'])
if asset['system_asset'] not in system_asset_added and asset['system_asset'] in system_asset_name:
system_asset_list.append({"system_asset": asset['system_asset'],
"systemdisplayorder": asset['systemdisplayorder'],
"active_status": asset['active_status'],
})
system_asset_added.add(asset['system_asset'])
"systemdisplayorder": asset['systemdisplayorder'],
"active_status": asset['active_status'],
})
system_asset_added.add(
asset['system_asset'])
for old_variants in data_old['JSON']:
if old_variants['Variant']['name']==variant_new['Variant']['name']:
if old_variants['Variant']['name'] == variant_new['Variant']['name']:
for old_system in old_variants['Variant']['Systems']:
if old_system['system_name']==system['system_name']:
if old_system['system_name'] == system['system_name']:
for old_system_asset in old_system['Assets']:
system_asset_name.add(old_system_asset['system_asset'])
system_asset_name.add(
old_system_asset['system_asset'])
if old_system_asset['system_asset'] not in system_asset_added and old_system_asset['system_asset'] in system_asset_name:
system_asset_list.append(old_system_asset)
system_asset_added.add(old_system_asset['system_asset'])
system_asset_list.append(
old_system_asset)
system_asset_added.add(
old_system_asset['system_asset'])
system_list.append({"systemdisplayorder": system['systemdisplayorder'],
"system_name": system['system_name'],
"icon_file": system['icon_file'],
"myid": system['myid'],
"active_status": system['active_status'],
"Assets": system_asset_list,
"Subsystems":sub_system_list,
"Config Kilometer":conf_km_list,
})
"Subsystems": sub_system_list,
"Config Kilometer": conf_km_list,
})
system_added.add(system['system_name'])
except:
pass
# print('Systems not present in '+variant_new['Variant']['name'])
for old_variants in data_old['JSON']:
if old_variants['Variant']['name']==variant_new['Variant']['name']:
if old_variants['Variant']['name'] == variant_new['Variant']['name']:
try:
old_variants['Variant']['Systems']
for system in old_variants['Variant']['Systems']:
@ -505,40 +538,41 @@ def merge_json_files(old_json_path,new_json_path,out_file_path):
except:
pass
# print('Systems not present in '+variant_new['Variant']['name'])
data_consolidated['JSON'].append({'Variant':{"name": variant_new['Variant']['name'],
"variant": variant_new['Variant']['variant'],
"vehicle": variant_new['Variant']['vehicle'],
"family_code": variant_new['Variant']['family_code'],
"vehicle_segment": variant_new['Variant']['vehicle_segment'],
"fuel": variant_new['Variant']['fuel'],
"transmission": variant_new['Variant']['transmission'],
"drive": variant_new['Variant']['drive'],
"active_status": variant_new['Variant']['active_status'],
"kms_mapping_active_status": variant_new['Variant']['kms_mapping_active_status'],
"Assets":variant_asset_list,
"Systems": system_list
}})
data_consolidated['JSON'].append({'Variant': {"name": variant_new['Variant']['name'],
"variant": variant_new['Variant']['variant'],
"vehicle": variant_new['Variant']['vehicle'],
"family_code": variant_new['Variant']['family_code'],
"vehicle_segment": variant_new['Variant']['vehicle_segment'],
"fuel": variant_new['Variant']['fuel'],
"transmission": variant_new['Variant']['transmission'],
"drive": variant_new['Variant']['drive'],
"active_status": variant_new['Variant']['active_status'],
"kms_mapping_active_status": variant_new['Variant']['kms_mapping_active_status'],
"Assets": variant_asset_list,
"Systems": system_list
}})
variant_added.add(variant_new['Variant']['name'])
for variant_old in data_old['JSON']:
if variant_old['Variant']['name'] in variant_name and variant_old['Variant']['name'] not in variant_added:
data_consolidated['JSON'].append({'Variant': variant_old['Variant'],
})
})
json_object = json.dumps(data_consolidated)
with open(out_file_path, "w") as outfile:
outfile.write(json_object)
outfile.write(json_object)
return out_file_path
except Exception as e :
return e
except Exception as e:
return "Exception in publish"
def get_step_total_count(json_path):
with open(json_path) as json_file:
data = json.load(json_file)
total_count = calculate_total(data)
generate_json(data,json_path)
generate_json(data, json_path)
return total_count
def generate_json(data,json_path):
def generate_json(data, json_path):
json_object = json.dumps(data)
with open(json_path, "w") as outfile:
outfile.write(json_object)
@ -574,12 +608,3 @@ def calculate_total(data):
variant['TotalCount'] = total_count
variant['StepCount'] = step_count
return data
# def get_data(args):
# try:
# docs_child = frappe.db.get_list('Publish_Docs', filters={'parent': args},
# fields=['variant_mapping', 'system', 'sub_system', 'procedure_status',
# 'procedure_link'])
# except Exception as e:
# return False
# return docs_child

12
smart_service/apis/transaction_api.py

@ -7,16 +7,17 @@ from smart_service.apis.app_user_login import input_validation
current_db_name = frappe.conf.get("db_name")
site_name = cstr(frappe.local.site)
base_url = os.path.expanduser("~") + "/frappe-bench/sites/" + site_name + "/public"
base_url = os.path.expanduser(
"~") + "/frappe-bench/sites/" + site_name + "/public"
@frappe.whitelist()
def get_technical_manual(args=None):
# if args == None:
# return {'status': 0, 'error': "Parameter missing : args"}
val=input_validation(args=args)
if val!='':
return {'status': 0, 'error': "Parameter missing :"+val}
val = input_validation(args=args)
if val != '':
return {'status': 0, 'error': "Parameter missing :"+val}
try:
manual_out = frappe.db.sql('''SELECT parent as variant, language, attach_file as file, active_status,idx as variant_asset_idx FROM {0}.`tabVariant Mapping_Assets` where parent='{1}' and category='Technical Manual'
and parentfield = 'assets';'''.format(current_db_name, args), as_dict=True)
@ -36,5 +37,4 @@ def get_technical_manual(args=None):
return {"status": 1, "error": "Data Not available"}
except Exception as e:
return {"status": 0, "error": e}
return {"status": 0, "error": "Failed to fetch data"}

354
smart_service/apis/update_validation.py

@ -7,7 +7,8 @@ import time
from smart_service.apis.app_user_login import input_validation
current_db_name = frappe.conf.get("db_name")
site_name = cstr(frappe.local.site)
base_url = os.path.expanduser("~") + "/frappe-bench/sites/" + site_name + "/public"
base_url = os.path.expanduser(
"~") + "/frappe-bench/sites/" + site_name + "/public"
def get_parent_map(input_list, parameter):
@ -31,8 +32,8 @@ def get_parent_map(input_list, parameter):
def check_all_vehicle_updates(vehicle_list=None):
# if vehicle_list == None:
# return {"status": 0, "error": "Parameter missing: Vehicle List"}
val=input_validation(vehicle_list=vehicle_list)
if val!='':
val = input_validation(vehicle_list=vehicle_list)
if val != '':
return {"status": 0, "error": "Parameter missing:"+val}
if vehicle_list:
@ -44,7 +45,8 @@ def check_all_vehicle_updates(vehicle_list=None):
iid = v_list['InstallationId']
vehicle_data = v_list['VehicleReqList']
publish_type = frappe.db.sql(
'''SELECT publish_type FROM {}.`tabApp Device` where name='{}';'''.format(current_db_name, iid),
'''SELECT publish_type FROM {}.`tabApp Device` where name='{}';'''.format(
current_db_name, iid),
as_list=True)
if publish_type[0][0] is not None:
@ -67,10 +69,10 @@ def check_all_vehicle_updates(vehicle_list=None):
if current_version < float(data1_global[0]['version']):
data = frappe.db.sql('''SELECT name,max(version) as version,vehicle_id,language FROM {}.tabPublish where vehicle='{}' and language='{}' and publish_status='Published'
and publish_type='Global' and vehicle_status='Active' and version > '{}' order by version ASC;'''.format(
current_db_name, v_id, lang, current_version), as_dict=True)
current_db_name, v_id, lang, current_version), as_dict=True)
elif current_version == float(data1_global[0]['version']):
if current_version < float(data1[0]['version']):
if current_version < float(data1[0]['version']):
data = frappe.db.sql('''SELECT name,max(version) as version,vehicle_id,language FROM {}.tabPublish where vehicle='{}' and language='{}' and publish_status='Published'
and publish_type='{}' and vehicle_status='Active' and version > '{}' order by version ASC;'''.format(
current_db_name, v_id, lang, publish_type[0][0], current_version), as_dict=True)
@ -79,7 +81,8 @@ def check_all_vehicle_updates(vehicle_list=None):
try:
for d in data:
d['IsUpdateAvailable'] = 'true'
d['CurrentVersion'] = float(current_version)
d['CurrentVersion'] = float(
current_version)
data_append.append(d)
Vehicle_req_list.append(data_append)
except:
@ -98,32 +101,34 @@ def check_all_vehicle_updates(vehicle_list=None):
return {"status": 0, "error": "Invalid Publish Details"}
except Exception as e:
return {"status": 0, "error": e}
return {"status": 0, "error": "Failed to fetch updates"}
else:
return {"status": 0, "error": "Check argument: vehicle list"}
@frappe.whitelist()
def check_vehicle_update(vehicle_list=None):
# if vehicle_list == None:
# return {"status": 0, "error": "Parameter missing: Vehicle List"}
val=input_validation(vehicle_list=vehicle_list)
if val!='':
val = input_validation(vehicle_list=vehicle_list)
if val != '':
return {"status": 0, "error": "Parameter missing:"+val}
if vehicle_list:
try:
response = {}
req_list = json.loads(vehicle_list)
response['Vehicle']=req_list['Vehicle']
response['Vehicle'] = req_list['Vehicle']
vehicle = req_list['Vehicle']
iid = req_list['InstallationId']
vehicle_data = req_list['VehicleReqList']
publish_type = frappe.db.get_list('App Device', filters={'name': iid}, fields='publish_type')
publish_type = frappe.db.get_list(
'App Device', filters={'name': iid}, fields='publish_type')
if len(publish_type) > 0:
publish_type = publish_type[0]['publish_type']
Vehicle_req_list = []
# Iterate on language
# Iterate on language
for v in vehicle_data:
l_id = v['LanguageID']
current_version = float(v['CurrentVersion'])
@ -134,12 +139,12 @@ def check_vehicle_update(vehicle_list=None):
data1 = frappe.db.sql('''SELECT name,max(version) as version,vehicle_id,language FROM {}.tabPublish where vehicle='{}' and language='{}' and publish_status='Published'
and vehicle_status='Active' order by version ASC;'''.format(
current_db_name, vehicle, l_id), as_dict=True)
if data1_global[0]['version']:
if data1_global[0]['version']:
if data1[0]['version'] is not None:
if current_version == float(data1[0]['version']):
data1[0]['IsUpdateAvailable'] = "false"
data={}
data['Language']=l_id
data = {}
data['Language'] = l_id
data['IsUpdateAvailable'] = 'false'
data['CurrentVersion'] = float(current_version)
Vehicle_req_list.append(data)
@ -148,82 +153,101 @@ def check_vehicle_update(vehicle_list=None):
if current_version < (float(data1_global[0]['version'])-1.00):
data = frappe.db.sql('''SELECT name as Name,max(version) as Version,vehicle_id as Vehicle,language as Language FROM {}.tabPublish where vehicle='{}' and language='{}' and publish_status='Published'
and publish_type='Global' and vehicle_status='Active' and Version > '{}' order by version ASC;'''.format(
current_db_name, vehicle, l_id, current_version), as_dict=True)
current_db_name, vehicle, l_id, current_version), as_dict=True)
try:
for d in data:
try:
file_name="/files/json_files/full_update/"+vehicle+"/"+vehicle+"-"+d['Language']+"-"+"full_v"+str(d['Version'])+".json"
file_size = os.path.getsize(base_url + file_name)
d['JsonURL']= file_name
d['FileSize']= file_size
d['Error']= None
file_name = "/files/json_files/full_update/"+vehicle+"/"+vehicle + \
"-" + \
d['Language']+"-"+"full_v" + \
str(d['Version'])+".json"
file_size = os.path.getsize(
base_url + file_name)
d['JsonURL'] = file_name
d['FileSize'] = file_size
d['Error'] = None
except:
file_name= None
file_name = None
file_size = None
d['JsonURL']= file_name
d['FileSize']= file_size
d['Error']='File failed to load'
d['JsonURL'] = file_name
d['FileSize'] = file_size
d['Error'] = 'File failed to load'
d['IsUpdateAvailable'] = 'true'
d['CurrentVersion'] = float(current_version)
d['CurrentVersion'] = float(
current_version)
Vehicle_req_list.append(d)
except Exception as e:
Vehicle_req_list.append({"Error":e})
Vehicle_req_list.append(
{"Error": "Update checking Failed"})
elif current_version == (float(data1_global[0]['version'])-1.00):
data = frappe.db.sql('''SELECT name as Name,max(version) as Version,vehicle_id as Vehicle,language as Language FROM {}.tabPublish where vehicle='{}' and language='{}' and publish_status='Published'
and publish_type='Global' and vehicle_status='Active' and Version > '{}' order by version ASC;'''.format(
current_db_name, vehicle, l_id, current_version), as_dict=True)
current_db_name, vehicle, l_id, current_version), as_dict=True)
try:
for d in data:
file_name = None
try:
file_name="/files/json_files/global/"+vehicle+"/"+vehicle+"-"+d['Language']+"_v"+str(d['Version'])+".json"
file_size = os.path.getsize(base_url + file_name)
d['JsonURL']= file_name
d['FileSize']= file_size
d['Error']= None
file_name = "/files/json_files/global/"+vehicle+"/" + \
vehicle+"-" + \
d['Language']+"_v" + \
str(d['Version'])+".json"
file_size = os.path.getsize(
base_url + file_name)
d['JsonURL'] = file_name
d['FileSize'] = file_size
d['Error'] = None
except:
# file_name= None
file_size = None
d['JsonURL']= file_name
d['FileSize']= file_size
d['Error']='File failed to load'
d['JsonURL'] = file_name
d['FileSize'] = file_size
d['Error'] = 'File failed to load'
d['IsUpdateAvailable'] = 'true'
d['CurrentVersion'] = float(current_version)
d['CurrentVersion'] = float(
current_version)
Vehicle_req_list.append(d)
except Exception as e1:
Vehicle_req_list.append({"Error":e1})
Vehicle_req_list.append(
{"Error": "Update checking Failed"})
elif current_version == float(data1_global[0]['version']):
if current_version < float(data1[0]['version']):
if current_version < float(data1[0]['version']):
data = frappe.db.sql('''SELECT name as Name,max(version) as Version,vehicle_id as Vehicle,language as Language FROM {}.tabPublish where vehicle='{}' and language='{}' and publish_status='Published'
and publish_type='{}' and vehicle_status='Active' and version > '{}' order by version ASC;'''.format(
current_db_name, vehicle, l_id, publish_type, current_version), as_dict=True)
try:
for d in data:
try:
file_name="/files/json_files/internal/"+vehicle+"/"+vehicle+"-"+d['Language']+"_v"+str(d['Version'])+".json"
file_size = os.path.getsize(base_url + file_name)
d['JsonURL']= file_name
d['FileSize']= file_size
d['Error']= None
file_name = "/files/json_files/internal/"+vehicle+"/" + \
vehicle+"-" + \
d['Language']+"_v" + \
str(d['Version']) + \
".json"
file_size = os.path.getsize(
base_url + file_name)
d['JsonURL'] = file_name
d['FileSize'] = file_size
d['Error'] = None
except:
file_name= None
file_name = None
file_size = None
d['JsonURL']= file_name
d['FileSize']= file_size
d['Error']='File failed to load'
d['JsonURL'] = file_name
d['FileSize'] = file_size
d['Error'] = 'File failed to load'
d['IsUpdateAvailable'] = 'true'
d['CurrentVersion'] = float(current_version)
d['CurrentVersion'] = float(
current_version)
Vehicle_req_list.append(d)
except Exception as e2:
Vehicle_req_list.append({"Error":e2})
Vehicle_req_list.append(
{"Error": "Update checking Failed"})
elif (float(data1_global[0]['version'])-1.00) < current_version < float(data1_global[0]['version']):
if current_version < float(data1[0]['version']):
@ -233,24 +257,35 @@ def check_vehicle_update(vehicle_list=None):
try:
for d in data:
try:
file_name="/files/json_files/global/"+vehicle+"/"+vehicle+"-"+d['Language']+"_v"+str(d['Version'])+".json"
file_size = os.path.getsize(base_url + file_name)
d['JsonURL']= file_name
d['FileSize']= file_size
d['Error']= None
file_name = "/files/json_files/global/"+vehicle+"/" + \
vehicle+"-" + \
d['Language']+"_v" + \
str(d['Version']) + \
".json"
file_size = os.path.getsize(
base_url + file_name)
d['JsonURL'] = file_name
d['FileSize'] = file_size
d['Error'] = None
except:
file_name= "/files/json_files/global/"+vehicle+"/"+vehicle+"-"+d['Language']+"_v"+str(d['Version'])+".json"
file_name = "/files/json_files/global/"+vehicle+"/" + \
vehicle+"-" + \
d['Language']+"_v" + \
str(d['Version']) + \
".json"
file_size = None
d['JsonURL']= file_name
d['FileSize']= file_size
d['Error']='File failed to load'
d['JsonURL'] = file_name
d['FileSize'] = file_size
d['Error'] = 'File failed to load'
d['IsUpdateAvailable'] = 'true'
d['CurrentVersion'] = float(current_version)
d['CurrentVersion'] = float(
current_version)
Vehicle_req_list.append(d)
except Exception as e2:
Vehicle_req_list.append({"Error":e2})
Vehicle_req_list.append(
{"Error": "Update checking Failed"})
# else:
# Vehicle_req_list.append({"error2":"Else"})
@ -258,28 +293,39 @@ def check_vehicle_update(vehicle_list=None):
if current_version < float(data1[0]['version']):
data = frappe.db.sql('''SELECT name as Name,max(version) as Version,vehicle_id as Vehicle,language as Language FROM {}.tabPublish where vehicle='{}' and language='{}' and publish_status='Published'
and publish_type='{}' and vehicle_status='Active' and version > '{}' order by version ASC;'''.format(
current_db_name, vehicle, l_id,publish_type, current_version), as_dict=True)
current_db_name, vehicle, l_id, publish_type, current_version), as_dict=True)
try:
for d in data:
try:
file_name="/files/json_files/internal/"+vehicle+"/"+vehicle+"-"+d['Language']+"_v"+str(d['Version'])+".json"
file_size = os.path.getsize(base_url + file_name)
d['JsonURL']= file_name
d['FileSize']= file_size
d['Error']= None
file_name = "/files/json_files/internal/"+vehicle+"/" + \
vehicle+"-" + \
d['Language']+"_v" + \
str(d['Version']) + \
".json"
file_size = os.path.getsize(
base_url + file_name)
d['JsonURL'] = file_name
d['FileSize'] = file_size
d['Error'] = None
except:
file_name= "/files/json_files/internal/"+vehicle+"/"+vehicle+"-"+d['Language']+"_v"+str(d['Version'])+".json"
file_name = "/files/json_files/internal/"+vehicle+"/" + \
vehicle+"-" + \
d['Language']+"_v" + \
str(d['Version']) + \
".json"
file_size = None
d['JsonURL']= file_name
d['FileSize']= file_size
d['Error']='File failed to load'
d['JsonURL'] = file_name
d['FileSize'] = file_size
d['Error'] = 'File failed to load'
d['IsUpdateAvailable'] = 'true'
d['CurrentVersion'] = float(current_version)
d['CurrentVersion'] = float(
current_version)
Vehicle_req_list.append(d)
except Exception as e3:
Vehicle_req_list.append({'Error':e3})
Vehicle_req_list.append(
{'Error': "Update checking Failed"})
# else:
# Vehicle_req_list.append({'Error':"Else 3"})
@ -289,28 +335,32 @@ def check_vehicle_update(vehicle_list=None):
else:
data = frappe.db.sql('''SELECT name as Name,max(version) as Version,vehicle_id as Vehicle,language as Language FROM {}.tabPublish where vehicle='{}' and language='{}' and publish_status='Published'
and publish_type='{}' and vehicle_status='Active' and version > '{}' order by version ASC;'''.format(
current_db_name, vehicle, l_id, publish_type, current_version), as_dict=True)
current_db_name, vehicle, l_id, publish_type, current_version), as_dict=True)
try:
for d in data:
try:
file_name="/files/json_files/internal/"+vehicle+"/"+vehicle+"-"+d['Language']+"_v"+str(d['Version'])+".json"
file_size = os.path.getsize(base_url + file_name)
d['JsonURL']= file_name
d['FileSize']= file_size
d['Error']= None
file_name = "/files/json_files/internal/"+vehicle+"/" + \
vehicle+"-"+d['Language'] + \
"_v"+str(d['Version'])+".json"
file_size = os.path.getsize(
base_url + file_name)
d['JsonURL'] = file_name
d['FileSize'] = file_size
d['Error'] = None
except:
file_name= None
file_name = None
file_size = None
d['JsonURL']= file_name
d['FileSize']= file_size
d['Error']='File failed to load'
d['JsonURL'] = file_name
d['FileSize'] = file_size
d['Error'] = 'File failed to load'
d['IsUpdateAvailable'] = 'true'
d['CurrentVersion'] = float(current_version)
Vehicle_req_list.append(d)
except Exception as e2:
Vehicle_req_list.append({"Error":e2})
Vehicle_req_list.append(
{"Error": "Update checking Failed"})
response['Vehicle'] = vehicle
response['VehicleReqList'] = Vehicle_req_list
@ -319,11 +369,12 @@ def check_vehicle_update(vehicle_list=None):
response['JSON'] = {"status": 0, "Error": "Data Not available"}
return response
except Exception as e:
response['JSON'] = {"status": 0, "error": e}
response['JSON'] = {"status": 0, "error": "Update checking Failed"}
return response
else:
return {"status": 0, "error": "Check Parameter: vehicle list"}
def get_step_total_count(json_path):
with open(json_path) as json_file:
data = json.load(json_file)
@ -382,11 +433,10 @@ def calculate_step(data):
return data
@frappe.whitelist()
def check_vehicle_update11(vehicle_list=None):
val=input_validation(vehicle_list=vehicle_list)
if val!='':
val = input_validation(vehicle_list=vehicle_list)
if val != '':
return {"status": 0, "error": "Parameter missing:"+val}
# if vehicle_list == None:
# return {"status": 0, "error": "Parameter missing: Vehicle List"}
@ -395,58 +445,65 @@ def check_vehicle_update11(vehicle_list=None):
if vehicle_list:
response = {}
req_list = json.loads(vehicle_list)
response['Vehicle']=req_list['Vehicle']
response['Vehicle'] = req_list['Vehicle']
vehicle = req_list['Vehicle']
iid = req_list['InstallationId']
vehicle_data = req_list['VehicleReqList']
publish_type = frappe.db.get_list('App Device', filters={'name': iid}, fields='publish_type')
publish_type = frappe.db.get_list(
'App Device', filters={'name': iid}, fields='publish_type')
if len(publish_type) > 0:
publish_type = publish_type[0]['publish_type']
# Iterate over language
# Iterate over language
if publish_type == 'Internal':
for v in vehicle_data:
for v in vehicle_data:
global_ver = frappe.db.sql('''SELECT max(version) as version,publish_type as version,vehicle_id,language FROM {}.tabPublish where vehicle='{}'
and language='{}' and publish_status='Published' and vehicle_status='Active' and publish_type = 'Global' ;'''.format(
current_db_name, vehicle, l_id), as_dict=True)
current_db_name, vehicle, l_id), as_dict=True)
if global_ver:
global_pub_ver = global_pub_ver['version']
l_id = v['LanguageID']
cur_ver = v['CurrentVersion']
pub_ver = get_publish_ver(vehicle,l_id)
pub_ver = get_publish_ver(vehicle, l_id)
if cur_ver == pub_ver['version']:
Vehicle_req_list.append({'Language': l_id, 'IsUpdateAvailable': 'false',
'CurrentVersion': float(cur_ver)})
'CurrentVersion': float(cur_ver)})
# Global File
else:
for v in vehicle_data:
l_id = v['LanguageID']
cur_ver = v['CurrentVersion']
global_pub = frappe.db.sql('''SELECT max(version) as version,publish_type, vehicle_id,language FROM {}.tabPublish where vehicle='{}'
and language='{}' and publish_status='Published' and vehicle_status='Active' and publish_type = 'Global' ;'''.format(
current_db_name, vehicle, l_id), as_dict=True)
current_db_name, vehicle, l_id), as_dict=True)
if global_pub:
if global_pub:
global_pub_ver1 = float(global_pub[0]['version'])
if global_pub_ver1 == cur_ver:
Vehicle_req_list.append({'Language': l_id, 'IsUpdateAvailable': 'false',
'CurrentVersion': float(cur_ver)})
'CurrentVersion': float(cur_ver)})
else:
if cur_ver < global_pub_ver1:
if (global_pub_ver1 - cur_ver) > 1:
file_name="/files/json_files/full_update/"+vehicle+"/"+vehicle+"-"+ l_id +"-" + "full_v" + str(global_pub[0]['version'])+".json"
file_size = os.path.getsize(base_url + file_name)
Vehicle_req_list.append({'Version':global_pub_ver1,'Language': l_id, 'IsUpdateAvailable': 'true','JsonURL':file_name,'FileSize':file_size,
'Error':None,'CurrentVersion': float(cur_ver)})
file_name = "/files/json_files/full_update/"+vehicle+"/"+vehicle + \
"-" + l_id + "-" + "full_v" + \
str(global_pub[0]['version'])+".json"
file_size = os.path.getsize(
base_url + file_name)
Vehicle_req_list.append({'Version': global_pub_ver1, 'Language': l_id, 'IsUpdateAvailable': 'true', 'JsonURL': file_name, 'FileSize': file_size,
'Error': None, 'CurrentVersion': float(cur_ver)})
else:
file_name="/files/json_files/global/"+vehicle+"/"+vehicle+"-"+ l_id + "_v" + str(global_pub[0]['version'])+".json"
file_size = os.path.getsize(base_url + file_name)
Vehicle_req_list.append({'Version':global_pub_ver1,'Language': l_id, 'IsUpdateAvailable': 'true','JsonURL':file_name,'FileSize':file_size,
'Error':None,'CurrentVersion': float(cur_ver)})
file_name = "/files/json_files/global/"+vehicle+"/"+vehicle + \
"-" + l_id + "_v" + \
str(global_pub[0]['version'])+".json"
file_size = os.path.getsize(
base_url + file_name)
Vehicle_req_list.append({'Version': global_pub_ver1, 'Language': l_id, 'IsUpdateAvailable': 'true', 'JsonURL': file_name, 'FileSize': file_size,
'Error': None, 'CurrentVersion': float(cur_ver)})
else:
Vehicle_req_list.append({'Language': l_id, 'IsUpdateAvailable': 'false',
@ -454,11 +511,10 @@ def check_vehicle_update11(vehicle_list=None):
return Vehicle_req_list
def get_publish_ver(vehicle,l_id):
def get_publish_ver(vehicle, l_id):
return frappe.db.sql('''SELECT max(version) as version,publish_type as version,vehicle_id,language FROM {}.tabPublish where vehicle='{}' and language='{}' and
publish_status='Published' and vehicle_status='Active' ;'''.format(
current_db_name, vehicle, l_id), as_dict=True)
current_db_name, vehicle, l_id), as_dict=True)
# @frappe.whitelist()
@ -477,7 +533,7 @@ def get_publish_ver(vehicle,l_id):
# if len(publish_type) > 0:
# publish_type = publish_type[0]['publish_type']
# Vehicle_req_list = []
# # Iterate on language
# # Iterate on language
# for v in vehicle_data:
# appendList = []
# appendDict = {}
@ -491,13 +547,13 @@ def get_publish_ver(vehicle,l_id):
# l_id = v['LanguageID']
# current_version = v['CurrentVersion']
# # Not necessary
# # Not necessary
# if publish_type == 'Internal':
# publish_data = frappe.db.sql('''select name,CAST(version AS DECIMAL(10,2)) as version from {}.tabPublish where vehicle= '{}'
# publish_data = frappe.db.sql('''select name,CAST(version AS DECIMAL(10,2)) as version from {}.tabPublish where vehicle= '{}'
# and language='{}' and publish_type = '{}' and version > {} and vehicle_status = 'Active';
# '''.format(current_db_name, vehicle, l_id, publish_type, current_version), as_dict=True)
# else:
# publish_data = frappe.db.sql('''select name,version,release_description as description from {}.tabPublish where vehicle= '{}'
# publish_data = frappe.db.sql('''select name,version,release_description as description from {}.tabPublish where vehicle= '{}'
# and language='{}' and publish_type = '{}' and version > {} and vehicle_status = 'Active'; '''.format(
# current_db_name, vehicle, l_id, publish_type,
# current_version), as_dict=True)
@ -567,7 +623,7 @@ def get_publish_ver(vehicle,l_id):
# FROM {}.`tabVariant Mapping` WHERE name ='{}' ; '''.format(current_db_name, d),
# as_dict=True)[0]
# var_asset = frappe.db.sql('''SELECT category, attach_file as file, {},idx as variant_asset_idx FROM {}.`tabVariant Mapping_Assets`
# var_asset = frappe.db.sql('''SELECT category, attach_file as file, {},idx as variant_asset_idx FROM {}.`tabVariant Mapping_Assets`
# where category<>'Technical Manual' and parent='{}' and language='{}';'''.format(
# active_status_case, current_db_name, d, l_id), as_dict=True)
@ -598,8 +654,8 @@ def get_publish_ver(vehicle,l_id):
# for i in appendDict[d]:
# if i is not None:
# sys = frappe.db.sql(''' SELECT min(tmss.idx) as systemdisplayorder,ts.system_name,ts.icon_file,ts.myid,ts.active_status FROM
# {0}.`tabSystem Mapping_Sub System` as tmss inner join {0}.`tabSystems` as ts on tmss.systems = ts.system_name
# sys = frappe.db.sql(''' SELECT min(tmss.idx) as systemdisplayorder,ts.system_name,ts.icon_file,ts.myid,ts.active_status FROM
# {0}.`tabSystem Mapping_Sub System` as tmss inner join {0}.`tabSystems` as ts on tmss.systems = ts.system_name
# where tmss.parent LIKE '{1}' and substring(tmss.parent,-5,2) = '{2}' and tmss.systems ='{3}';'''
# .format(current_db_name, str(vari['name'] + "%"), l_id, i),
# as_dict=True)[0]
@ -610,7 +666,7 @@ def get_publish_ver(vehicle,l_id):
# sys['active_status'] = False
# # System Assets
# sysassets = frappe.db.sql('''SELECT idx as systemdisplayorder, system_asset,active_status FROM {3}.`tabSystem Mapping_System Assets`
# sysassets = frappe.db.sql('''SELECT idx as systemdisplayorder, system_asset,active_status FROM {3}.`tabSystem Mapping_System Assets`
# where parent like '{0}%' and language='{1}' and systems='{2}';'''.format(
# d, l_id, i, current_db_name), as_dict=True)
# for sysasset in sysassets:
@ -625,10 +681,10 @@ def get_publish_ver(vehicle,l_id):
# # Sub system
# subsystem_out = []
# for j in appendDict[d][i]:
# subsys = frappe.db.sql('''select `tabSystem Mapping_Sub System`.idx as subSystemdisplayorder, systems,sub_systems, symptom,
# subsys = frappe.db.sql('''select `tabSystem Mapping_Sub System`.idx as subSystemdisplayorder, systems,sub_systems, symptom,
# component, estimate_time as estimated_time, rts, mat, cover_image, `tabSub Systems`.myid,`tabSystem Mapping_Sub System`.active_status,
# `tabSystem Mapping_Sub System`.cover_image from {4}.`tabSystem Mapping_Sub System` inner join {4}.`tabSub Systems` on
# `tabSystem Mapping_Sub System`.sub_systems = `tabSub Systems`.name where `tabSystem Mapping_Sub System`.parent like '{0}-{3}%' and
# `tabSystem Mapping_Sub System`.cover_image from {4}.`tabSystem Mapping_Sub System` inner join {4}.`tabSub Systems` on
# `tabSystem Mapping_Sub System`.sub_systems = `tabSub Systems`.name where `tabSystem Mapping_Sub System`.parent like '{0}-{3}%' and
# systems='{1}' and sub_systems='{2}' and `tabSystem Mapping_Sub System`.active_status = 'Active';'''.format(
# d, i, j, l_id, current_db_name), as_dict=True)
@ -639,17 +695,17 @@ def get_publish_ver(vehicle,l_id):
# else:
# subsys['active_status'] = False
# kms = frappe.db.sql('''SELECT kilometer as kilometer_name, idx as kilometer_IDX, applicable as kilometers_applicable
# FROM {}.`tabKilometer Mapping_Items` where sub_systems='{}' and parent Like '{}' and substring(parent,-5,2) = '{}'
# kms = frappe.db.sql('''SELECT kilometer as kilometer_name, idx as kilometer_IDX, applicable as kilometers_applicable
# FROM {}.`tabKilometer Mapping_Items` where sub_systems='{}' and parent Like '{}' and substring(parent,-5,2) = '{}'
# order by kilometer_IDX;'''.format(current_db_name, j, d + "%",
# l_id),
# as_dict=True)
# total_count += len(kms)
# subsys['Config Kilometer'] = kms
# for k in appendDict[d][i][j]:
# proc_details = frappe.db.sql('''select procedure_name, step_name, content_type,
# proc_details = frappe.db.sql('''select procedure_name, step_name, content_type,
# GROUP_CONCAT(case when content_type='Link' Then system_id else content end) as content,
# GROUP_CONCAT(file) as file,GROUP_CONCAT(DISTINCT idx order by idx) as display_order, idx from {}.tabProcedure_Details
# GROUP_CONCAT(file) as file,GROUP_CONCAT(DISTINCT idx order by idx) as display_order, idx from {}.tabProcedure_Details
# where parent ='{}' group by procedure_name,step_name,content_type,content order by idx asc; '''
# .format(current_db_name, k), as_dict=True)
@ -689,14 +745,14 @@ def get_publish_ver(vehicle,l_id):
# with open(base_url + file_name, 'w') as outfile:
# outfile.write(json.dumps(dicfinal))
# file_size = os.path.getsize(base_url + file_name)
# res['JsonURL'] = file_name
# res['FileSize'] = file_size
# res['Error'] = None
# except:
# res['JsonURL'] = None
# res['FileSize'] = None
@ -707,7 +763,7 @@ def get_publish_ver(vehicle,l_id):
# Vehicle_req_list.append(
# {'Language': l_id, 'IsUpdateAvailable': 'false', 'CurrentVersion': float(current_version)})
# response['Vehicle'] = vehicle
# response['VehicleReqList'] = Vehicle_req_list
# return response
@ -724,28 +780,28 @@ def get_publish_ver(vehicle,l_id):
@frappe.whitelist()
def update_completed(FileName=None):
val=input_validation(vehicle_list=vehicle_list)
if val!='':
val = input_validation(vehicle_list=vehicle_list)
if val != '':
return {"status": 0, "error": "Parameter missing:"+val}
# if FileName == None:
# return {'status': 0, 'error': "Parameter missing: FileName"}
if FileName:
try:
os.remove(base_url + FileName)
return {'isSuccessful': True}
except Exception as e:
return {'isSuccessful': False,"status": 0, 'error': e}
return {'isSuccessful': False, "status": 0, 'error': e}
else:
return {"status": 0, "error": "Parameter: FileName is null"}
@frappe.whitelist()
def delete_complete(doc=None, method=None):
base_url1 = os.path.expanduser("~") + "/frappe-bench/sites/" + site_name + "/public"
base_url1 = os.path.expanduser(
"~") + "/frappe-bench/sites/" + site_name + "/public"
path = base_url1 + '/files/json_files/temp/'
path_file = os.listdir(path)
if path_file:
for file in path_file:
os.remove(str(path) + str(file))

3
smart_service/transactions/doctype/publish/publish.json

@ -89,6 +89,7 @@
{
"fieldname": "vehicle",
"fieldtype": "Link",
"in_standard_filter": 1,
"label": "Vehicle",
"options": "Vehicle",
"reqd": 1,
@ -300,7 +301,7 @@
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2022-08-19 20:36:03.516687",
"modified": "2022-10-18 16:02:09.597920",
"modified_by": "Administrator",
"module": "Transactions",
"name": "Publish",

Loading…
Cancel
Save