|
|
@ -584,11 +584,6 @@ def get_service_repair(vehicle, |
|
|
|
''', as_dict=1) |
|
|
|
return data |
|
|
|
def create_df(data_set): |
|
|
|
|
|
|
|
# with open(base_url+'data.json', 'w') as outfile: |
|
|
|
# outfile.write(json.dumps(feature_finder_tmp, indent=4, default=str)) |
|
|
|
# with open(base_url+'data.json') as f: |
|
|
|
# feature_finder_tmp = json.load(f) |
|
|
|
feature_finder_tmp=json.dumps(data_set) |
|
|
|
df = pd.DataFrame(json.loads(feature_finder_tmp)) |
|
|
|
filter_group=df.groupby('variant') |
|
|
@ -720,13 +715,14 @@ def feature_finder_publish(vehicle=None, vehicle_id=None, |
|
|
|
create_publish_folders(folder_url) |
|
|
|
file_path = folder_url + "/" + publish_type + "/" + \ |
|
|
|
vehicle.replace(' ', '-') + '-feature_finder' + '.json' |
|
|
|
|
|
|
|
global_file_path=folder_url + "/" + "Global" + "/" + \ |
|
|
|
vehicle.replace(' ', '-') + '-feature_finder' + '.json' |
|
|
|
'''Append Published Data to Json''' |
|
|
|
logger.info( |
|
|
|
f'Repair Checksheet Data Append Start::{vehicle}-{language}-{publish_type}') |
|
|
|
'''update existing global json file''' |
|
|
|
if os.path.isfile(file_path): |
|
|
|
with open(file_path) as f: |
|
|
|
if os.path.isfile(file_path) and publish_type == 'Internal': |
|
|
|
with open(global_file_path) as f: |
|
|
|
published_data = json.load(f) |
|
|
|
for i in parent: |
|
|
|
feature_finder = feature_finder_data(vehicle, language, |
|
|
@ -736,14 +732,21 @@ def feature_finder_publish(vehicle=None, vehicle_id=None, |
|
|
|
feature_finder_tmp.append( |
|
|
|
feature_finder['data'][0]) |
|
|
|
feature_finder_tmp=create_df(feature_finder_tmp) |
|
|
|
# frappe.msgprint(str(json.dumps(feature_finder_tmp))) |
|
|
|
|
|
|
|
# feature_finder_tmp = get_latest_data( |
|
|
|
# {'data': published_data['data']}, {'data': feature_finder_tmp}) |
|
|
|
vehi_data = compare_get_data( {'data': published_data['data']}, {'data': feature_finder_tmp}) |
|
|
|
|
|
|
|
elif os.path.isfile(file_path) and publish_type == 'Global': |
|
|
|
with open(global_file_path) as f: |
|
|
|
published_data = json.load(f) |
|
|
|
for i in parent: |
|
|
|
feature_finder = feature_finder_data(vehicle, language, |
|
|
|
publish_type, i.parent1, i.variant) |
|
|
|
if feature_finder['status'] == 1: |
|
|
|
publish_repair_checksheet = 1 |
|
|
|
feature_finder_tmp.append( |
|
|
|
feature_finder['data'][0]) |
|
|
|
feature_finder_tmp=create_df(feature_finder_tmp) |
|
|
|
vehi_data = compare_get_data( {'data': published_data['data']}, {'data': feature_finder_tmp}) |
|
|
|
else: |
|
|
|
|
|
|
|
for i in parent: |
|
|
|
feature_finder = feature_finder_data( |
|
|
|
vehicle, language, publish_type, i.parent1, i.variant) |
|
|
@ -760,9 +763,8 @@ def feature_finder_publish(vehicle=None, vehicle_id=None, |
|
|
|
{'data': feature_finder_tmp}, {'data': []}) |
|
|
|
|
|
|
|
vehi_data=create_df(feature_finder_tmp) |
|
|
|
# if publish_feature_finder == 1: |
|
|
|
""" Save publish file """ |
|
|
|
|
|
|
|
""" Save publish file """ |
|
|
|
vehicle_data['data'] = vehi_data |
|
|
|
with open(file_path, 'w') as outfile: |
|
|
|
outfile.write(json.dumps(vehicle_data, indent=4, default=str)) |
|
|
@ -808,24 +810,65 @@ def get_latest_data(prev_data, latest_data): |
|
|
|
|
|
|
|
def compare_get_data(prev_data, latest_data): |
|
|
|
try: |
|
|
|
logger_file = 'compare' |
|
|
|
logger = frappe.logger(logger_file, |
|
|
|
allow_site=True, file_count=100) |
|
|
|
logger.info( |
|
|
|
f"start compare data") |
|
|
|
final_dic={} |
|
|
|
for key,value in prev_data.items(): |
|
|
|
prev_data[key]=latest_data.get(key) |
|
|
|
final_dic=copy.deepcopy(prev_data) |
|
|
|
final_dic=prev_data.copy() |
|
|
|
|
|
|
|
for key,value in final_dic["data"].items(): |
|
|
|
for i in value: |
|
|
|
if i['active_status']=="Inactive": |
|
|
|
value.remove(i) |
|
|
|
for key,value in latest_data["data"].items(): |
|
|
|
for i in value: |
|
|
|
if i['active_status']=="Inactive": |
|
|
|
value.remove(i) |
|
|
|
#compare old & new json |
|
|
|
for key,values in latest_data["data"].items(): |
|
|
|
for i in latest_data["data"][key]: |
|
|
|
check_key({key:i},final_dic["data"],'') |
|
|
|
logger.info( |
|
|
|
f"End of compare data"+str(final_dic['data'])) |
|
|
|
|
|
|
|
return final_dic["data"] |
|
|
|
return final_dic['data'] |
|
|
|
|
|
|
|
|
|
|
|
except Exception as e: |
|
|
|
logger.error(str(e)) |
|
|
|
frappe.throw(str(e)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def check_key(key_name, old_data, type=None): |
|
|
|
try: |
|
|
|
frappe.msgprint(str(key_name)) |
|
|
|
logger_file = 'check key' |
|
|
|
logger = frappe.logger(logger_file, |
|
|
|
allow_site=True, file_count=100) |
|
|
|
logger.info( |
|
|
|
f"start of key data") |
|
|
|
new_dict=[] |
|
|
|
for key,val in key_name.items(): |
|
|
|
if key in old_data: |
|
|
|
if val['name'] in old_data: |
|
|
|
for old_key,old_val in old_data.items(): |
|
|
|
for i in old_val: |
|
|
|
if val['name'] in old_val : |
|
|
|
if old_key == key and val['name'] == i['name']: |
|
|
|
i.update(val) |
|
|
|
else: |
|
|
|
old_data[key].append(val) |
|
|
|
|
|
|
|
else: |
|
|
|
new_dict.append(val) |
|
|
|
old_data[key]=new_dict |
|
|
|
logger.info(f"end of key data"+str(key_name)) |
|
|
|
except Exception as e: |
|
|
|
logger.error(str(e)) |
|
|
|
return str(e) |
|
|
|
def repair_checksheet_data(vehicle=None, language=None, |
|
|
|
publish_type=None, parent=None): |
|
|
|
try: |
|
|
@ -845,8 +888,7 @@ def repair_checksheet_data(vehicle=None, language=None, |
|
|
|
|
|
|
|
for d in repair_service_details: |
|
|
|
d['complaint'] = frappe.db.sql(f"""select complaint,remedial_action_ok, |
|
|
|
remedial_action_not_ok,idx as display_order, |
|
|
|
active_status from `tabRepair Service Child` |
|
|
|
remedial_action_not_ok,idx as display_order from `tabRepair Service Child` |
|
|
|
where parent = '{d['name']}' |
|
|
|
order by display_order ;""", as_dict=1) |
|
|
|
|
|
|
@ -893,17 +935,17 @@ def feature_finder_data(vehicle=None, language=None, |
|
|
|
|
|
|
|
for f in feature_finder_details: |
|
|
|
f['disclaimer'] = frappe.db.sql(f''' |
|
|
|
SELECT name,content,active_status,idx as display_order FROM `tabFeature Finder Disclaimer` |
|
|
|
SELECT name,content,idx as display_order FROM `tabFeature Finder Disclaimer` |
|
|
|
where parent = '{str(f['vehicle'])+ str('-')+ str(f['feature_name']) +str('-')+str(f['language'])}'; |
|
|
|
''', as_dict=1) |
|
|
|
|
|
|
|
sop_images = frappe.db.sql(f""" select image,display_order,active_status from `tabFeature Finder Images` where |
|
|
|
sop_images = frappe.db.sql(f""" select image,display_order from `tabFeature Finder Images` where |
|
|
|
parent = '{f['name']}' and feature_type ='SOP' order by display_order desc;""", as_dict=1) |
|
|
|
|
|
|
|
sop_content = frappe.db.sql(f"""select content,display_order, active_status from `tabFeature Finder Content` |
|
|
|
sop_content = frappe.db.sql(f"""select content,display_order from `tabFeature Finder Content` |
|
|
|
where parent = '{f['name']}' and feature_type ='SOP' order by display_order desc;""", as_dict=1) |
|
|
|
|
|
|
|
sop_specification = frappe.db.sql(f"""select specification,value,display_order,active_status from `tabFeature Finder Specification` |
|
|
|
sop_specification = frappe.db.sql(f"""select specification,value,display_order from `tabFeature Finder Specification` |
|
|
|
where parent = '{f['name']}' and feature_type ='SOP' order by display_order desc;""", as_dict=1) |
|
|
|
|
|
|
|
f['sop'] = {'content': sop_content, 'images': sop_images, |
|
|
@ -912,13 +954,13 @@ def feature_finder_data(vehicle=None, language=None, |
|
|
|
from `tabPost Vin Cutoff ID` where parent = '{f['name']}';''', as_dict=1) |
|
|
|
for p in post_vin_data: |
|
|
|
|
|
|
|
vin_content = frappe.db.sql(f"""select content,display_order, active_status from `tabFeature Finder Content` |
|
|
|
vin_content = frappe.db.sql(f"""select content,display_order from `tabFeature Finder Content` |
|
|
|
where parent = '{f['name']}' and post_vin_cutoff_name ='{p['post_vin_cutoff_name']}' order by display_order desc;""", as_dict=1) |
|
|
|
|
|
|
|
vin_images = frappe.db.sql(f""" select image,display_order,active_status from `tabFeature Finder Images` where |
|
|
|
vin_images = frappe.db.sql(f""" select image,display_order from `tabFeature Finder Images` where |
|
|
|
parent = '{f['name']}' and post_vin_cutoff_name ='{p['post_vin_cutoff_name']}' order by display_order desc;""", as_dict=1) |
|
|
|
|
|
|
|
vin_specification = frappe.db.sql(f"""select specification,value,display_order,active_status from `tabFeature Finder Specification` |
|
|
|
vin_specification = frappe.db.sql(f"""select specification,value,display_order from `tabFeature Finder Specification` |
|
|
|
where parent = '{f['name']}' and post_vin_cutoff_name ='{p['post_vin_cutoff_name']}' order by display_order desc;""", as_dict=1) |
|
|
|
p['content'] = vin_content |
|
|
|
p['images'] = vin_images |
|
|
|