|
|
@ -20,6 +20,7 @@ base_url = os.path.expanduser( |
|
|
|
frappe.utils.logger.set_log_level("DEBUG") |
|
|
|
success_reponse = {"status": 1, "data": "", "message": ""} |
|
|
|
failure_reponse = {"status": 0, "data": "", "error": ""} |
|
|
|
module_name='feature_finder' |
|
|
|
|
|
|
|
|
|
|
|
class PublishTest(Document): |
|
|
@ -51,6 +52,8 @@ class PublishTest(Document): |
|
|
|
if self.docstatus == 1 and self.publish_status == 'To Publish' and self.publish_module == 'Others' and self.publish_type == 'Internal': |
|
|
|
repair_checksheet_publish(self.vehicle, self.vehicle_id, self.language, self.publish_type, |
|
|
|
self.release_description, self.variant, self.repair_checksheet_publish) |
|
|
|
feature_finder_publish(self.vehicle, self.vehicle_id, self.language, self.publish_type, |
|
|
|
self.release_description,self.feature_finder_publish) |
|
|
|
update_publish_status = frappe.db.sql( |
|
|
|
"""update `tabPublish Test` set publish_status='Published' where name='{0}'""".format(self.name)) |
|
|
|
if self.docstatus == 1 and self.publish_module == 'Others' and self.publish_type == 'Global': |
|
|
@ -267,7 +270,8 @@ def generate_global_publish(name): |
|
|
|
"language": res.language, |
|
|
|
"release_description": res.release_description, |
|
|
|
"publish_module": res.publish_module, |
|
|
|
"repair_checksheet_publish": res.repair_checksheet_publish |
|
|
|
"repair_checksheet_publish": res.repair_checksheet_publish, |
|
|
|
"feature_finder_publish":res.feature_finder_publish |
|
|
|
}) |
|
|
|
ret.insert() |
|
|
|
return {"status": "success", "message": ret.name, "url": frappe.utils.get_url()} |
|
|
@ -440,12 +444,21 @@ def update_procedure_value(name, file_path): |
|
|
|
|
|
|
|
|
|
|
|
@frappe.whitelist() |
|
|
|
def get_service_repair(vehicle, language_label, publish_type): |
|
|
|
def get_service_repair(vehicle, |
|
|
|
language_label, publish_type): |
|
|
|
data = frappe.db.sql(f''' |
|
|
|
select * from `tabRepair Service Mapping` where vehicle = '{vehicle}' and language='{language_label}' and published = 0; |
|
|
|
''', as_dict=1) |
|
|
|
return data |
|
|
|
|
|
|
|
@frappe.whitelist() |
|
|
|
def get_feature_finder(vehicle,language_label): |
|
|
|
try: |
|
|
|
data=frappe.db.sql(f"""select * from `tabFeature Finder` where vehicle='{vehicle}' and language='{language_label}' and is_published=0""",as_dict=1) |
|
|
|
return data |
|
|
|
except Exception as e: |
|
|
|
return str(e) |
|
|
|
|
|
|
|
|
|
|
|
def repair_checksheet_publish(vehicle, vehicle_id, |
|
|
|
language, publish_type, release_description, |
|
|
@ -489,15 +502,12 @@ def repair_checksheet_publish(vehicle, vehicle_id, |
|
|
|
publish_type, i.parent_name) |
|
|
|
if repair_checksheet['status'] == 1: |
|
|
|
publish_repair_checksheet = 1 |
|
|
|
if len(repair_checksheet['data']) > 0: |
|
|
|
# Compare with existing |
|
|
|
global_publish['data']['repair_checksheet'].append( |
|
|
|
repair_checksheet_tmp.append( |
|
|
|
repair_checksheet['data'][0]) |
|
|
|
repair_checksheet_tmp = published_data['data']['repair_checksheet'] |
|
|
|
frappe.msgprint('file_exists' + str(published_data)) |
|
|
|
|
|
|
|
repair_checksheet_tmp=get_latest_data({'data':published_data['data']},{'data':repair_checksheet_tmp}) |
|
|
|
|
|
|
|
else: |
|
|
|
frappe.msgprint(str('new file')) |
|
|
|
for i in parent: |
|
|
|
repair_checksheet = repair_checksheet_data( |
|
|
|
vehicle, language, publish_type, i.parent_name) |
|
|
@ -507,6 +517,9 @@ def repair_checksheet_publish(vehicle, vehicle_id, |
|
|
|
if len(repair_checksheet['data']): |
|
|
|
repair_checksheet_tmp.append( |
|
|
|
repair_checksheet['data'][0]) |
|
|
|
# frappe.msgprint(str(repair_checksheet['data'][0])) |
|
|
|
repair_checksheet_tmp=get_latest_data({'data':repair_checksheet_tmp},{'data':[]}) |
|
|
|
frappe.msgprint(str(repair_checksheet_tmp)) |
|
|
|
|
|
|
|
if publish_repair_checksheet == 1: |
|
|
|
""" Save publish file """ |
|
|
@ -522,6 +535,87 @@ def repair_checksheet_publish(vehicle, vehicle_id, |
|
|
|
f'{vehicle} - {language} - {publish_type} error in json creation' + str(e)) |
|
|
|
frappe.throw('Failed To Publish') |
|
|
|
|
|
|
|
def feature_finder_publish(vehicle=None, language=None, |
|
|
|
vehicle_id=None,publish_type=None, |
|
|
|
release_description=None,parent=None): |
|
|
|
try: |
|
|
|
|
|
|
|
logger_file = f'{vehicle} - {language} - {publish_type} - {module_name}' |
|
|
|
logger = frappe.logger(logger_file, |
|
|
|
allow_site=True, file_count=100) |
|
|
|
logger.info( |
|
|
|
f"start of fetching repair checksheet data - {vehicle} - {language} - {module_name}") |
|
|
|
|
|
|
|
folder_url = base_url+"/"+vehicle.replace(' ', '-') + "/"+language |
|
|
|
logger.info(f'Created Folder-{vehicle}-{language}-{publish_type}') |
|
|
|
|
|
|
|
'''Final Json''' |
|
|
|
vehicle_data = { |
|
|
|
'vehicle': vehicle, |
|
|
|
'vehicle_myid': vehicle_id, |
|
|
|
'publish_type': publish_type, |
|
|
|
'publish_description': release_description, |
|
|
|
'publish_language': language, |
|
|
|
'data': '' |
|
|
|
} |
|
|
|
|
|
|
|
'''Publish Ready Flags''' |
|
|
|
publish_feature_finder = 0 |
|
|
|
feature_finder_tmp = [] |
|
|
|
|
|
|
|
'''Create Folder For Publish''' |
|
|
|
create_publish_folders(folder_url) |
|
|
|
file_path = folder_url + "/" + publish_type + "/" + \ |
|
|
|
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: |
|
|
|
published_data = json.load(f) |
|
|
|
for i in parent: |
|
|
|
repair_checksheet = repair_checksheet_data(vehicle, language, |
|
|
|
publish_type, i.parent_name) |
|
|
|
if repair_checksheet['status'] == 1: |
|
|
|
publish_repair_checksheet = 1 |
|
|
|
repair_checksheet_tmp.append( |
|
|
|
repair_checksheet['data'][0]) |
|
|
|
|
|
|
|
repair_checksheet_tmp=get_latest_data({'data':published_data['data']},{'data':repair_checksheet_tmp}) |
|
|
|
|
|
|
|
else: |
|
|
|
for i in parent: |
|
|
|
feature_finder = feature_finder_data( |
|
|
|
vehicle, language, publish_type, i.parent) |
|
|
|
|
|
|
|
if feature_finder['status'] == 1: |
|
|
|
publish_feature_finder = 1 |
|
|
|
if len(feature_finder['data']): |
|
|
|
feature_finder_tmp.append( |
|
|
|
feature_finder['data'][0]) |
|
|
|
|
|
|
|
|
|
|
|
feature_finder_tmp=get_latest_data({'data':feature_finder_tmp},{'data':[]}) |
|
|
|
frappe.msgprint(str(feature_finder_tmp)) |
|
|
|
|
|
|
|
|
|
|
|
if publish_feature_finder == 1: |
|
|
|
""" Save publish file """ |
|
|
|
vehicle_data['data'] = feature_finder_tmp |
|
|
|
|
|
|
|
with open(file_path, 'w') as outfile: |
|
|
|
outfile.write(json.dumps(vehicle_data, indent=4, default=str)) |
|
|
|
|
|
|
|
return 1, file_path |
|
|
|
|
|
|
|
|
|
|
|
except Exception as e: |
|
|
|
logger.info( |
|
|
|
f'{vehicle} - {language} - {publish_type} - {module_name} error in json creation' + str(e)) |
|
|
|
frappe.throw('Failed To Publish') |
|
|
|
|
|
|
|
|
|
|
|
def update_published_docs(self): |
|
|
|
try: |
|
|
@ -565,6 +659,7 @@ def get_key_value_data(data): |
|
|
|
|
|
|
|
|
|
|
|
def get_latest_data(prev_data, latest_data): |
|
|
|
|
|
|
|
data_dic1 = get_key_value_data(prev_data) |
|
|
|
data_dic2 = get_key_value_data(latest_data) |
|
|
|
|
|
|
@ -581,6 +676,8 @@ def get_latest_data(prev_data, latest_data): |
|
|
|
final_dic.update({d2: data_dic2[d2]}) |
|
|
|
|
|
|
|
final_list = list(final_dic.values()) |
|
|
|
frappe.msgprint(str(final_list)) |
|
|
|
|
|
|
|
return final_list |
|
|
|
|
|
|
|
|
|
|
@ -625,6 +722,74 @@ def repair_checksheet_data(vehicle=None, language=None, |
|
|
|
def feature_finder_data(vehicle=None, language=None, |
|
|
|
publish_type=None, parent=None): |
|
|
|
try: |
|
|
|
pass |
|
|
|
logger_file = f'{vehicle} - {language} - {publish_type} - {module_name}' |
|
|
|
logger = frappe.logger(logger_file, |
|
|
|
allow_site=True, file_count=100) |
|
|
|
logger.info( |
|
|
|
f"start of fetching feature finder checksheet data - {vehicle} - {language} - {module_name}") |
|
|
|
feature_finder_details = [] |
|
|
|
if language == 'en': |
|
|
|
feature_finder_details = frappe.db.sql(f"""select ff.name,ff.vehicle,ff.vehicle_id,ff.variant,ff.variant_id,ff.language, |
|
|
|
ff.features_names as feature_name,ff.feature_category,ff.display_order,ff.active_status, |
|
|
|
ffm.feature_pdf as pdf from `tabFeature Finder` ff left join `tabFeature Finder Master` ffm on |
|
|
|
ff.features_names = ffm.feature_name |
|
|
|
where ff.vehicle = "{vehicle}" and ffm.vehicle = "{vehicle}" and ff.variant = "{variant}" |
|
|
|
and ff.language = "{language}" and ffm.language = "{language} and ff.name="{parent}"; |
|
|
|
""", as_dict=1) |
|
|
|
else: |
|
|
|
feature_finder_details = frappe.db.sql(f"""select ff.name,ff.vehicle,ff.vehicle_id,ff.variant,ff.variant_id,ff.language, |
|
|
|
ff.translated_feature_name as feature_name,ff.feature_category, |
|
|
|
ff.display_order,ff.active_status,ffm.feature_pdf as pdf from `tabFeature Finder` ff |
|
|
|
left join `tabFeature Finder Master` ffm on ff.features_names = ffm.feature_name |
|
|
|
where ff.vehicle = "{vehicle}" and ffm.vehicle = "{vehicle}" and ff.variant = "{variant}" |
|
|
|
and ff.language = "{language}" and ff.name="{parent}" ; """, as_dict=1) |
|
|
|
|
|
|
|
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` |
|
|
|
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,idx as display_order,active_status from `tabFeature Finder Images` where |
|
|
|
parent = '{f['name']}' and feature_type ='SOP';""", as_dict=1) |
|
|
|
|
|
|
|
sop_content = frappe.db.sql(f"""select content,idx as display_order, active_status from `tabFeature Finder Content` |
|
|
|
where parent = '{f['name']}' and feature_type ='SOP';""", as_dict=1) |
|
|
|
|
|
|
|
sop_specification = frappe.db.sql(f"""select specification,value,idx as display_order,active_status from `tabFeature Finder Specification` |
|
|
|
where parent = '{f['name']}' and feature_type ='SOP';""", as_dict=1) |
|
|
|
|
|
|
|
f['sop'] = {'content': sop_content, 'images': sop_images, |
|
|
|
'specificaton': sop_specification} |
|
|
|
post_vin_data = frappe.db.sql(f'''select name,idx as display_order,post_vin_cutoff_name,post_vin_cutoff_id |
|
|
|
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,idx as display_order, active_status from `tabFeature Finder Content` |
|
|
|
where parent = '{f['name']}' and post_vin_cutoff_name ='{p['post_vin_cutoff_name']}';""", as_dict=1) |
|
|
|
|
|
|
|
vin_images = frappe.db.sql(f""" select image,idx as display_order,active_status from `tabFeature Finder Images` where |
|
|
|
parent = '{f['name']}' and post_vin_cutoff_name ='{p['post_vin_cutoff_name']}';""", as_dict=1) |
|
|
|
|
|
|
|
vin_specification = frappe.db.sql(f"""select specification,value,idx as display_order,active_status from `tabFeature Finder Specification` |
|
|
|
where parent = '{f['name']}' and post_vin_cutoff_name ='{p['post_vin_cutoff_name']}';""", as_dict=1) |
|
|
|
p['content'] = vin_content |
|
|
|
p['images'] = vin_images |
|
|
|
p['specificaton'] = vin_specification |
|
|
|
|
|
|
|
f['post_vin'] = post_vin_data |
|
|
|
|
|
|
|
|
|
|
|
logger.info( |
|
|
|
f"end of fetching feature finder data {vehicle} - {language}") |
|
|
|
success_reponse['data'] = feature_finder_details |
|
|
|
success_reponse[ |
|
|
|
'message'] = f'Repair Checksheet Fecthed Succesfully for {vehicle} - {language}' |
|
|
|
return success_reponse |
|
|
|
|
|
|
|
except Exception as e: |
|
|
|
pass |
|
|
|
failure_reponse['error'] = f"{vehicle} - {language} has following error - " + str( |
|
|
|
e) |
|
|
|
logger.error('error in repair checksheet' + str(e)) |
|
|
|
return failure_reponse |
|
|
|
|
|
|
|