diff --git a/smart_service/apis/publish_api.py b/smart_service/apis/publish_api.py index 92add16..0d1b005 100644 --- a/smart_service/apis/publish_api.py +++ b/smart_service/apis/publish_api.py @@ -16,6 +16,9 @@ base_url = os.path.expanduser( 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/' +STATUS = 'status' +ERROR = 'error' +PARAM_MISSING = "Parameter missing :" def custom_rate_limit(limit, seconds): @@ -58,7 +61,7 @@ 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 != '': - return {'status': 0, 'error': "Parameter missing :"+val} + return {STATUS: 0, ERROR: PARAM_MISSING+val} try: dir1 = base_url + "/files/json_files/" @@ -242,10 +245,6 @@ def json_grouping(args, language): return dicfinal -def print(sts): - frappe.msgprint(str(sts)) - - """ New Publish """ @@ -257,9 +256,9 @@ 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 != '': - return {'status': 0, 'error': "Parameter missing :"+val} - # Create Directory for internal,global and full_update publish - # list1 = [] + return {STATUS: 0, ERROR: PARAM_MISSING+val} + """ Create Directory for internal,global and full_update publish """ + try: try: if not os.path.exists(internal_path + vehicle + '/'): @@ -270,26 +269,27 @@ def new_publish(args, publish_type, vehicle, language, version): os.makedirs(full_update_path + vehicle + '/') except Exception as e: - return {"status": 0, "error": "Failed to create Folders"} + return {STATUS: 0, ERROR: "Failed to create Folders "} - # JSON generation + """ JSON generation """ json_file = json_grouping(args, language) file_name = '' base_file_name = '%s-%s_v%s.json' % (vehicle, language, version) - # File name generation + + """ File name generation """ if publish_type.lower() == 'internal': file_name = internal_path + vehicle + '/' + base_file_name elif publish_type.lower() == 'global': file_name = global_path + vehicle + '/' + base_file_name else: - return {"status": 0, 'error': 'Publish type not available'} + return {STATUS: 0, ERROR: 'Publish type not available'} - # Save file (Internal/Global) + """ Save file (Internal/Global) """ with open(file_name, 'w') as outfile: 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 @@ -297,17 +297,22 @@ def new_publish(args, publish_type, vehicle, language, version): 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 - if version == 1.00: + + new_full_update_file_name = full_update_path + vehicle + '/' + \ + '%s-%s-full_update.json' % (vehicle, language) + """ 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)) - + with open(new_full_update_file_name, 'w') as outfile: + outfile.write(json.dumps(json_file)) # get_step_total_count(full_update_file_name) else: @@ -318,14 +323,13 @@ def new_publish(args, publish_type, vehicle, language, version): prev_full_update_file = full_update_path + vehicle + '/' + \ '%s-%s-full_v%s.json' % (vehicle, language, prev_update_ver) - + # test_full_update_file_name = '/home/ubuntu/frappe-bench/sites/guidedsmartservice.com/public/files/json_files/full_update/XUV 0613/XUV 0613-en-full_update.json' file_flag, final_update_file = merge_json_files( prev_full_update_file, file_name, full_update_file_name) - # if file_flag: - # return True, file_name.split('public')[1] - # else: - # return False, final_update_file - # get_step_total_count(final_update_file) + # return prev_full_update_file, file_name, new_full_update_file_name + # file_flag, final_update_file = new_merge_json_files( + # prev_full_update_file, file_name, new_full_update_file_name) + return file_flag, final_update_file return True, file_name.split('public')[1] except Exception as e: @@ -335,17 +339,23 @@ def new_publish(args, publish_type, vehicle, language, version): @frappe.whitelist(allow_guest=True) def merge_json_files(old_json_path, new_json_path, out_file_path): + # old_json_path = '/home/ubuntu/frappe-bench/sites/guidedsmartservice.com/public/files/json_files/full_update/XUV 0613/XUV 0613-en-full_v1.0.json' + # new_json_path = '/home/ubuntu/frappe-bench/sites/guidedsmartservice.com/public/files/json_files/global/XUV 0613/XUV 0613-en_v2.00.json' + # out_file_path = '/home/ubuntu/frappe-bench/sites/guidedsmartservice.com/public/files/json_files/full_update/XUV 0613/XUV 0613-en-full_update_test.json' + + # return old_json_path,new_json_path,out_file_path # rate_res = custom_rate_limit(limit=5, seconds=15) # if rate_res != 1: # return rate_res # 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} + # return {status: 0, error: "Parameter missing :" + val} try: with open(old_json_path, 'r') as json_file: data_old = json.load(json_file) + # return data_old with open(new_json_path, 'r') as json_file1: data_new = json.load(json_file1) @@ -377,7 +387,6 @@ def merge_json_files(old_json_path, new_json_path, out_file_path): variant_asset_added.add(variant_asset['file']) except: pass - # print('Assets not present in '+variant_new['Variant']['name']) try: # variant_new['Variant']['Systems'] for system in variant_new['Variant']['Systems']: @@ -514,7 +523,6 @@ def merge_json_files(old_json_path, new_json_path, out_file_path): 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']: try: @@ -526,7 +534,7 @@ def merge_json_files(old_json_path, new_json_path, out_file_path): system_added.add(system['system_name']) 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'], @@ -547,8 +555,224 @@ def merge_json_files(old_json_path, new_json_path, out_file_path): 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) + + return True, out_file_path + except Exception as e: + return False, frappe.get_traceback() + # return "Exception in publish" + + +@frappe.whitelist(allow_guest=True) +def new_merge_json_files(old_json_path, new_json_path, out_file_path): + + try: + with open(old_json_path, 'r') as json_file: + data_old = json.load(json_file) + with open(new_json_path, 'r') as json_file1: + data_new = json.load(json_file1) + + data_consolidated = {'JSON': []} + + variant_name = set() + sub_system_name = set() + variant_added = set() + for variant in data_old['JSON']: + variant_name.add(variant['Variant']['name']) + for variant in data_new['JSON']: + variant_name.add(variant['Variant']['name']) + + 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 = [] + try: + # 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) + variant_asset_added.add(variant_asset['file']) + except: + pass + try: + # variant_new['Variant']['Systems'] + 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 = [] + 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 = [] + 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: + conf_km_list.append({ + "kilometer_name": ck['kilometer_name'], + "kilometer_IDX": ck['kilometer_IDX'], + "kilometers_applicable": ck['kilometers_applicable'] + }) + conf_km_added.add( + ck['kilometer_name']) + for old_variants in data_old['JSON']: + 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']: + for old_sub_system in old_system['Subsystems']: + 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']) + 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 = [] + 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']) + for old_variants in data_old['JSON']: + 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']: + for old_sub_system in old_system['Subsystems']: + 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']) + 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({"subSystemdisplayorder": subsystem['subSystemdisplayorder'], + "systems": subsystem['systems'], + "sub_systems": subsystem['sub_systems'], + "symptom": subsystem['symptom'], + "component": subsystem['component'], + "estimated_time": subsystem['estimated_time'], + "rts": subsystem['rts'], + "mat": subsystem['mat'], + "cover_image": subsystem['cover_image'], + "myid": subsystem['myid'], + "active_status": subsystem['active_status'], + "Config Kilometer": conf_km_list, + "procedure_status": subsystem['procedure_status'], + "procedure_link": subsystem['procedure_link'], + "Procedure_details": proc_det_list, + }) + sub_system_added.add( + subsystem['sub_systems']) + for old_variants in data_old['JSON']: + 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']: + for old_sub_system in old_system['Subsystems']: + 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']) + 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']) + for old_variants in data_old['JSON']: + 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']: + for old_system_asset in old_system['Assets']: + 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_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, + }) + system_added.add(system['system_name']) + except: + pass + for old_variants in data_old['JSON']: + if old_variants['Variant']['name'] == variant_new['Variant']['name']: + try: + old_variants['Variant']['Systems'] + for system in old_variants['Variant']['Systems']: + system_name.add(system['system_name']) + if system['system_name'] not in system_added and system['system_name'] in system_name: + system_list.append(system) + system_added.add(system['system_name']) + except: + pass + + 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'], + }) + return True, data_consolidated json_object = json.dumps(data_consolidated) - # return True, json_object with open(out_file_path, "w") as outfile: outfile.write(json_object) @@ -565,16 +789,14 @@ def new_update(vehicle_list=None): return rate_res val = input_validation(vehicle_list=vehicle_list) if val != '': - return {'status': 0, 'error': "Parameter missing :"+val} + return {STATUS: 0, ERROR: PARAM_MISSING+val} req_list = json.loads(vehicle_list) vehicle = req_list['Vehicle'] - iid = req_list['InstallationId'] vehicle_data = req_list['VehicleReqList'] - list_val = [] json_val = [] for v in vehicle_data: lang = v['LanguageID'] - cur_ver = v['CurrentVersion'] + # cur_ver = v['CurrentVersion'] # 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) @@ -654,6 +876,7 @@ def calculate_total(data): @frappe.whitelist() def upv(): - frappe.db.sql( - f'''update `tabPublish` set version = 1.00 where name = 'THAR-en -2023-05-21 16:57:54.119826';''') - frappe.db.commit() + # frappe.db.sql( + # f'''update `tabPublish` set version = 1.00 where name = 'THAR-en -2023-05-21 16:57:54.119826';''') + # frappe.db.commit() + return 1 diff --git a/smart_service/apis/update_validation.py b/smart_service/apis/update_validation.py index 96f586a..b4e1fba 100644 --- a/smart_service/apis/update_validation.py +++ b/smart_service/apis/update_validation.py @@ -11,13 +11,21 @@ base_url = os.path.expanduser( "~") + "/frappe-bench/sites/" + site_name + "/public" # Constants -json_ext = ".json" -json_internal_path = "/files/json_files/internal/" -json_global_path = "/files/json_files/global/" -json_full_update_path = "/files/json_files/full_update/" -status = "status" -error = "error" -update_available = 'IsUpdateAvailable' +JSON_EXT = ".json" +JSON_INT_PATH = "/files/json_files/internal/" +JSON_GLOABL_PATH = "/files/json_files/global/" +JSON_FULL_UPDATE_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' +FILE_ERROR = 'File failed to load' +LANGUAGE = 'Language' +FILE_SIZE = 'FileSize' +JSON_URL = 'JsonURL' def custom_rate_limit(limit, seconds): @@ -61,10 +69,10 @@ def check_all_vehicle_updates(vehicle_list=None): if rate_res != 1: return rate_res # if vehicle_list == None: - # return {status: 0, error: "Parameter missing: Vehicle List"} + # return {STATUS: 0, ERROR: "Parameter missing: Vehicle List"} val = input_validation(vehicle_list=vehicle_list) if val != '': - return {status: 0, error: "Parameter missing:"+val} + return {STATUS: 0, ERROR: PARAM_MISSING+val} if vehicle_list: try: @@ -81,7 +89,7 @@ def check_all_vehicle_updates(vehicle_list=None): if vehicle_data: for v in vehicle_data: v_id = v['Vehicle'] - current_version = float(v['CurrentVersion']) + current_version = float(v[CUR_VERSION]) data1_global = frappe.db.sql('''SELECT name,format(max(version),2) as version,vehicle_id,language FROM `tabPublish` where vehicle='{}' and language='{}' and publish_status='Published' and publish_type='Global' and vehicle_status='Active' order by version ASC;'''.format(v_id, lang), as_dict=1) @@ -91,7 +99,7 @@ def check_all_vehicle_updates(vehicle_list=None): if data1[0]['version'] is not None: if current_version == float(data1[0]['version']): - data1[0][update_available] = "false" + data1[0][UPDATE_AVAILABLE] = "false" vehicle_req_list.append(data1) else: if current_version < float(data1_global[0]['version']): @@ -108,8 +116,8 @@ def check_all_vehicle_updates(vehicle_list=None): data_append = [] try: for d in data: - d[update_available] = 'true' - d['CurrentVersion'] = float( + d[UPDATE_AVAILABLE] = 'true' + d[CUR_VERSION] = float( current_version) data_append.append(d) vehicle_req_list.append(data_append) @@ -122,16 +130,16 @@ def check_all_vehicle_updates(vehicle_list=None): response['VehicleReqList'] = vehicle_req_list[0] return response else: - return {status: 0, error: "No Vehicles in criteria"} + return {STATUS: 0, ERROR: "No Vehicles in criteria"} else: - return {status: 0, error: "Invalid Publish Details"} + return {STATUS: 0, ERROR: "Invalid Publish Details"} else: - return {status: 0, error: "Invalid Publish Details"} + return {STATUS: 0, ERROR: "Invalid Publish Details"} except Exception as e: - return {status: 0, error: "Failed to fetch updates"} + return {STATUS: 0, ERROR: "Failed to fetch updates"} else: - return {status: 0, error: "Check argument: vehicle list"} + return {STATUS: 0, ERROR: "Check argument: vehicle list"} @frappe.whitelist() @@ -140,10 +148,10 @@ def check_vehicle_update(vehicle_list=None): if rate_res != 1: return rate_res # if vehicle_list == None: - # return {status: 0, error: "Parameter missing: Vehicle List"} + # return {STATUS: 0, ERROR: "Parameter missing: Vehicle List"} val = input_validation(vehicle_list=vehicle_list) if val != '': - return {status: 0, error: "Parameter missing:"+val} + return {STATUS: 0, ERROR: PARAM_MISSING+val} if vehicle_list: try: @@ -162,7 +170,7 @@ def check_vehicle_update(vehicle_list=None): # Iterate on language for v in vehicle_data: l_id = v['LanguageID'] - current_version = float(v['CurrentVersion']) + current_version = float(v[CUR_VERSION]) data1_global = frappe.db.sql('''SELECT name,format(max(version),2) as version,vehicle_id,language FROM `tabPublish` where vehicle='{}' and language='{}' and publish_status='Published' and publish_type='Global' and vehicle_status='Active' order by version ASC;'''.format(vehicle, l_id), as_dict=1) @@ -173,11 +181,11 @@ def check_vehicle_update(vehicle_list=None): if data1_global[0]['version']: if data1[0]['version'] is not None: if current_version == float(data1[0]['version']): - data1[0][update_available] = "false" + data1[0][UPDATE_AVAILABLE] = "false" data = {} - data['Language'] = l_id - data[update_available] = 'false' - data['CurrentVersion'] = float(current_version) + data[LANGUAGE] = l_id + data[UPDATE_AVAILABLE] = 'false' + data[CUR_VERSION] = float(current_version) vehicle_req_list.append(data) else: @@ -188,63 +196,65 @@ def check_vehicle_update(vehicle_list=None): try: for d in data: try: - file_name = json_full_update_path+vehicle+"/"+vehicle + \ + file_name = JSON_FULL_UPDATE_PATH+vehicle+"/"+vehicle + \ "-" + \ - d['Language']+"-"+"full_v" + \ - str(d['Version'])+json_ext + d[LANGUAGE]+"-"+"full_v" + \ + str(d[VERSION])+JSON_EXT file_size = os.path.getsize( base_url + file_name) - d['JsonURL'] = file_name - d['FileSize'] = file_size + d[JSON_URL] = file_name + d[FILE_SIZE] = file_size d['Error'] = None + d[UPDATE_AVAILABLE] = 'true' - except: + except Exception as e: file_name = None file_size = None - d['JsonURL'] = file_name - d['FileSize'] = file_size - d['Error'] = 'File failed to load' + d[JSON_URL] = file_name + d[FILE_SIZE] = file_size + d['Error'] = e + d[UPDATE_AVAILABLE] = 'false' - d[update_available] = 'true' - d['CurrentVersion'] = float( + d[CUR_VERSION] = float( current_version) vehicle_req_list.append(d) except Exception as e: vehicle_req_list.append( - {error: "Update checking Failed"}) + {ERROR: UPDATE_FAILED}) elif current_version == (float(data1_global[0]['version'])-1.00): data = frappe.db.sql('''SELECT name as Name,format(max(version),2) 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(vehicle, l_id, current_version), as_dict=1) + where vehicle='{}' and language='{}' and publish_status='Published' and publish_type='Global' and vehicle_status='Active' + and Version > '{}' order by version ASC;'''.format(vehicle, l_id, current_version), as_dict=1) try: for d in data: file_name = None try: - file_name = json_global_path+vehicle+"/" + \ + file_name = JSON_GLOABL_PATH+vehicle+"/" + \ vehicle+"-" + \ - d['Language']+"_v" + \ - str(d['Version'])+json_ext + d[LANGUAGE]+"_v" + \ + str(d[VERSION])+JSON_EXT file_size = os.path.getsize( base_url + file_name) - d['JsonURL'] = file_name - d['FileSize'] = file_size + d[JSON_URL] = file_name + d[FILE_SIZE] = file_size d['Error'] = None + d[UPDATE_AVAILABLE] = 'true' - except: + except Exception as e: # file_name= None file_size = None - d['JsonURL'] = file_name - d['FileSize'] = file_size - d['Error'] = 'File failed to load' + d[JSON_URL] = file_name + d[FILE_SIZE] = file_size + d['Error'] = e + d[UPDATE_AVAILABLE] = 'false' - d[update_available] = 'true' - d['CurrentVersion'] = float( + d[CUR_VERSION] = float( current_version) vehicle_req_list.append(d) except Exception as e1: vehicle_req_list.append( - {error: "Update checking Failed"}) + {ERROR: UPDATE_FAILED}) elif current_version == float(data1_global[0]['version']): if current_version < float(data1[0]['version']): @@ -254,31 +264,32 @@ def check_vehicle_update(vehicle_list=None): try: for d in data: try: - file_name = json_internal_path+vehicle+"/" + \ + file_name = JSON_INT_PATH+vehicle+"/" + \ vehicle+"-" + \ - d['Language']+"_v" + \ - str(d['Version']) + \ - json_ext + d[LANGUAGE]+"_v" + \ + str(d[VERSION]) + \ + JSON_EXT file_size = os.path.getsize( base_url + file_name) - d['JsonURL'] = file_name - d['FileSize'] = file_size + d[JSON_URL] = file_name + d[FILE_SIZE] = file_size d['Error'] = None + d[UPDATE_AVAILABLE] = 'true' - except: + except Exception as e: file_name = None file_size = None - d['JsonURL'] = file_name - d['FileSize'] = file_size - d['Error'] = 'File failed to load' + d[JSON_URL] = file_name + d[FILE_SIZE] = file_size + d['Error'] = e + d[UPDATE_AVAILABLE] = 'false' - d[update_available] = 'true' - d['CurrentVersion'] = float( + d[CUR_VERSION] = float( current_version) vehicle_req_list.append(d) except Exception as e2: vehicle_req_list.append( - {error: "Update checking Failed"}) + {ERROR: UPDATE_FAILED}) elif (float(data1_global[0]['version'])-1.00) < current_version < float(data1_global[0]['version']): if current_version < float(data1[0]['version']): @@ -288,37 +299,36 @@ def check_vehicle_update(vehicle_list=None): try: for d in data: try: - file_name = json_global_path+vehicle+"/" + \ + file_name = JSON_GLOABL_PATH+vehicle+"/" + \ vehicle+"-" + \ - d['Language']+"_v" + \ - str(d['Version']) + \ - json_ext + d[LANGUAGE]+"_v" + \ + str(d[VERSION]) + \ + JSON_EXT file_size = os.path.getsize( base_url + file_name) - d['JsonURL'] = file_name - d['FileSize'] = file_size + d[JSON_URL] = file_name + d[FILE_SIZE] = file_size d['Error'] = None + d[UPDATE_AVAILABLE] = 'true' - except: - file_name = json_global_path+vehicle+"/" + \ + except Exception as e: + file_name = JSON_GLOABL_PATH+vehicle+"/" + \ vehicle+"-" + \ - d['Language']+"_v" + \ - str(d['Version']) + \ - json_ext + d[LANGUAGE]+"_v" + \ + str(d[VERSION]) + \ + JSON_EXT file_size = None - d['JsonURL'] = file_name - d['FileSize'] = file_size - d['Error'] = 'File failed to load' + d[JSON_URL] = file_name + d[FILE_SIZE] = file_size + d['Error'] = e + d[UPDATE_AVAILABLE] = 'false' - d[update_available] = 'true' - d['CurrentVersion'] = float( + d[CUR_VERSION] = float( current_version) vehicle_req_list.append(d) except Exception as e2: vehicle_req_list.append( - {error: "Update checking Failed"}) - # else: - # vehicle_req_list.append({"error2":"Else"}) + {ERROR: UPDATE_FAILED}) elif current_version > float(data1_global[0]['version']): if current_version < float(data1[0]['version']): @@ -328,41 +338,42 @@ def check_vehicle_update(vehicle_list=None): try: for d in data: try: - file_name = json_internal_path+vehicle+"/" + \ + file_name = JSON_INT_PATH+vehicle+"/" + \ vehicle+"-" + \ - d['Language']+"_v" + \ - str(d['Version']) + \ - json_ext + d[LANGUAGE]+"_v" + \ + str(d[VERSION]) + \ + JSON_EXT file_size = os.path.getsize( base_url + file_name) - d['JsonURL'] = file_name - d['FileSize'] = file_size + d[JSON_URL] = file_name + d[FILE_SIZE] = file_size d['Error'] = None + d[UPDATE_AVAILABLE] = 'true' - except: - file_name = json_internal_path+vehicle+"/" + \ + except Exception as e: + file_name = JSON_INT_PATH+vehicle+"/" + \ vehicle+"-" + \ - d['Language']+"_v" + \ - str(d['Version']) + \ - json_ext + d[LANGUAGE]+"_v" + \ + str(d[VERSION]) + \ + JSON_EXT file_size = None - d['JsonURL'] = file_name - d['FileSize'] = file_size - d['Error'] = 'File failed to load' + d[JSON_URL] = file_name + d[FILE_SIZE] = file_size + d['Error'] = e + d[UPDATE_AVAILABLE] = 'false' - d[update_available] = 'true' - d['CurrentVersion'] = float( + d[CUR_VERSION] = float( current_version) vehicle_req_list.append(d) except Exception as e3: vehicle_req_list.append( - {'Error': "Update checking Failed"}) + {'Error': UPDATE_FAILED}) # else: # vehicle_req_list.append({'Error':"Else 3"}) else: vehicle_req_list.append( - {'Language': l_id, update_available: 'false', 'CurrentVersion': float(current_version)}) + {LANGUAGE: l_id, UPDATE_AVAILABLE: 'false', CUR_VERSION: float(current_version)}) else: data = frappe.db.sql('''SELECT name as Name,format(max(version),2) 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' @@ -370,40 +381,41 @@ def check_vehicle_update(vehicle_list=None): try: for d in data: try: - file_name = json_internal_path+vehicle+"/" + \ - vehicle+"-"+d['Language'] + \ - "_v"+str(d['Version'])+json_ext + file_name = JSON_INT_PATH+vehicle+"/" + \ + vehicle+"-"+d[LANGUAGE] + \ + "_v"+str(d[VERSION])+JSON_EXT file_size = os.path.getsize( base_url + file_name) - d['JsonURL'] = file_name - d['FileSize'] = file_size + d[JSON_URL] = file_name + d[FILE_SIZE] = file_size d['Error'] = None + d[UPDATE_AVAILABLE] = 'true' except: file_name = None file_size = None - d['JsonURL'] = file_name - d['FileSize'] = file_size - d['Error'] = 'File failed to load' + d[JSON_URL] = file_name + d[FILE_SIZE] = file_size + d['Error'] = FILE_ERROR + d[UPDATE_AVAILABLE] = 'false' - d[update_available] = 'true' - d['CurrentVersion'] = float(current_version) + d[CUR_VERSION] = float(current_version) vehicle_req_list.append(d) except Exception as e2: vehicle_req_list.append( - {error: "Update checking Failed"}) + {ERROR: UPDATE_FAILED}) response['Vehicle'] = vehicle response['VehicleReqList'] = vehicle_req_list return response else: - response['JSON'] = {status: 0, error: "Data Not available"} + response['JSON'] = {STATUS: 0, ERROR: "Data Not available"} return response except Exception as e: - response['JSON'] = {status: 0, error: "Update checking Failed"} + response['JSON'] = {STATUS: 0, ERROR: UPDATE_FAILED} return response else: - return {status: 0, error: "Check Parameter: vehicle list"} + return {STATUS: 0, ERROR: "Check Parameter: vehicle list"} def get_step_total_count(json_path): @@ -464,84 +476,6 @@ def calculate_step(data): return data -@frappe.whitelist() -def check_vehicle_update11(vehicle_list=None): - 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"} - vehicle_req_list = [] - - if vehicle_list: - response = {} - req_list = json.loads(vehicle_list) - 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') - - if len(publish_type) > 0: - publish_type = publish_type[0]['publish_type'] - # Iterate over language - if publish_type == 'Internal': - for v in vehicle_data: - global_ver = frappe.db.sql('''SELECT format(max(version),2) 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(vehicle, l_id), as_dict=1) - - 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) - if cur_ver == pub_ver['version']: - vehicle_req_list.append({'Language': l_id, update_available: 'false', - '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 format(max(version),2) 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(vehicle, l_id), as_dict=1) - - if global_pub: - global_pub_ver1 = float(global_pub[0]['version']) - - if global_pub_ver1 == cur_ver: - vehicle_req_list.append({'Language': l_id, update_available: 'false', - 'CurrentVersion': float(cur_ver)}) - else: - if cur_ver < global_pub_ver1: - if (global_pub_ver1 - cur_ver) > 1: - file_name = json_full_update_path+vehicle+"/"+vehicle + \ - "-" + l_id + "-" + "full_v" + \ - str(global_pub[0]['version'])+json_ext - file_size = os.path.getsize( - base_url + file_name) - vehicle_req_list.append({'Version': global_pub_ver1, 'Language': l_id, update_available: 'true', 'JsonURL': file_name, 'FileSize': file_size, - 'Error': None, 'CurrentVersion': float(cur_ver)}) - else: - file_name = json_global_path+vehicle+"/"+vehicle + \ - "-" + l_id + "_v" + \ - str(global_pub[0]['version'])+json_ext - file_size = os.path.getsize( - base_url + file_name) - vehicle_req_list.append({'Version': global_pub_ver1, 'Language': l_id, update_available: 'true', 'JsonURL': file_name, 'FileSize': file_size, - 'Error': None, 'CurrentVersion': float(cur_ver)}) - - else: - vehicle_req_list.append({'Language': l_id, update_available: 'false', - 'CurrentVersion': float(cur_ver)}) - return vehicle_req_list - - def get_publish_ver(vehicle, l_id): return frappe.db.sql('''SELECT format(max(version),2) as version,publish_type as version,vehicle_id,language FROM `tabPublish` where vehicle='{}' and language='{}' and publish_status='Published' and vehicle_status='Active' ;'''.format(vehicle, l_id), as_dict=1) @@ -554,16 +488,16 @@ def update_completed(FileName=None): return rate_res val = input_validation(FileName=FileName) if val != '': - return {status: 0, error: "Parameter missing:"+val} + return {STATUS: 0, ERROR: "Parameter missing:"+val} 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"} + return {STATUS: 0, ERROR: "Parameter: FileName is null"} @frappe.whitelist() diff --git a/smart_service/masters/doctype/service_kilometers/service_kilometers.js b/smart_service/masters/doctype/service_kilometers/service_kilometers.js index d17712d..eb17805 100644 --- a/smart_service/masters/doctype/service_kilometers/service_kilometers.js +++ b/smart_service/masters/doctype/service_kilometers/service_kilometers.js @@ -31,7 +31,7 @@ frappe.ui.form.on('Service Kilometers', { var regex = /[!@#$%^&*()_+\=\[\]{};~`':"\\|.<>\/?]+/; if (frm.doc.kilometer) { if (regex.test(frm.doc.kilometer) === true) { - frappe.throw(__("Service Kilometer: Only letters, numbers and , are allowed.")); + frappe.throw(__("Service Kilometer: Only letters, numbers and / - , are allowed.")); frappe.validated = false; } else if ((frm.doc.kilometer.includes("'"))) { frappe.throw(__("Service Kilometer: Only letters, numbers and , are allowed.")); diff --git a/smart_service/masters/doctype/vehicle/vehicle.js b/smart_service/masters/doctype/vehicle/vehicle.js index 21e1e2b..98bd452 100644 --- a/smart_service/masters/doctype/vehicle/vehicle.js +++ b/smart_service/masters/doctype/vehicle/vehicle.js @@ -88,7 +88,7 @@ frappe.ui.form.on('Vehicle', { frappe.msgprint(__("Just a . is not prescribed!")); frappe.validated = false; } - var regex = /[!@#$%^&*()_+\=\[\]{};'`~:"\\|.<>\/?]+/; + var regex = /[!@#$%^&*()_+\=\[\]{};'`~:"\\|.<>\/?]+/; if (frm.doc.vehicle) { if (regex.test(frm.doc.vehicle) === true) { frappe.msgprint(__("Vehicle: Only letters, numbers and -, are allowed.")); diff --git a/smart_service/transactions/doctype/publish/publish.js b/smart_service/transactions/doctype/publish/publish.js index d51367b..a638ec9 100644 --- a/smart_service/transactions/doctype/publish/publish.js +++ b/smart_service/transactions/doctype/publish/publish.js @@ -15,7 +15,7 @@ cur_frm.fields_dict['vehicle'].get_query = function (doc, cdt, cdn) { return { query: "smart_service.masters.doctype.vehicle.vehicle.vehicle_filter", }; }; -var lang_set_first_time = true; +let lang_set_first_time = true; frappe.ui.form.on('Publish', { onload: function (frm) { $(document).on('mouseover', function (events) { @@ -28,7 +28,7 @@ frappe.ui.form.on('Publish', { }, planned_publish_date: function (frm) { - var date = (frappe.datetime.nowdate()) + let date = (frappe.datetime.nowdate()) if (frm.doc.planned_publish_date < date) { frm.doc.planned_publish_date = ''; cur_frm.refresh_fields(); @@ -271,7 +271,8 @@ frappe.ui.form.on('Publish', { frm.fields_dict.variant_mapping_assets.grid.grid_buttons.find('.btn-custom').removeClass('btn-default').addClass('btn-primary'); } if (frm.doc.docstatus == 1) { - $(".grid-buttons").hide(); + $(".grid-buttons").hide(); L̥ + } }, validate: function (frm) { @@ -279,7 +280,7 @@ frappe.ui.form.on('Publish', { if (regex.test(frm.doc.release_description) === true) { frm.doc.release_description = ''; frm.refresh_fields(); - frappe.msgprint(__("Publish Description: Only letters, numbers and / - () & , ' : are allowed.")); + frappe.msgprint(__("Publish Description: Only letters, numbers and / - () & , ' : are allowed.")); } if (frm.doc.vehicle && frm.doc.release_description && frm.fields_dict.publish_documents.grid.grid_rows.length === 0) {