From b205a9b8ba83115dcb62a4520b4e5fc43540abc1 Mon Sep 17 00:00:00 2001 From: venkata akhil Date: Fri, 1 Dec 2023 18:32:35 +0530 Subject: [PATCH] Torque manual publish --- smart_service/apis/publish_api.py | 2 +- smart_service/apis/v2/master.py | 44 ++- .../doctype/feature_finder/feature_finder.js | 8 + .../torque_manual_publish_data/__init__.py | 0 .../torque_manual_publish_data.json | 99 +++++++ .../torque_manual_publish_data.py | 8 + .../torque_manual_publish_docs/__init__.py | 0 .../torque_manual_publish_docs.json | 92 ++++++ .../torque_manual_publish_docs.py | 8 + .../training_information.json | 2 +- .../transactions/doctype/publish/publish.js | 280 +++++++++++++++++- .../transactions/doctype/publish/publish.json | 24 +- .../transactions/doctype/publish/publish.py | 275 ++++++++++++++++- 13 files changed, 814 insertions(+), 28 deletions(-) create mode 100644 smart_service/phase_2/doctype/torque_manual_publish_data/__init__.py create mode 100644 smart_service/phase_2/doctype/torque_manual_publish_data/torque_manual_publish_data.json create mode 100644 smart_service/phase_2/doctype/torque_manual_publish_data/torque_manual_publish_data.py create mode 100644 smart_service/phase_2/doctype/torque_manual_publish_docs/__init__.py create mode 100644 smart_service/phase_2/doctype/torque_manual_publish_docs/torque_manual_publish_docs.json create mode 100644 smart_service/phase_2/doctype/torque_manual_publish_docs/torque_manual_publish_docs.py diff --git a/smart_service/apis/publish_api.py b/smart_service/apis/publish_api.py index 0b1aefd..90244d8 100644 --- a/smart_service/apis/publish_api.py +++ b/smart_service/apis/publish_api.py @@ -488,7 +488,7 @@ def new_publish(args, publish_type, vehicle, language, version): return True, file_name1.split("public")[1] else: - pub_ver = frappe.db.sql(""" SELECT vehicle,language,format(version,2) as version,modified,publish_type FROM tabPublish where vehicle = "{}" + pub_ver = frappe.db.sql(""" SELECT vehicle,language,format(version,2) as version,modified,publish_type FROM `tabPublish` where vehicle = "{}" and publish_type = "Global" AND `language` = "{}" and publish_module="Automotive System" order by modified desc;""".format(vehicle, language), as_dict=1) if pub_ver: diff --git a/smart_service/apis/v2/master.py b/smart_service/apis/v2/master.py index d04e9cf..58f8a68 100644 --- a/smart_service/apis/v2/master.py +++ b/smart_service/apis/v2/master.py @@ -292,8 +292,7 @@ def new_publish(): qp_rhs['content'] = cnverted_data elif module == 'Training Information': - # flag, data = get_training_information(vehicle, language) - pass + flag, data = get_training_information(vehicle, language) elif module == 'Mahindra Special Tool Information': CLEANR_back_slash = re.compile("\"") @@ -314,8 +313,8 @@ def new_publish(): elif module == 'PDI Inspection': pass - elif module == 'Torque Information NM': - pass + elif module == 'Torque Manual': + flag,data = get_torque_manual(variant,language) else: flag = False @@ -357,8 +356,8 @@ def new_publish1(): else: return {"status": 0, "error": "Publish Type Not Set For: " + iid} - # BASE_PATH = BASE_URL + "/files/json_files/phase2/" + \ - # str(vehicle) + '/' + str(language) + '/' + str(publish_type) + '/' + BASE_PATH = BASE_URL + "/files/json_files/phase2/" + \ + str(vehicle) + '/' + str(language) + '/' + str(publish_type) + '/' FULL_UPDATE_PATH = BASE_URL + "/files/json_files/phase2/" + \ str(vehicle) + '/' + str(language) + '/' + \ "{}".format(publish_type)+"_Full_Update/" @@ -424,8 +423,11 @@ def new_publish1(): elif module == 'PDI Inspection': pass - elif module == 'Torque Information NM': - pass + elif module == 'Torque Manual': + with open(BASE_PATH + str(vehicle) + '-torque_manual.json') as outfile: + data = json.load(outfile) + data = data.get('data') + data = data.get(variant) else: data = 'No Module found' @@ -477,7 +479,33 @@ def get_qwik_service(variant, language): return True, qwik_service_details except Exception as e: return False, e + + +@frappe.whitelist(methods=["POST"], allow_guest=1) +def get_torque_manual(variant,language): + try: + 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) + return True,torque_manual_details + except Exception as e: + return False , e +@frappe.whitelist(methods=["POST"], allow_guest=1) +def get_training_information(vehicle,language): + try: + training_information_details = frappe.db.sql('''select name,vehicle,category,display_order,active_status,my_id from + `tabTraining Information` where vehicle = '%s' && language = '%s';'''%(vehicle,language),as_dict=1) + for i in training_information_details: + i['content'] = frappe.db.sql('''select idx as 'display_order',topic,content from `tabTraining Information Content Reference` + where parent = '%s' order by display_order;'''%(i['name']),as_dict=1) + + return True, training_information_details + except Exception as e: + raise e + @frappe.whitelist(allow_guest=1) def update_publish_mapping(vehicle, variant, language, module): diff --git a/smart_service/phase_2/doctype/feature_finder/feature_finder.js b/smart_service/phase_2/doctype/feature_finder/feature_finder.js index 92f1775..c032815 100644 --- a/smart_service/phase_2/doctype/feature_finder/feature_finder.js +++ b/smart_service/phase_2/doctype/feature_finder/feature_finder.js @@ -1150,6 +1150,13 @@ function custom_tab_html(frm) { // size: 'small', // small, large, extra-large primary_action_label: 'Submit', primary_action(values) { + //Not allow more than 500 cahracters + var args = spec_dia.get_values(); + var content_limit = args.content.length + if(content_limit>500){ + frappe.throw("Content: Only 500 characters are allowed") + } + if (values && values.content) { frappe.call({ method: "smart_service.phase_2.doctype.feature_finder.feature_finder.insert_content_data", @@ -1160,6 +1167,7 @@ function custom_tab_html(frm) { }, callback: function (r) { if (r.message.status == "success") { + frappe.show_alert({ message: __('Submited data will be auto saved'), indicator: 'green' diff --git a/smart_service/phase_2/doctype/torque_manual_publish_data/__init__.py b/smart_service/phase_2/doctype/torque_manual_publish_data/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/smart_service/phase_2/doctype/torque_manual_publish_data/torque_manual_publish_data.json b/smart_service/phase_2/doctype/torque_manual_publish_data/torque_manual_publish_data.json new file mode 100644 index 0000000..24f35a6 --- /dev/null +++ b/smart_service/phase_2/doctype/torque_manual_publish_data/torque_manual_publish_data.json @@ -0,0 +1,99 @@ +{ + "actions": [], + "allow_rename": 1, + "creation": "2023-12-01 16:25:50.626564", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "is_published", + "variant", + "vehicle", + "language", + "display_order", + "category", + "active_status", + "sub_category", + "parent1" + ], + "fields": [ + { + "default": "0", + "fieldname": "is_published", + "fieldtype": "Check", + "label": "Published", + "read_only": 1 + }, + { + "fieldname": "variant", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Variant", + "options": "Variant Mapping", + "read_only": 1 + }, + { + "fetch_from": "variant.vehicle", + "fieldname": "vehicle", + "fieldtype": "Data", + "in_list_view": 1, + "in_standard_filter": 1, + "label": "Vehicle", + "read_only": 1 + }, + { + "fieldname": "language", + "fieldtype": "Link", + "label": "Language", + "options": "Custom Languages" + }, + { + "fieldname": "display_order", + "fieldtype": "Int", + "in_standard_filter": 1, + "label": "Display Order", + "read_only": 1 + }, + { + "fieldname": "category", + "fieldtype": "Data", + "in_list_view": 1, + "in_standard_filter": 1, + "label": "Category", + "read_only": 1 + }, + { + "fieldname": "sub_category", + "fieldtype": "Data", + "in_global_search": 1, + "in_standard_filter": 1, + "label": "Sub Category", + "read_only": 1 + }, + { + "fieldname": "parent1", + "fieldtype": "Link", + "in_standard_filter": 1, + "label": "Parent", + "options": "Torque Manual", + "read_only": 1 + }, + { + "fieldname": "active_status", + "fieldtype": "Select", + "label": "Active Status", + "options": "Active\nInactive" + } + ], + "index_web_pages_for_search": 1, + "istable": 1, + "links": [], + "modified": "2023-12-01 18:20:24.959655", + "modified_by": "Administrator", + "module": "Phase-2", + "name": "Torque Manual Publish Data", + "owner": "Administrator", + "permissions": [], + "sort_field": "modified", + "sort_order": "DESC" +} \ No newline at end of file diff --git a/smart_service/phase_2/doctype/torque_manual_publish_data/torque_manual_publish_data.py b/smart_service/phase_2/doctype/torque_manual_publish_data/torque_manual_publish_data.py new file mode 100644 index 0000000..c4cb460 --- /dev/null +++ b/smart_service/phase_2/doctype/torque_manual_publish_data/torque_manual_publish_data.py @@ -0,0 +1,8 @@ +# Copyright (c) 2023, Hard n Soft Technologies Pvt Ltd and contributors +# For license information, please see license.txt + +# import frappe +from frappe.model.document import Document + +class TorqueManualPublishData(Document): + pass diff --git a/smart_service/phase_2/doctype/torque_manual_publish_docs/__init__.py b/smart_service/phase_2/doctype/torque_manual_publish_docs/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/smart_service/phase_2/doctype/torque_manual_publish_docs/torque_manual_publish_docs.json b/smart_service/phase_2/doctype/torque_manual_publish_docs/torque_manual_publish_docs.json new file mode 100644 index 0000000..c409431 --- /dev/null +++ b/smart_service/phase_2/doctype/torque_manual_publish_docs/torque_manual_publish_docs.json @@ -0,0 +1,92 @@ +{ + "actions": [], + "allow_rename": 1, + "creation": "2023-12-01 16:42:33.197929", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "variant", + "vehicle", + "language", + "display_order", + "category", + "sub_category", + "active_status", + "parent1" + ], + "fields": [ + { + "fieldname": "variant", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Variant", + "options": "Variant Mapping", + "read_only": 1 + }, + { + "fetch_from": "variant.vehicle", + "fieldname": "vehicle", + "fieldtype": "Data", + "in_list_view": 1, + "in_standard_filter": 1, + "label": "Vehicle", + "read_only": 1 + }, + { + "fieldname": "language", + "fieldtype": "Link", + "label": "Language", + "options": "Custom Languages", + "set_only_once": 1 + }, + { + "fieldname": "display_order", + "fieldtype": "Int", + "in_standard_filter": 1, + "label": "Display Order", + "read_only": 1 + }, + { + "fieldname": "category", + "fieldtype": "Data", + "in_list_view": 1, + "in_standard_filter": 1, + "label": "Category", + "read_only": 1 + }, + { + "fieldname": "sub_category", + "fieldtype": "Data", + "in_global_search": 1, + "in_standard_filter": 1, + "label": "Sub Category", + "read_only": 1 + }, + { + "fieldname": "parent1", + "fieldtype": "Link", + "in_standard_filter": 1, + "label": "Parent", + "options": "Torque Manual", + "read_only": 1 + }, + { + "fieldname": "active_status", + "fieldtype": "Select", + "label": "Active status", + "options": "Active\nInactive" + } + ], + "index_web_pages_for_search": 1, + "istable": 1, + "links": [], + "modified": "2023-12-01 18:20:06.958959", + "modified_by": "Administrator", + "module": "Phase-2", + "name": "Torque Manual Publish Docs", + "owner": "Administrator", + "permissions": [], + "sort_field": "modified", + "sort_order": "DESC" +} \ No newline at end of file diff --git a/smart_service/phase_2/doctype/torque_manual_publish_docs/torque_manual_publish_docs.py b/smart_service/phase_2/doctype/torque_manual_publish_docs/torque_manual_publish_docs.py new file mode 100644 index 0000000..c9a5a3d --- /dev/null +++ b/smart_service/phase_2/doctype/torque_manual_publish_docs/torque_manual_publish_docs.py @@ -0,0 +1,8 @@ +# Copyright (c) 2023, Hard n Soft Technologies Pvt Ltd and contributors +# For license information, please see license.txt + +# import frappe +from frappe.model.document import Document + +class TorqueManualPublishDocs(Document): + pass diff --git a/smart_service/phase_2/doctype/training_information/training_information.json b/smart_service/phase_2/doctype/training_information/training_information.json index 29a72f0..f833a4c 100644 --- a/smart_service/phase_2/doctype/training_information/training_information.json +++ b/smart_service/phase_2/doctype/training_information/training_information.json @@ -99,7 +99,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2023-12-01 13:19:50.127628", + "modified": "2023-12-01 14:20:25.382259", "modified_by": "Administrator", "module": "Phase-2", "name": "Training Information", diff --git a/smart_service/transactions/doctype/publish/publish.js b/smart_service/transactions/doctype/publish/publish.js index 8762648..3d28464 100644 --- a/smart_service/transactions/doctype/publish/publish.js +++ b/smart_service/transactions/doctype/publish/publish.js @@ -88,6 +88,14 @@ frappe.ui.form.on("Publish", { cur_frm.set_df_property("feature_finder_publish_docs", "read_only", 1); frm.refresh_field("feature_finder_publish_docs"); } + if ( + frm.doc.hasOwnProperty("torque_manual_publish_docs") && + frm.doc.feature_finder_publish_docs.length > 0 && frm.doc.docstatus == 1 + ) { + frm.set_df_property("torque_manual_publish_docs", "hidden", 0); + cur_frm.set_df_property("torque_manual_publish_docs", "read_only", 1); + frm.refresh_field("torque_manual_publish_docs"); + } if ( frm.doc.hasOwnProperty("qwik_service_publish_docs") && frm.doc.qwik_service_publish_docs.length > 0 @@ -116,6 +124,18 @@ frappe.ui.form.on("Publish", { cur_frm.set_df_property("feature_finder_publish", "read_only", 1); } } + if (frm.doc.docstatus == 1 && frm.doc.publish_module == "Torque Manual") { + // cur_frm.set_df_property("kilometer_mapping_details", "hidden", 1); + cur_frm.set_df_property("torque_manual_publish_docs", "read_only", 1); + cur_frm.refresh_field("torque_manual_publish_docs"); + cur_frm.refresh_field("kilometer_mapping_details"); + cur_frm.remove_custom_button("Add To Publish"); + if (frm.doc.feature_finder_publish.length > 0) { + frm.set_df_property("torque_manual_publish", "hidden", 1); + frm.refresh_field("torque_manual_publish"); + cur_frm.set_df_property("torque_manual_publish", "read_only", 1); + } + } if (frm.doc.docstatus == 1 && frm.doc.publish_module == "Repair service") { cur_frm.set_df_property("repiar_checksheet_publish_docs", "read_only", 1); @@ -178,6 +198,22 @@ frappe.ui.form.on("Publish", { cur_frm.set_df_property("feature_finder_publish_docs", "hidden", 0); cur_frm.refresh_field("feature_finder_publish_docs"); } + if ( + (frm.doc.docstatus != 1 && + frm.doc.publish_module == "Torque Manual" && + frm.doc.torque_manual_publish_docs.length > 0 && + frm.doc.publish_type == "Internal") || + frm.doc.publish_type == "Global" + ) { + // cur_frm.set_df_property("kilometer_mapping_details", "hidden", 1); + + cur_frm.refresh_field("torque_manual_publish_docs"); + cur_frm.refresh_field("kilometer_mapping_details"); + cur_frm.remove_custom_button("Add To Publish"); + + cur_frm.set_df_property("torque_manual_publish_docs", "hidden", 0); + cur_frm.refresh_field("torque_manual_publish_docs"); + } if ( (frm.doc.docstatus != 1 && frm.doc.publish_module == "Repair service") || frm.doc.publish_type == "Internal" || @@ -848,6 +884,9 @@ frappe.ui.form.on("Publish", { if (frm.doc.publish_module == "Feature Finder") { add_feature_finder(frm); } + if (frm.doc.publish_module == "Torque Manual") { + add_torque_manual(frm); + } if(frm.doc.publish_module == "Qwik Service"){ add_qwik_service(frm) } @@ -896,6 +935,53 @@ frappe.ui.form.on("Publish", { frm.fields_dict.repair_checksheet_publish.grid.grid_buttons.find('.btn-custom').removeClass('btn-default').addClass('btn-primary'); } + if (frm.doc.docstatus === 0 && frm.doc.publish_status == 'To Publish' && frm.doc.publish_module=='Torque Manual') { + + frm.get_field('torque_manual_publish').grid.add_custom_button(__('Add to Publish'), function () { + let added = 0; + frm.doc.torque_manual_publish.forEach(row => { + if (row.active_status == "Active" || row.active_status == "Inactive") { + let dulicate = false; + if (frm.doc.torque_manual_publish_docs) { + frm.doc.torque_manual_publish_docs.forEach(publishrow => { + if (row.parent1 == publishrow.parent1) { + + dulicate = true; + } + }); + } + if (dulicate === false) { + let child = cur_frm.add_child("torque_manual_publish_docs"); + child.vehicle = frm.doc.vehicle; + child.parent1 = row.parent1; + child.language = row.language; + child.variant = row.variant; + child.category= row.category; + child.sub_category= row.sub_category; + child.active_status = row.active_status; + added += 1; + frm.set_df_property('torque_manual_publish_docs','hidden',0) + cur_frm.refresh_field("torque_manual_publish",'read_only',1); + refresh_field("torque_manual_publish_docs"); + cur_frm.set_df_property("torque_manual_publish",'read_only',1); + document.getElementsByClassName('btn btn-xs btn-secondary grid-add-row')[4] .setAttribute("style","display:none;"); + document.getElementsByClassName('btn btn-xs btn-secondary grid-add-row')[5] .setAttribute("style","display:none;"); + } + else{ + frappe.msgprint(__(row.parent1 + 'Alraeady Added')) + } + cur_frm.refresh_field("torque_manual_publish_docs",'read_only',1); + } + }); + if (added) { frappe.msgprint(__(added + " Doc(s) Added")); + cur_frm.set_df_property('torque_manual_publish','read_only',1) + cur_frm.set_df_property("torque_manual_publish_docs",'read_only',1); + cur_frm.refresh_field("torque_manual_publish"); } + else if(added==0) { frappe.msgprint(__("No Doc Added")); } + }); + + frm.fields_dict.torque_manual_publish.grid.grid_buttons.find('.btn-custom').removeClass('btn-default').addClass('btn-primary'); + } if (frm.doc.publish_module == "Automotive System") { let km_name = frm.doc.variant_mapping + "-" + frm.doc.language + "-KM"; frappe.db.get_value( @@ -1082,15 +1168,26 @@ frappe.ui.form.on("Publish", { frappe.msgprint("Variant Mapping already added"); } - if (dulicate === false && frm.doc.publish_module == 'Feature Finder') { - let child = cur_frm.add_child("feature_finder_publish_docs"); + if(frm.doc.torque_manual_publish_docs && frm.doc.publish_module=='Torque Manual'){ + frm.doc.publish_documents.forEach(publishrow => { + if (frm.doc.variant_mapping == publishrow.variant_mapping) { + dulicate = true; + } + }); + frappe.msgprint("Variant Mapping already added"); + + } + if (dulicate === false && frm.doc.publish_module == 'Torque Manual') { + let child = cur_frm.add_child("torque_manual_publish_docs"); child.variant_mapping = frm.doc.variant_mapping; child.vehicle = frm.doc.vehicle; child.parent1 = row.parent1; child.language = row.language; + child.category= row.category; + child.sub_category= row.sub_category; child.variant = row.variant; child.active_status = row.active_status; - refresh_field("feature_finder_publish_docs"); + refresh_field("torque_manual_publish_docs"); frappe.msgprint(__(frm.doc.variant_mapping + " Added")); } else{ @@ -1201,9 +1298,11 @@ frappe.ui.form.on("Publish", { frm.set_value("repair_checksheet_publish", ""); frm.set_value("feature_finder_publish", ""); frm.set_value("qwik_service_publish",""); + frm.set_value("torque_manual_publish",""); frm.set_value("repiar_checksheet_publish_docs", ""); frm.set_value("feature_finder_publish_docs", ""); frm.set_value("qwik_service_publish_docs", ""); + frm.set_value("torque_manual_publish_docs", ""); if (frm.doc.publish_module == "Repair service" && frm.doc.vehicle) { @@ -1230,6 +1329,19 @@ frappe.ui.form.on("Publish", { cur_frm.refresh_fields("feature_finder_publish"); } } + if ( + frm.doc.publish_module == "Torque Manual" && + frm.doc.vehicle && + frm.doc.variant_mapping + ) { + if ( + frm.doc.torque_manual_publish && + frm.doc.torque_manual_publish.length > 0 + ) { + cur_frm.clear_table("torque_manual_publish"); + cur_frm.refresh_fields("torque_manual_publish"); + } + } if ( frm.doc.publish_module == "Qwik Service" && @@ -1289,7 +1401,22 @@ frappe.ui.form.on("Publish", { } ); - } + } + if (!lang_set_first_time && frm.doc.publish_module == "Torque Manual") { + frappe.confirm( + "This will clear all the data, are you sure you want to proceed?", + () => { + // action to perform if Yes is selected + frm.set_value("torque_manual_publish", null); + frm.set_value("variant_mapping", ""); + lang_set_first_time = false; + }, + () => { + // action to perform if No is selected + } + ); + + } if (!lang_set_first_time && frm.doc.publish_module == "Qwik Service") { frappe.confirm( "This will clear all the data, are you sure you want to proceed?", @@ -1342,10 +1469,12 @@ frappe.ui.form.on("Publish", { frm.doc.feature_finder_publish = ""; frm.doc.qwik_service_publish=""; frm.doc.special_tool_publish=""; + frm.doc.torque_manual_publish=""; frm.set_value("feature_finder_publish_docs", ""); frm.set_value("repiar_checksheet_publish_docs", ""); frm.set_value("qwik_service_publish_docs", ""); frm.set_value("special_tool_publish_docs",""); + frm.set_value("torque_manual_publish_docs",""); frm.set_df_property("repiar_checksheet_publish_docs", "hidden", 1); frm.refresh_fields(); if (frm.doc.publish_module == "Repair service") { @@ -1357,6 +1486,10 @@ frappe.ui.form.on("Publish", { if (frm.doc.publish_module == "Feature Finder") { add_feature_finder(frm); } + if (frm.doc.publish_module == "Torque Manual") { + add_torque_manual(frm); + } + if(frm.doc.publish_module == "Qwik Service"){ add_qwik_service(frm) } @@ -1644,6 +1777,145 @@ function add_feature_finder(frm) { }, }); } +function add_torque_manual(frm) { + cur_frm.clear_table("torque_manual_publish"); + cur_frm.refresh_fields(); + var fin_add_btn = document + .getElementsByClassName("btn btn-xs btn-secondary grid-add-row")[3] + .setAttribute("style", "display:none;"); + + frappe.call({ + method: + "smart_service.transactions.doctype.publish.publish.get_torque_manual", + args: { + vehicle: frm.doc.vehicle, + variant: frm.doc.variant_mapping, + language_label: frm.doc.language, + publish_type: frm.doc.publish_type, + }, + callback: function (r) { + if (r.message.length > 0) { + cur_frm.set_df_property("torque_manual_publish", "hidden", 0); + var records = r.message; + records.map((v) => { + var childTable = cur_frm.add_child("torque_manual_publish"); + childTable.parent1 = v["name"]; + childTable.vehicle = v["vehicle"]; + childTable.language = v["language"]; + childTable.variant = v["variant"]; + childTable.active_status = v["active_status"]; + childTable.category = v["category"]; + childTable.sub_category = v["sub_category"] + }); + //add to repair service published doc table + if ( + frm.doc.docstatus === 0 && + frm.doc.publish_status == "To Publish" && + frm.doc.publish_module == "Torque Manual" + ) { + frm + .get_field("torque_manual_publish") + .grid.add_custom_button(__("Add to Publish"), function () { + let added = 0; + frm.doc.torque_manual_publish.forEach((row) => { + if ( + row.active_status == "Active" || + row.active_status == "Inactive" + ) { + let dulicate = false; + if (frm.doc.torque_manual_publish) { + frm.doc.torque_manual_publish_docs.forEach( + (publishrow) => { + if (row.parent1 == publishrow.parent1) { + dulicate = true; + } + } + ); + } + if (dulicate === false) { + let child = cur_frm.add_child( + "torque_manual_publish_docs" + ); + child.vehicle = frm.doc.vehicle; + child.parent1 = row.parent1; + child.language = row.language; + child.variant = row.variant; + child.category= row.category; + child.sub_category= row.sub_category; + child.active_status = row.active_status; + added += 1; + frm.set_df_property( + "torque_manual_publish_docs", + "hidden", + 0 + ); + cur_frm.refresh_field( + "torque_manual_publish", + "read_only", + 1 + ); + refresh_field("torque_manual_publish_docs"); + cur_frm.set_df_property( + "torque_manual_publish", + "read_only", + 1 + ); + document + .getElementsByClassName( + "btn btn-xs btn-secondary grid-add-row" + )[4] + .setAttribute("style", "display:none;"); + document + .getElementsByClassName( + "btn btn-xs btn-secondary grid-add-row" + )[5] + .setAttribute("style", "display:none;"); + + frm.fields_dict.torque_manual_publish.grid.grid_buttons + .find(".btn-custom") + .removeClass("btn-default") + .addClass("btn-primary"); + } else { + frappe.msgprint(__(row.parent1 + "Alraeady Added")); + } + cur_frm.refresh_field( + "torque_manual_publish_docs", + "read_only", + 1 + ); + } + }); + if (added) { + frappe.msgprint(__(added + " Doc(s) Added")); + cur_frm.set_df_property( + "torque_manual_publish", + "read_only", + 1 + ); + cur_frm.set_df_property( + "torque_manual_publish_docs", + "read_only", + 1 + ); + cur_frm.refresh_field("torque_manual_publish"); + } else if (added == 0) { + frappe.msgprint(__("No Doc Added")); + } + }); + frm.fields_dict.torque_manual_publish.grid.grid_buttons + .find(".btn-custom") + .removeClass("btn-default") + .addClass("btn-primary"); + } + cur_frm.set_df_property("torque_manual_publish", "hidden", 0); + cur_frm.refresh_field("torque_manual_publish"); + let find_add_btn = document + .getElementsByClassName("btn btn-xs btn-secondary grid-add-row")[3] + .setAttribute("style", "display:none;"); + } + }, + }); +} function add_qwik_service(frm){ cur_frm.clear_table("Qwik_service_publish"); cur_frm.refresh_fields(); diff --git a/smart_service/transactions/doctype/publish/publish.json b/smart_service/transactions/doctype/publish/publish.json index 8e8c129..81297d1 100644 --- a/smart_service/transactions/doctype/publish/publish.json +++ b/smart_service/transactions/doctype/publish/publish.json @@ -53,7 +53,9 @@ "qwik_service_publish", "qwik_service_publish_docs", "special_tool_publish", - "special_tool_publish_docs" + "special_tool_publish_docs", + "torque_manual_publish", + "torque_manual_publish_docs" ], "fields": [ { @@ -108,7 +110,7 @@ "set_only_once": 1 }, { - "depends_on": "eval:doc.vehicle && doc.docstatus == 0 && doc.publish_module=='Automotive System' || doc.publish_module=='Feature Finder' || doc.publish_module=='Qwik Service' ", + "depends_on": "eval:doc.vehicle && doc.docstatus == 0 && doc.publish_module=='Automotive System' || doc.publish_module=='Feature Finder' || doc.publish_module=='Qwik Service' || doc.publish_module=='Qwik Service' || doc.publish_module=='Torque Manual' ", "fieldname": "variant_mapping", "fieldtype": "Link", "in_list_view": 1, @@ -328,7 +330,7 @@ "in_list_view": 1, "in_standard_filter": 1, "label": "Module", - "options": "Automotive System\nFeature Finder\nRepair service\nQwik Service\nSpecial Tool", + "options": "Automotive System\nFeature Finder\nRepair service\nQwik Service\nSpecial Tool\nTorque Manual", "reqd": 1 }, { @@ -403,12 +405,26 @@ "fieldname": "variant_mapping_html", "fieldtype": "HTML", "label": "Variant Mapping HTML" + }, + { + "depends_on": "eval:doc.publish_module =='Torque Manual';", + "fieldname": "torque_manual_publish", + "fieldtype": "Table", + "label": "Torque Manual Publish", + "options": "Torque Manual Publish Data" + }, + { + "depends_on": "eval:doc.publish_module =='Torque Manual';", + "fieldname": "torque_manual_publish_docs", + "fieldtype": "Table", + "label": "Torque Manual Publish Docs", + "options": "Torque Manual Publish Docs" } ], "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], - "modified": "2023-11-27 12:34:08.109971", + "modified": "2023-12-01 17:39:07.089216", "modified_by": "Administrator", "module": "Transactions", "name": "Publish", diff --git a/smart_service/transactions/doctype/publish/publish.py b/smart_service/transactions/doctype/publish/publish.py index aeaa997..b014ab7 100644 --- a/smart_service/transactions/doctype/publish/publish.py +++ b/smart_service/transactions/doctype/publish/publish.py @@ -59,15 +59,8 @@ class Publish(Document): str(km_mapping.name) + '\n' 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, @@ -124,6 +127,23 @@ class Publish(Document): update_special_tool_publish_docs(self) 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, @@ -210,6 +230,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): @@ -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) \ No newline at end of file