|
|
@ -60,14 +60,7 @@ class Publish(Document): |
|
|
|
|
|
|
|
def on_submit(self): |
|
|
|
|
|
|
|
if self.docstatus == 1 and self.publish_status == 'To Publish' and self.publish_module == 'Repair service' and self.publish_type == 'Internal': |
|
|
|
repair_res_obj = repair_checksheet_publish(self.vehicle, self.vehicle_id, |
|
|
|
self.language, self.publish_type, |
|
|
|
self.release_description, self.variant, |
|
|
|
self.repiar_checksheet_publish_docs) |
|
|
|
|
|
|
|
update_publish_status = frappe.db.sql( |
|
|
|
"""update `tabPublish` set publish_status='Published' where name='{0}'""".format(self.name)) |
|
|
|
# qwik_service |
|
|
|
if self.docstatus == 1 and self.publish_status == 'To Publish' and self.publish_module == 'Qwik Service' and self.publish_type == 'Internal': |
|
|
|
qwik_service_publish(self.vehicle, self.vehicle_id, self.variant, |
|
|
|
self.language, self.publish_type, |
|
|
@ -85,6 +78,7 @@ class Publish(Document): |
|
|
|
update_qwik_published_docs(self) |
|
|
|
update_publish_status = frappe.db.sql( |
|
|
|
"""update `tabPublish` set publish_status='Published' where name='{0}'""".format(self.name)) |
|
|
|
# feature_finder |
|
|
|
if self.docstatus == 1 and self.publish_status == 'To Publish' and self.publish_module == 'Feature Finder' and self.publish_type == 'Internal' and self.feature_finder_publish_docs: |
|
|
|
feature_finder_publish(self.vehicle, self.vehicle_id, |
|
|
|
self.language, self.publish_type, |
|
|
@ -100,6 +94,15 @@ class Publish(Document): |
|
|
|
update_feature_published_docs(self) |
|
|
|
update_publish_status = frappe.db.sql( |
|
|
|
"""update `tabPublish` set publish_status='Published' where name='{0}'""".format(self.name)) |
|
|
|
# repair_service |
|
|
|
if self.docstatus == 1 and self.publish_status == 'To Publish' and self.publish_module == 'Repair service' and self.publish_type == 'Internal': |
|
|
|
repair_res_obj = repair_checksheet_publish(self.vehicle, self.vehicle_id, |
|
|
|
self.language, self.publish_type, |
|
|
|
self.release_description, self.variant, |
|
|
|
self.repiar_checksheet_publish_docs) |
|
|
|
|
|
|
|
update_publish_status = frappe.db.sql( |
|
|
|
"""update `tabPublish` set publish_status='Published' where name='{0}'""".format(self.name)) |
|
|
|
if self.docstatus == 1 and self.publish_status == 'To Publish' and self.publish_module == 'Repair service' and self.publish_type == 'Global' and self.repiar_checksheet_publish_docs: |
|
|
|
repair_checksheet_publish(self.vehicle, self.vehicle_id, |
|
|
|
self.language, self.publish_type, |
|
|
@ -108,7 +111,7 @@ class Publish(Document): |
|
|
|
update_repair_published_docs(self) |
|
|
|
update_publish_status = frappe.db.sql( |
|
|
|
"""update `tabPublish` set publish_status='Published' where name='{0}'""".format(self.name)) |
|
|
|
|
|
|
|
# special tool |
|
|
|
if self.docstatus == 1 and self.publish_status == 'To Publish' and self.publish_module == 'Special Tool' and self.publish_type == 'Internal': |
|
|
|
special_tool_publish(self.vehicle, self.vehicle_id, |
|
|
|
self.publish_type, |
|
|
@ -125,6 +128,23 @@ class Publish(Document): |
|
|
|
update_publish_status = frappe.db.sql( |
|
|
|
"""update `tabPublish` set publish_status='Published' where name='{0}'""".format(self.name)) |
|
|
|
|
|
|
|
# torque_manual |
|
|
|
if self.docstatus == 1 and self.publish_status == 'To Publish' and self.publish_module == 'Torque Manual' and self.publish_type == 'Internal' and self.torque_manual_publish_docs: |
|
|
|
torque_manual_publish(self.vehicle, self.vehicle_id, |
|
|
|
self.language, self.publish_type, |
|
|
|
self.release_description, self.torque_manual_publish_docs, self.variant) |
|
|
|
update_publish_status = frappe.db.sql( |
|
|
|
"""update `tabPublish` set publish_status='Published' where name='{0}'""".format(self.name)) |
|
|
|
|
|
|
|
if self.docstatus == 1 and self.publish_module == 'Feature Finder' and self.publish_type == 'Global': |
|
|
|
torque_manual_publish(self.vehicle, self.vehicle_id, |
|
|
|
self.language, self.publish_type, |
|
|
|
self.release_description, self.torque_manual_publish_docs, |
|
|
|
self.variant) |
|
|
|
update_torque_manual_published_docs(self) |
|
|
|
update_publish_status = frappe.db.sql( |
|
|
|
"""update `tabPublish` set publish_status='Published' where name='{0}'""".format(self.name)) |
|
|
|
|
|
|
|
variant = self.variant_mapping_details.split('/n') |
|
|
|
update_publish_mapping(self.vehicle, self.variant_mapping, |
|
|
|
self.language, self.publish_module, self.publish_type) |
|
|
@ -211,6 +231,14 @@ def update_qwik_published_docs(self): |
|
|
|
except Exception as ex: |
|
|
|
return str(ex) |
|
|
|
|
|
|
|
def update_torque_manual_published_docs(self): |
|
|
|
try: |
|
|
|
for d in self.torque_manual_publish_docs: |
|
|
|
frappe.db.sql(''' update `tabTorque Manual` set is_published=1 where name='{0}';'''.format(d.parent1)) |
|
|
|
frappe.db.commit() |
|
|
|
except Exception as e: |
|
|
|
raise e |
|
|
|
|
|
|
|
|
|
|
|
def update_publish_mapping(vehicle, variant, language, module, publish_type): |
|
|
|
# frappe.set_user('Administrator') |
|
|
@ -421,6 +449,18 @@ def generate_global_publish(name, module_name): |
|
|
|
"publish_module": res.publish_module |
|
|
|
|
|
|
|
}) |
|
|
|
elif module_name == 'Torque Manual': |
|
|
|
ret = frappe.get_doc({ |
|
|
|
"doctype": "Publish", |
|
|
|
"vehicle": res.vehicle, |
|
|
|
"publish_type": "Global", |
|
|
|
"language": res.language, |
|
|
|
"variant_mapping_details": res.variant_mapping_details, |
|
|
|
"publish_status": 'To Publish', |
|
|
|
"release_description": res.release_description, |
|
|
|
"publish_module": res.publish_module, |
|
|
|
"torque_manual_publish_docs": res.torque_manual_publish_docs |
|
|
|
}) |
|
|
|
ret.save() |
|
|
|
return {"status": "success", "message": ret.name, "url": frappe.utils.get_url()} |
|
|
|
except Exception as e: |
|
|
@ -1243,6 +1283,186 @@ def special_tool_publish(vehicle, vehicle_id, |
|
|
|
frappe.throw('Failed To Publish') |
|
|
|
|
|
|
|
|
|
|
|
def torque_manual_publish(vehicle=None, vehicle_id=None, |
|
|
|
language=None, publish_type=None, |
|
|
|
release_description=None, parent=None, |
|
|
|
variant=None): |
|
|
|
try: |
|
|
|
logger_file = f'{vehicle} - {language} - {publish_type} - {module_name} - {variant}' |
|
|
|
logger = frappe.logger(logger_file, |
|
|
|
allow_site=True, file_count=100) |
|
|
|
logger.info( |
|
|
|
f"start of fetching Torque Manual data - {vehicle} - {language} - {module_name} - {variant}") |
|
|
|
|
|
|
|
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': '' |
|
|
|
} |
|
|
|
|
|
|
|
latest_pub_data = vehicle_data.copy() |
|
|
|
|
|
|
|
'''Publish Ready Flags''' |
|
|
|
publish_torque_manual= 0 |
|
|
|
torque_manual_tmp = [] |
|
|
|
|
|
|
|
'''Create Folder For Publish''' |
|
|
|
create_publish_folders(folder_url) |
|
|
|
full_update_folder_url = folder_url + "/" + "{}".format(publish_type)+"_Full_Update" |
|
|
|
file_path = folder_url + "/" + publish_type + "/" + \ |
|
|
|
vehicle.replace(' ', '-') + '-torque_manual' + '.json' |
|
|
|
global_file_path = folder_url + "/" + 'Global' + "/" + \ |
|
|
|
vehicle.replace(' ', '-') + '-torque_manual' + '.json' |
|
|
|
|
|
|
|
full_update_file = full_update_folder_url+"/" + vehicle.replace(' ', '-') + '-torque_manual_full_update' + '.json' |
|
|
|
# full_internal_update_file = full_update_folder_url+"/" + vehicle.replace(' ', '-') + '-feature_finder_full_update' + '.json' |
|
|
|
global_full_update_path = folder_url + "/" + "Global_Full_Update" |
|
|
|
check_glbl_full_updte = global_full_update_path+"/" + vehicle.replace(' ', '-') + '-torque_manual_full_update' + '.json' |
|
|
|
|
|
|
|
'''Append Published Data to Json''' |
|
|
|
|
|
|
|
logger.info( |
|
|
|
f'Feature Data Append Start::{vehicle}-{language}-{publish_type}') |
|
|
|
'''update existing global json file''' |
|
|
|
if os.path.isfile(global_file_path) and publish_type == 'Internal': |
|
|
|
if os.path.isfile(check_glbl_full_updte): |
|
|
|
with open(check_glbl_full_updte) as f: |
|
|
|
published_data = json.load(f) |
|
|
|
for i in parent: |
|
|
|
torque_manual = torque_manual_data(vehicle, language, |
|
|
|
publish_type, i.parent1, i.variant) |
|
|
|
if torque_manual['status'] == 1: |
|
|
|
publish_torque_manual = 1 |
|
|
|
torque_manual_tmp.append( |
|
|
|
torque_manual['data'][0]) |
|
|
|
torque_manual_tmp = create_df(torque_manual_tmp) |
|
|
|
latest_pub_data['data'] = torque_manual_tmp |
|
|
|
vehi_data = compare_get_data({'data': latest_pub_data['data']}, { |
|
|
|
'data': torque_manual_tmp}) |
|
|
|
if vehi_data: |
|
|
|
find_distinct = set(exisitng_var) |
|
|
|
new_variant_name = [ |
|
|
|
x for x in new_variant if x not in find_distinct] |
|
|
|
vehi_data = add_new_val( |
|
|
|
vehi_data, new_variant_name, feature_finder_tmp) |
|
|
|
|
|
|
|
elif os.path.isfile(file_path) and publish_type == 'Global': |
|
|
|
frappe.log_error('inside') |
|
|
|
full_update_folder_url_internal = folder_url + "/" + "Internal_Full_Update" |
|
|
|
#Remove Internal Full Update File On Global Publish |
|
|
|
existing_internal_full_update = full_update_folder_url_internal+"/" + vehicle.replace(' ', '-') + '-torque_manual_full_update' + '.json' |
|
|
|
frappe.log_error('file_path' + str(existing_internal_full_update)) |
|
|
|
if os.path.isfile(existing_internal_full_update): |
|
|
|
os.remove(existing_internal_full_update) |
|
|
|
with open(check_glbl_full_updte) as f: |
|
|
|
published_data = json.load(f) |
|
|
|
for i in parent: |
|
|
|
torque_manual = torque_manual_data(vehicle, language, |
|
|
|
publish_type, i.parent1, i.variant) |
|
|
|
if torque_manual['status'] == 1: |
|
|
|
publish_torque_manual = 1 |
|
|
|
feature_finder_tmp.append( |
|
|
|
torque_manual['data'][0]) |
|
|
|
torque_manual_tmp = create_df(torque_manual_tmp) |
|
|
|
latest_pub_data['data'] = torque_manual_tmp |
|
|
|
vehi_data = compare_get_data({'data': latest_pub_data['data']}, { |
|
|
|
'data': torque_manual_tmp}) |
|
|
|
if vehi_data: |
|
|
|
find_distinct = set(exisitng_var) |
|
|
|
new_variant_name = [ |
|
|
|
x for x in new_variant if x not in find_distinct] |
|
|
|
vehi_data = add_new_val( |
|
|
|
vehi_data, new_variant_name, torque_manual_tmp) |
|
|
|
else: |
|
|
|
#Existing Global or Internal Full Update |
|
|
|
|
|
|
|
internal_full_update_check = full_update_folder_url = folder_url + "/" +"Internal_Full_Update" |
|
|
|
check_full_update_file = internal_full_update_check+"/" + vehicle.replace(' ', '-') + '-torque_manual_full_update' + '.json' |
|
|
|
if os.path.isfile(check_full_update_file): |
|
|
|
with open(check_full_update_file) as f: |
|
|
|
published_data = json.load(f) |
|
|
|
for i in parent: |
|
|
|
frappe.log_error("i",str(parent)) |
|
|
|
torque_manual = torque_manual_data( |
|
|
|
vehicle, language, publish_type, i.parent1, i.variant) |
|
|
|
if torque_manual['status'] == 1: |
|
|
|
publish_torque_manual = 1 |
|
|
|
|
|
|
|
if len(torque_manual['data']): |
|
|
|
torque_manual_tmp.append( |
|
|
|
torque_manual['data'][0]) |
|
|
|
else: |
|
|
|
frappe.throw('failed to publish') |
|
|
|
torque_manual_tmp = create_df(torque_manual_tmp) |
|
|
|
latest_pub_data['data'] = torque_manual_tmp |
|
|
|
|
|
|
|
vehi_data = compare_get_data({'data': latest_pub_data['data']}, { |
|
|
|
'data': torque_manual_tmp}) |
|
|
|
if vehi_data: |
|
|
|
find_distinct = set(exisitng_var) |
|
|
|
new_variant_name = [ |
|
|
|
x for x in new_variant if x not in find_distinct] |
|
|
|
vehi_data = add_new_val( |
|
|
|
vehi_data, new_variant_name, torque_manual_tmp) |
|
|
|
|
|
|
|
vehicle_data['data'] = vehi_data |
|
|
|
|
|
|
|
#First Time Global Or Internal |
|
|
|
else: |
|
|
|
for i in parent: |
|
|
|
frappe.log_error("619",str(parent)) |
|
|
|
torque_manual = torque_manual_data( |
|
|
|
vehicle, language, publish_type, i.parent1, i.variant) |
|
|
|
|
|
|
|
if torque_manual['status'] == 1: |
|
|
|
publish_torque_manual = 1 |
|
|
|
if len(torque_manual['data'])>0: |
|
|
|
torque_manual_tmp.append( |
|
|
|
torque_manual['data'][0]) |
|
|
|
else: |
|
|
|
frappe.throw('failed to publish') |
|
|
|
torque_manual_tmp = get_latest_data( |
|
|
|
{'data': torque_manual_tmp}, {'data': []}) |
|
|
|
frappe.log_error(str(torque_manual_tmp)) |
|
|
|
vehi_data = create_df(torque_manual_tmp) |
|
|
|
latest_pub_data['data'] = vehi_data |
|
|
|
|
|
|
|
if publish_type == "Global": |
|
|
|
full_update_folder_url_internal = folder_url + "/" + "Internal_Full_Update" |
|
|
|
#Remove Internal Full Update File On Global Publish |
|
|
|
existing_internal_full_update = full_update_folder_url_internal+"/" + vehicle.replace(' ', '-') + '-torque_manual_full_update' + '.json' |
|
|
|
frappe.log_error('file_path' + str(existing_internal_full_update)) |
|
|
|
if os.path.isfile(existing_internal_full_update): |
|
|
|
os.remove(existing_internal_full_update) |
|
|
|
""" Save publish file """ |
|
|
|
vehicle_data['data'] = vehi_data |
|
|
|
|
|
|
|
with open(file_path, 'w') as outfile: |
|
|
|
outfile.write(json.dumps(latest_pub_data, indent=4, default=str)) |
|
|
|
|
|
|
|
|
|
|
|
with open(full_update_file, 'w') as outfile: |
|
|
|
outfile.write(json.dumps(vehicle_data, indent=4, default=str)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logger.info( |
|
|
|
f'Torque Manual Data Append Start::{vehicle}-{language}-{publish_type}') |
|
|
|
|
|
|
|
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 get_key_value_data(data): |
|
|
|
module_dic = {} |
|
|
|
for d in data['data']: |
|
|
@ -1574,7 +1794,32 @@ def special_tool_data(vehicle=None, |
|
|
|
logger.error('error in special tool' + str(e)) |
|
|
|
return failure_reponse |
|
|
|
|
|
|
|
def torque_manual_data(vehicle=None, language=None, |
|
|
|
publish_type=None, parent=None, variant=None): |
|
|
|
try: |
|
|
|
logger_file = f'{vehicle} - {language} - {publish_type} - {module_name} - {variant} - fetch data' |
|
|
|
logger = frappe.logger(logger_file, |
|
|
|
allow_site=True, file_count=100) |
|
|
|
logger.info( |
|
|
|
f"start of fetching torque manual data - {vehicle} - {language} - {variant} - {module_name}") |
|
|
|
torque_manual_details = frappe.db.sql('''select name,variant,vehicle,language,active_status,category,sub_category,display_order,my_id |
|
|
|
from `tabTorque Manual` where variant ='%s' && language= '%s';'''%(variant,language), as_dict=1) |
|
|
|
for t in torque_manual_details: |
|
|
|
t['torque_table']= frappe.db.sql(''' select idx as 'display_order',fastener_description,specification,qty,torque_nm,remark from |
|
|
|
`tabTorque Manual Details` where parent = '%s' order by display_order;'''%(t['name']),as_dict=1) |
|
|
|
|
|
|
|
logger.info( |
|
|
|
f"end of Torque Manual data {variant} - {language}") |
|
|
|
success_reponse['data'] = torque_manual_details |
|
|
|
success_reponse[ |
|
|
|
'message'] = f'Torque Manual Fecthed Succesfully for {vehicle} - {language}' |
|
|
|
return success_reponse |
|
|
|
|
|
|
|
except Exception as e: |
|
|
|
failure_reponse['error'] = f"{vehicle} - {language} has following error - " + str( |
|
|
|
e) |
|
|
|
logger.error('error in Torque Manual' + str(e)) |
|
|
|
return failure_reponse |
|
|
|
@frappe.whitelist() |
|
|
|
def max_publish_new_module(doc): |
|
|
|
doc = frappe.get_doc("Publish", doc) |
|
|
@ -1631,3 +1876,13 @@ def get_special_tool(vehicle=None, publish_type=None): |
|
|
|
data = frappe.db.sql(''' |
|
|
|
select * from `tabSpecial Tool Information` where vehicle ='%s' and published = '%s';''' % (vehicle, 0), as_dict=1) |
|
|
|
return data |
|
|
|
|
|
|
|
|
|
|
|
@frappe.whitelist() |
|
|
|
def get_torque_manual(variant=None, language_label=None): |
|
|
|
try: |
|
|
|
data = frappe.db.sql( |
|
|
|
"""select * from `tabTorque Manual` where variant='%s' and language='%s' and is_published='%s';"""%(variant,language_label,0), as_dict=1) |
|
|
|
return data |
|
|
|
except Exception as e: |
|
|
|
return str(e) |