From fbd0c484ca5a235968eef2b7a8460f440dc6ecf1 Mon Sep 17 00:00:00 2001 From: venkataakhil Date: Fri, 18 Aug 2023 16:51:14 +0530 Subject: [PATCH 1/2] Publish pHase 2 api integration --- smart_service/apis/master_api.py | 9 +- smart_service/apis/update_validation.py | 7 +- smart_service/apis/v2/master.py | 49 ++++- .../module_publish_mapping.json | 4 +- .../transactions/doctype/publish/publish.js | 107 +++++----- .../transactions/doctype/publish/publish.json | 4 +- .../transactions/doctype/publish/publish.py | 183 ++++++++++-------- 7 files changed, 207 insertions(+), 156 deletions(-) diff --git a/smart_service/apis/master_api.py b/smart_service/apis/master_api.py index a382d38..0d2b9fe 100644 --- a/smart_service/apis/master_api.py +++ b/smart_service/apis/master_api.py @@ -401,13 +401,8 @@ def app_modules(LSD): @frappe.whitelist(methods=["POST"], allow_guest=1) -def role_mapping(): - # logger_file = f'Role Mapping' - # logger = frappe.logger(logger_file, allow_site=True, file_count=100) - - # logger.info(f'Start') +def role_mapping(): req = json.loads(frappe.request.data) - try: lsdt = req['LSD'] if lsdt != '': @@ -435,9 +430,7 @@ def role_mapping(): for r in role_maping_details: role_list = r['modules'].split(",") - # logger.info(f'Module data-{module_details1}') modules = copy.deepcopy(module_details1) - # logger.info(f'Module-{modules}') for m in modules: if m['module_name'] in role_list: m['active_status'] = 1 diff --git a/smart_service/apis/update_validation.py b/smart_service/apis/update_validation.py index b4e1fba..61f897f 100644 --- a/smart_service/apis/update_validation.py +++ b/smart_service/apis/update_validation.py @@ -2,14 +2,15 @@ import frappe from frappe.model.document import Document import json import os -from frappe.utils import cstr + import time from smart_service.apis.app_user_login import input_validation -current_db_name = frappe.conf.get("db_name") + +from frappe.utils import cstr site_name = cstr(frappe.local.site) base_url = os.path.expanduser( "~") + "/frappe-bench/sites/" + site_name + "/public" - +current_db_name = frappe.conf.get("db_name") # Constants JSON_EXT = ".json" JSON_INT_PATH = "/files/json_files/internal/" diff --git a/smart_service/apis/v2/master.py b/smart_service/apis/v2/master.py index 33f6174..365b6de 100644 --- a/smart_service/apis/v2/master.py +++ b/smart_service/apis/v2/master.py @@ -4,8 +4,12 @@ from urllib import request import datetime from frappe import utils import json - +import os from smart_service.apis.app_user_login import input_validation +from frappe.utils import cstr +site_name = cstr(frappe.local.site) +BASE_URL = os.path.expanduser( + "~") + "/frappe-bench/sites/" + site_name + "/public" date_format = "%Y-%m-%d %H:%M:%S.%f" current_db_name = frappe.conf.get("db_name") @@ -174,6 +178,49 @@ def new_publish(): return {'status': 0, 'error': "Parameter's missing: " + str(e), 'data': None} +@frappe.whitelist(methods=['POST']) +def new_publish1(): + req = json.loads(frappe.request.data) + try: + module = req['module'] + iid = req['iid'] + vehicle = req['vehicle'] + variant = req['variant'] + language = req['language'] + + data = [] + # Get Publish Type + 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'] + + BASE_PATH = BASE_URL + "/files/json_files/phase2/" + \ + str(vehicle) + '/' + str(language) + '/' + str(publish_type) + '/' + + if module == 'Feature Finder': + with open(BASE_PATH + str(vehicle) + '-feature_finder.json') as outfile: + data = json.load(outfile) + data = data['data'] + + elif module == 'Repair/Service Check Sheet': + with open(BASE_PATH + str(vehicle) + '-repair_check_sheet.json') as outfile: + data = json.load(outfile) + data = data['data'] + + # elif module == 'Training Information': + # flag, data = get_training_information(vehicle, language) + + # elif module == "Mahindra Special Tool Information": + # flag, data = get_special_tool_information(vehicle) + return {'status': 1, 'error': None, 'data': data} + + except Exception as e: + frappe.local.response['http_status_code'] = 400 + return {'status': 0, 'error': "Parameter's missing: " + str(e), 'data': None} + + @frappe.whitelist(methods=['POST'], allow_guest=1) def get_special_tool_information(vehicle): try: diff --git a/smart_service/phase_2/doctype/module_publish_mapping/module_publish_mapping.json b/smart_service/phase_2/doctype/module_publish_mapping/module_publish_mapping.json index cbb2d3d..b0debfe 100644 --- a/smart_service/phase_2/doctype/module_publish_mapping/module_publish_mapping.json +++ b/smart_service/phase_2/doctype/module_publish_mapping/module_publish_mapping.json @@ -1,7 +1,7 @@ { "actions": [], "allow_rename": 1, - "autoname": "format:{vehicle}-{variant}-{language}", + "autoname": "format:{variant}-{language}", "creation": "2023-08-07 12:44:24.978007", "doctype": "DocType", "editable_grid": 1, @@ -107,7 +107,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2023-08-07 12:52:27.310290", + "modified": "2023-08-18 16:49:35.315359", "modified_by": "Administrator", "module": "Phase-2", "name": "Module Publish Mapping", diff --git a/smart_service/transactions/doctype/publish/publish.js b/smart_service/transactions/doctype/publish/publish.js index f1f50b3..9e8bee9 100644 --- a/smart_service/transactions/doctype/publish/publish.js +++ b/smart_service/transactions/doctype/publish/publish.js @@ -62,6 +62,34 @@ frappe.ui.form.on('Publish', { debugger $('[data-route="Form/Publish/' + frm.doc.name + '"]').find('.primary-action').html("Global Publish") } + if (frm.doc.docstatus === 1 && frm.doc.publish_type == "Internal" && frm.doc.publish_status == 'Published' && frm.doc.publish_module!='Automotive System' && !frm.doc.global_publish && frappe.user.has_role('_Publisher')) { + debugger + frappe.call({ + method: "smart_service.transactions.doctype.publish.publish.max_publish_new_module", + args: { + "doc": frm.doc.name, + }, + callback: function (r) { + if (r.message==frm.doc.version) { + debugger + if (r.message == frm.doc.version) { + frm.add_custom_button(__('Global Publish'), function () { + frappe.call({ + method: "smart_service.transactions.doctype.publish.publish.generate_global_publish", + args: { + "name": frm.doc.name, + }, + callback: function (r) { + cur_frm.reload_doc(); + } + }); + }).addClass("btn-warning").css({ 'background-color': '#f5b0cd', 'color': 'black' }); + } + } + } + }) + } + if (frm.doc.publish_module == 'Automotive System') { cur_frm.set_df_property('system_mapping', "read_only", 1); cur_frm.fields_dict['system_mapping'].grid.wrapper.find('.grid-add-row').hide(); @@ -312,70 +340,29 @@ frappe.ui.form.on('Publish', { } } - + - if (frm.doc.docstatus == 1 && !frm.is_new() && frm.doc.publish_type != "Global" && frm.doc.publish_module != 'Automotive System') { + if (frm.doc.docstatus == 1 && frm.doc.publish_status == 'To Publish' && !frm.is_new() && frm.doc.publish_type != "Global" && frm.doc.publish_module != 'Automotive System') { debugger frappe.call({ - method: "smart_service.transactions.doctype.publish.publish.max_publish_new_module", - args: { - - "doc": frm.doc.name - }, - callback: function (r) { - debugger - if (r.message) { - debugger - if (r.message) { - frm.add_custom_button(__('Global Publish'), function () { - frappe.call({ - method: "smart_service.transactions.doctype.publish.publish.generate_global_publish", - args: { - name: frm.doc.name - }, - callback: function (r) { - - if (r.message.status == "success") { - - window.location.href = r.message.url + "/app/publish" + "/" + r.message.message - } - } - }) - }).addClass("btn-primary"); - } - } - } - }) - frappe.call({ - method: "smart_service.transactions.doctype.publish.publish.max_publish_new_module", + method: "smart_service.transactions.doctype.publish.publish.cal_ver_new_module", args: { - "doc": frm.doc.name, + vehicle: frm.doc.vehicle, + lang: frm.doc.language, + publish_type: frm.doc.publish_type, + doc: frm.doc.name }, callback: function (r) { debugger if (r.message) { - debugger - if (r.message) { - frm.add_custom_button(__('Global Publish'), function () { - frappe.call({ - method: "smart_service.transactions.doctype.publish.publish.generate_global_publish", - args: { - name: frm.doc.name - }, - callback: function (r) { - - if (r.message.status == "success") { - - window.location.href = r.message.url + "/app/publish" + "/" + r.message.message - } - } - }) - }).addClass("btn-primary"); - } + frm.set_value('version', r.message); + cur_frm.refresh_field('version') + frm.set_value('actual_published_date', frappe.datetime.nowdate()); + } } }) - + } @@ -409,6 +396,7 @@ frappe.ui.form.on('Publish', { }, variant_mapping: function (frm) { + frappe.db.get_value('Variant Mapping', { name: frm.doc.variant_mapping }, ['fuel', 'transmission', 'drive'], (r) => { frm.doc.variant = r.fuel + ',' + r.transmission + ',' + r.drive; cur_frm.refresh_field('variant'); @@ -417,7 +405,7 @@ frappe.ui.form.on('Publish', { add_feature_finder(frm) } - + if (frm.doc.publish_module=='Automotive System') { let km_name = frm.doc.variant_mapping + "-" + frm.doc.language + "-KM"; frappe.db.get_value('Kilometer Mapping', { name: km_name }, 'workflow_state', (r) => { if (r.workflow_state == "Draft") { @@ -447,6 +435,7 @@ frappe.ui.form.on('Publish', { }); } }) + } }, km_active_status: function (frm) { @@ -559,7 +548,10 @@ frappe.ui.form.on('Publish', { } }, km_report: function (frm, cdt, cdn) { - frappe.set_route("query-report", 'Kilometer Mapping', { 'kilometer_mapping': frm.doc.kilometer_mapping }); + if (frm.doc.publish_module=='Automotive System') { + frappe.set_route("query-report", 'Kilometer Mapping', { 'kilometer_mapping': frm.doc.kilometer_mapping }); + } + }, after_save: function (frm) { frm.set_df_property('repair_checksheet_publish', 'hidden', 0) @@ -716,6 +708,8 @@ frappe.ui.form.on('Publish_Temp Doc', { }) function add_to_publish(frm) { + cur_frm.clear_table("repair_checksheet_publish") + cur_frm.refresh_fields(); if(frm.doc.vehicle){ frappe.call({ method: "smart_service.transactions.doctype.publish.publish.get_service_repair", @@ -749,7 +743,8 @@ function add_to_publish(frm) { } function add_feature_finder(frm){ - debugger + cur_frm.clear_table("feature_finder_publish") + cur_frm.refresh_fields(); frappe.call({ method: "smart_service.transactions.doctype.publish.publish.get_feature_finder", args: { vehicle: frm.doc.vehicle,variant:frm.doc.variant_mapping, language_label: frm.doc.language, publish_type: frm.doc.publish_type }, diff --git a/smart_service/transactions/doctype/publish/publish.json b/smart_service/transactions/doctype/publish/publish.json index 528903a..ea4f663 100644 --- a/smart_service/transactions/doctype/publish/publish.json +++ b/smart_service/transactions/doctype/publish/publish.json @@ -315,7 +315,7 @@ "fieldname": "publish_module", "fieldtype": "Select", "label": "Module", - "options": "\nAutomotive System\nRepair service\nFeature Finder", + "options": "\nAutomotive System\nFeature Finder\nRepair service", "reqd": 1 }, { @@ -336,7 +336,7 @@ "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], - "modified": "2023-08-17 10:11:07.549614", + "modified": "2023-08-18 13:01:25.808160", "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 8600cd7..1f7f684 100644 --- a/smart_service/transactions/doctype/publish/publish.py +++ b/smart_service/transactions/doctype/publish/publish.py @@ -15,12 +15,12 @@ sys.tracebacklimit = 0 site_name = cstr(frappe.local.site) base_url = os.path.expanduser( - "~") + "/frappe-bench/sites/" + site_name + "/public" + "/files" + "/json_files" + "/Other_Module" + "~") + "/frappe-bench/sites/" + site_name + "/public" + "/files" + "/json_files" + "/phase2" frappe.utils.logger.set_log_level("DEBUG") success_reponse = {"status": 1, "data": "", "message": ""} failure_reponse = {"status": 0, "data": "", "error": ""} -module_name='feature_finder' +module_name = 'feature_finder' class Publish(Document): @@ -50,34 +50,37 @@ 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_checksheet_publish(self.vehicle, self.vehicle_id, - self.language, self.publish_type, - self.release_description, self.variant, - self.repair_checksheet_publish) - # update_publish_status = frappe.db.sql( - # """update `tabPublish` set publish_status='Published' where name='{0}'""".format(self.name)) + repair_checksheet_publish(self.vehicle, self.vehicle_id, + self.language, self.publish_type, + self.release_description, self.variant, + self.repair_checksheet_publish) + 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 == 'Feature Finder' and self.publish_type == 'Internal' and self.feature_finder_publish: - feature_finder_publish(self.vehicle, self.vehicle_id, - self.language, self.publish_type, - self.release_description,self.feature_finder_publish,self.variant) - - if self.docstatus == 1 and self.publish_module =='Feature Finder' and self.publish_type == 'Global': - feature_finder_publish(self.vehicle, self.vehicle_id, - self.language, self.publish_type, - self.release_description,self.feature_finder_publish, - self.variant) + feature_finder_publish(self.vehicle, self.vehicle_id, + self.language, self.publish_type, + self.release_description, self.feature_finder_publish, 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': + feature_finder_publish(self.vehicle, self.vehicle_id, + self.language, self.publish_type, + self.release_description, self.feature_finder_publish, + self.variant) update_feature_published_docs(self) 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': - repair_checksheet_publish(self.vehicle, self.vehicle_id, - self.language, self.publish_type, - self.release_description, self.variant, - self.repair_checksheet_publish) + if self.docstatus == 1 and self.publish_status == 'To Publish' and self.publish_module == 'Repair service' and self.publish_type == 'Global' and self.repair_checksheet_publish: + repair_checksheet_publish(self.vehicle, self.vehicle_id, + self.language, self.publish_type, + self.release_description, self.variant, + self.repair_checksheet_publish) update_repair_published_docs(self) update_publish_status = frappe.db.sql( """update `tabPublish` set publish_status='Published' where name='{0}'""".format(self.name)) + def onload1(self): current_db_name = frappe.conf.get("db_name") # To validate updated procedure status @@ -244,7 +247,7 @@ def global_publish(doc): publish_record.vehicle = doc.vehicle publish_record.vehicle_id = doc.vehicle_id publish_record.variant_mapping = doc.variant_mapping - publish_record.publish_module=doc.publish_module + publish_record.publish_module = 'Automotive System' publish_record.variant_mapping_status = doc.variant_mapping_status publish_record.kilometer_mapping = doc.kilometer_mapping publish_record.km_active_status = doc.km_active_status @@ -278,17 +281,19 @@ def global_publish(doc): def generate_global_publish(name): try: res = frappe.get_doc("Publish", name) + ret = frappe.get_doc({ "doctype": "Publish", "vehicle": res.vehicle, "publish_type": "Global", "language": res.language, + "publish_status": "To Publish", "release_description": res.release_description, "publish_module": res.publish_module, - "feature_finder_publish":res.feature_finder_publish, - "repair_checksheet_publish":res.repair_checksheet_publish + "feature_finder_publish": res.feature_finder_publish, + "repair_checksheet_publish": res.repair_checksheet_publish }) - ret.insert() + ret.save() return {"status": "success", "message": ret.name, "url": frappe.utils.get_url()} except Exception as e: frappe.throw(str(e)) @@ -457,6 +462,7 @@ def update_procedure_value(name, file_path): "Publish", self.name, "published_by", str(name)) frappe.db.commit() + def update_feature_published_docs(self): try: @@ -465,9 +471,11 @@ def update_feature_published_docs(self): frappe.db.sql( """UPDATE `tabFeature Finder` set is_published=1 where name='{0}'""".format(d.parent1)) frappe.db.commit() - + except Exception as e: frappe.throw(str(e)) + + def update_repair_published_docs(self): try: @@ -476,7 +484,7 @@ def update_repair_published_docs(self): frappe.db.sql( """UPDATE `tabRepair Service Mapping` set published=1 where name='{0}'""".format(d.parent_name)) frappe.db.commit() - + except Exception as e: frappe.throw(str(e)) @@ -498,18 +506,21 @@ def create_publish_folders(folder_url): '''New Module Publish Section''' + @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,variant,language_label): +def get_feature_finder(vehicle, variant, language_label): try: - data=frappe.db.sql(f"""select * from `tabFeature Finder` where vehicle='{vehicle}' and variant_id='{variant}' and language='{language_label}' and is_published=0""",as_dict=1) + data = frappe.db.sql( + f"""select * from `tabFeature Finder` where vehicle='{vehicle}' and variant_id='{variant}' and language='{language_label}' and is_published=0""", as_dict=1) return data except Exception as e: return str(e) @@ -558,9 +569,10 @@ def repair_checksheet_publish(vehicle, vehicle_id, 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}) + repair_checksheet['data'][0]) + + repair_checksheet_tmp = get_latest_data({'data': published_data['data']}, { + 'data': repair_checksheet_tmp}) else: for i in parent: @@ -573,7 +585,8 @@ def repair_checksheet_publish(vehicle, vehicle_id, 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':[]}) + repair_checksheet_tmp = get_latest_data( + {'data': repair_checksheet_tmp}, {'data': []}) if publish_repair_checksheet == 1: """ Save publish file """ @@ -589,10 +602,11 @@ 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,vehicle_id=None, - language=None,publish_type=None, - release_description=None,parent=None, - variant=None): + +def feature_finder_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, @@ -631,50 +645,49 @@ def feature_finder_publish(vehicle=None,vehicle_id=None, published_data = json.load(f) for i in parent: feature_finder = feature_finder_data(vehicle, language, - publish_type, i.parent1,i.variant) + publish_type, i.parent1, i.variant) if feature_finder['status'] == 1: publish_repair_checksheet = 1 feature_finder_tmp.append( - feature_finder['data'][0]) - - repair_checksheet_tmp=get_latest_data({'data':published_data['data']},{'data':feature_finder_tmp}) + feature_finder['data'][0]) + + repair_checksheet_tmp = get_latest_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) + vehicle, language, publish_type, i.parent1, i.variant) if feature_finder['status'] == 1: publish_feature_finder = 1 - + if len(feature_finder['data']): feature_finder_tmp.append( feature_finder['data'][0]) else: frappe.throw('failed to publish') - - feature_finder_tmp=get_latest_data({'data':feature_finder_tmp},{'data':[]}) - - + + feature_finder_tmp = get_latest_data( + {'data': feature_finder_tmp}, {'data': []}) + # 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)) logger.info( - f'Repair Checksheet Data Append Start::{vehicle}-{language}-{publish_type}') - + f'Repair Checksheet 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']: @@ -686,7 +699,7 @@ def get_latest_data(prev_data, latest_data): try: data_dic1 = get_key_value_data(prev_data) data_dic2 = get_key_value_data(latest_data) - + final_dic = data_dic1.copy() for d1 in data_dic1: @@ -698,9 +711,9 @@ def get_latest_data(prev_data, latest_data): final_dic.pop(d2) else: final_dic.update({d2: data_dic2[d2]}) - + final_list = list(final_dic.values()) - + return final_list except Exception as e: frappe.throw(str(e)) @@ -745,7 +758,7 @@ def repair_checksheet_data(vehicle=None, language=None, def feature_finder_data(vehicle=None, language=None, - publish_type=None, parent=None,variant=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, @@ -770,7 +783,7 @@ def feature_finder_data(vehicle=None, language=None, 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` @@ -819,35 +832,37 @@ def feature_finder_data(vehicle=None, language=None, logger.error('error in repair checksheet' + str(e)) return failure_reponse + @frappe.whitelist() def max_publish_new_module(doc): doc = frappe.get_doc("Publish", doc) - ver = frappe.db.sql("""select max(creation) from {0}.tabPublish where vehicle = "{1}" and language = "{2}";""".format( + ver = frappe.db.sql("""select max(version) from {0}.tabPublish where vehicle = "{1}" and language = "{2}" and publish_module!="Automotive System";""".format( current_db_name, doc.vehicle, doc.language)) if ver: return ver -# @frappe.whitelist() -# def cal_ver_new_module(vehicle, lang, publish_type, doc): -# current_db_name = frappe.conf.get("db_name") -# doc = frappe.get_doc("Publish", doc) -# ver = frappe.db.sql(f"""select max(creation) from `tabPublish` where vehicle = "{vehicle}" and language = "{lang}";""",as_dict=1) -# v = 0.0 -# if publish_type == 'Global': -# if ver[0][0] == None: -# v = 1.0 -# else: -# v = int(float(ver[0][0])) + 1.0 - -# elif publish_type == 'Internal': -# if ver[0][0] == None: -# v = 0.01 -# else: -# v = float(ver[0][0]) + 0.01 -# v = "{:.2f}".format(v) -# doc.version = v -# frappe.db.sql("""update {0}.`tabPublish` set version = "{1}" where name = "{2}";""".format( -# current_db_name, v, doc.name)) -# frappe.db.commit() -# return v \ No newline at end of file +@frappe.whitelist() +def cal_ver_new_module(vehicle, lang, publish_type, doc): + current_db_name = frappe.conf.get("db_name") + doc = frappe.get_doc("Publish", doc) + ver = frappe.db.sql("""select max(version) from `tabPublish` where vehicle = "{vehi}" and language = "{lang}" and publish_module!="Automotive System";""" + .format(vehi=vehicle, lang=lang)) + v = 0.0 + if publish_type == 'Global': + if ver[0][0] == None: + v = 1.0 + else: + v = int(float(ver[0][0])) + 1.0 + + elif publish_type == 'Internal': + if ver[0][0] == None: + v = 0.01 + else: + v = float(ver[0][0]) + 0.01 + v = "{:.2f}".format(v) + doc.version = v + frappe.db.sql("""update {0}.`tabPublish` set version = "{1}" where name = "{2}";""".format( + current_db_name, v, doc.name)) + frappe.db.commit() + return v From 023dbedd198b07fbea96162ec6eb31705c5a2420 Mon Sep 17 00:00:00 2001 From: venkataakhil Date: Fri, 18 Aug 2023 18:59:32 +0530 Subject: [PATCH 2/2] Publish v2 verion and global custom button fix --- smart_service/apis/master_api.py | 11 ++-- smart_service/apis/v2/master.py | 33 ++++++++++ .../doctype/feature_finder/feature_finder.js | 33 ++++++++-- .../feature_finder/feature_finder.json | 10 +++- .../doctype/feature_finder/feature_finder.py | 19 ++++-- .../module_publish_mapping.json | 4 +- .../transactions/doctype/publish/publish.js | 9 ++- .../transactions/doctype/publish/publish.py | 60 ++++++++++++++++--- 8 files changed, 152 insertions(+), 27 deletions(-) diff --git a/smart_service/apis/master_api.py b/smart_service/apis/master_api.py index 0d2b9fe..c1e8e60 100644 --- a/smart_service/apis/master_api.py +++ b/smart_service/apis/master_api.py @@ -360,12 +360,13 @@ def variant(LSD, language): case when active_status= 'Active' Then true else false end as active_status FROM `tabVariant Mapping` where modified >='{LSD}';''', as_dict=1) for d in data: - modules = frappe.db.sql(f''' select automotive_system as 'Automotive System',tsb as 'TSB',fsa as 'FSA',tekalert as 'TEKalert', + modules = frappe.db.sql(f'''select automotive_system as 'Automotive System',tsb as 'TSB',fsa as 'FSA',tekalert as 'TEKalert', feature_finder as 'Feature Finder',repairservice_check_sheet as 'Repair/Service Check Sheet', - mahindra_special_tool_information as 'Mahindra Special Tool Information',training_information as 'Training Information', - qwik_service as 'QWIK Service',pdi_inspection as 'PDI Inspection', + mahindra_special_tool_information as 'Mahindra Special Tool Information',training_information as + 'Training Information',qwik_service as 'QWIK Service',pdi_inspection as 'PDI Inspection', torque_information_nm as 'Torque Information NM' - FROM `tabModule Publish Mapping` where variant="{d['variant_name']}" ;''', as_dict=1) + FROM `tabModule Publish Mapping` where vehicle= '{d['vehicle']}' and variant="{d['variant_name']}" ;''', + as_dict=1) if modules: d['modules'] = [{'title': k, 'active_status': v, 'app_menu_id': frappe.db.sql(f'''select app_menu_id from `tabModule Master` where module_name = '{k}' ;''', as_dict=1)[0]['app_menu_id']} @@ -401,7 +402,7 @@ def app_modules(LSD): @frappe.whitelist(methods=["POST"], allow_guest=1) -def role_mapping(): +def role_mapping(): req = json.loads(frappe.request.data) try: lsdt = req['LSD'] diff --git a/smart_service/apis/v2/master.py b/smart_service/apis/v2/master.py index 365b6de..f573eaa 100644 --- a/smart_service/apis/v2/master.py +++ b/smart_service/apis/v2/master.py @@ -232,3 +232,36 @@ def get_special_tool_information(vehicle): return True, special_tool_details except Exception as e: return False, e + + +@frappe.whitelist(allow_guest=1) +def update_publish_mapping(vehicle, variant, language, module): + frappe.set_user('Administrator') + pub_data = frappe.db.get_list('Module Publish Mapping', filters={ + "vehicle": vehicle, + "variant": variant, + "language": language + }, fields=['name']) + + if pub_data: + doc = frappe.get_doc('Module Publish Mapping', pub_data[0]['name']) + else: + doc = frappe.get_doc({ + 'doctype': 'Module Publish Mapping', + "vehicle": vehicle, + "variant": variant, + "language": language + }) + if module == 'Automotive System': + doc.automotive_system = 1 + doc.tsb = 1 + doc.fsa = 1 + doc.tekalert = 1 + + elif module == 'Feature Finder': + doc.feature_finder = 1 + + elif module == 'Repair service': + doc.repairservice_check_sheet = 1 + doc.save() + return 1 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 3cdb9dc..0586867 100644 --- a/smart_service/phase_2/doctype/feature_finder/feature_finder.js +++ b/smart_service/phase_2/doctype/feature_finder/feature_finder.js @@ -15,6 +15,7 @@ frappe.ui.form.on('Feature Finder', { } set_display_order(frm) show_images(frm) + }, onload: function (frm) { if (!frm.doc.feature_finder_images){ @@ -192,16 +193,28 @@ function custom_tab_html(frm) { res.append(``) + + if(frm.doc.tab_ref){ + $('.nav').find('.nav-link').removeClass('active') + $('.nav').find('#'+frm.doc.tab_ref).addClass('active') + } + var specification = "" var feature_finder_images = "" var feature_finder_content = "" if (frm.doc.specification && frm.doc.feature_finder_images && frm.doc.feature_finder_content){ + specification = frm.doc.specification.filter(o => o.feature_type == "SOP") feature_finder_images = frm.doc.feature_finder_images.filter(o => o.feature_type == "SOP") feature_finder_content = frm.doc.feature_finder_content.filter(o => o.feature_type == "SOP") + if(frm.doc.tab_ref !='SOP'){ + specification = frm.doc.specification.filter(o => o.post_vin_cutoff_name == frm.doc.tab_ref) + feature_finder_images = frm.doc.feature_finder_images.filter(o => o.post_vin_cutoff_name == frm.doc.tab_ref) + feature_finder_content = frm.doc.feature_finder_content.filter(o => o.post_vin_cutoff_name == frm.doc.tab_ref) + } specification.sort((a, b) => a.display_order - b.display_order); feature_finder_images.sort((a, b) => a.display_order - b.display_order); feature_finder_content.sort((a, b) => a.display_order - b.display_order); @@ -213,11 +226,17 @@ function custom_tab_html(frm) { var content_dialog_value = "" var nav_spec = {} nav_spec.feature_type = "SOP" + if(frm.doc.tab_ref !='SOP'){ + nav_spec.feature_type = "Post Vin CutOff" + nav_spec.post_vin_cutoff_name = frm.doc.tab_ref + } nav_spec.active_status = "Active" all_tabs() $('.main').find('.nav-link').click(function (event) { if ($(this)[0].id == "SOP") { + frm.doc.tab_ref = "SOP" + cur_frm.refresh_fields("tab_ref") nav_spec.feature_type = "SOP" nav_spec.post_vin_cutoff_name = "" specification = frm.doc.specification.filter(o => o.feature_type == $(this)[0].id) @@ -231,6 +250,8 @@ function custom_tab_html(frm) { } else { nav_spec.feature_type = "Post Vin CutOff" + frm.doc.tab_ref = $(this)[0].id + cur_frm.refresh_fields("tab_ref") nav_spec.post_vin_cutoff_name = $(this)[0].id specification = frm.doc.specification.filter(o => o.post_vin_cutoff_name == $(this)[0].id) feature_finder_images = frm.doc.feature_finder_images.filter(o => o.post_vin_cutoff_name == $(this)[0].id) @@ -241,7 +262,7 @@ function custom_tab_html(frm) { feature_finder_content.sort((a, b) => a.display_order - b.display_order); } - + all_tabs() }) @@ -790,10 +811,12 @@ function custom_tab_html(frm) { method: "smart_service.phase_2.doctype.feature_finder.feature_finder.insert_spec_data", args: { doc_name: frm.doc.name, - values: values + values: values, + tab_ref:frm.doc.tab_ref }, callback: function (r) { if (r.message.status == "success") { + cur_frm.reload_doc() cur_frm.refresh() } @@ -858,7 +881,8 @@ function custom_tab_html(frm) { method: "smart_service.phase_2.doctype.feature_finder.feature_finder.insert_image_data", args: { doc_name: frm.doc.name, - values: values + values: values, + tab_ref:frm.doc.tab_ref }, callback: function (r) { if (r.message.status == "success") { @@ -927,7 +951,8 @@ function custom_tab_html(frm) { method: "smart_service.phase_2.doctype.feature_finder.feature_finder.insert_content_data", args: { doc_name: frm.doc.name, - values: values + values: values, + tab_ref:frm.doc.tab_ref }, callback: function (r) { if (r.message.status == "success") { diff --git a/smart_service/phase_2/doctype/feature_finder/feature_finder.json b/smart_service/phase_2/doctype/feature_finder/feature_finder.json index 71425cc..b4a10cc 100644 --- a/smart_service/phase_2/doctype/feature_finder/feature_finder.json +++ b/smart_service/phase_2/doctype/feature_finder/feature_finder.json @@ -28,7 +28,8 @@ "feature_finder_images", "feature_finder_content", "vehicle_id", - "variant_id" + "variant_id", + "tab_ref" ], "fields": [ { @@ -186,11 +187,16 @@ { "fieldname": "section_break_o8kze", "fieldtype": "Section Break" + }, + { + "fieldname": "tab_ref", + "fieldtype": "Data", + "label": "Tab Ref" } ], "index_web_pages_for_search": 1, "links": [], - "modified": "2023-08-16 18:15:43.233327", + "modified": "2023-08-18 16:26:34.470582", "modified_by": "Administrator", "module": "Phase-2", "name": "Feature Finder", diff --git a/smart_service/phase_2/doctype/feature_finder/feature_finder.py b/smart_service/phase_2/doctype/feature_finder/feature_finder.py index 42f9acb..e69f9cf 100644 --- a/smart_service/phase_2/doctype/feature_finder/feature_finder.py +++ b/smart_service/phase_2/doctype/feature_finder/feature_finder.py @@ -97,12 +97,15 @@ def get_list_data(name, val): @frappe.whitelist() -def insert_spec_data(doc_name, values): +def insert_spec_data(doc_name, values,tab_ref): try: val = json.loads(values) get_count = frappe.db.sql(f"""select name from `tabFeature Finder Specification` where parent='{doc_name}' and feature_type='{val.get('feature_type')}'""",as_dict=1) get_count = len(get_count)+1 - frappe.log_error("displayorder",str(get_count)) + result = frappe.get_doc("Feature Finder", doc_name) + result.tab_ref = tab_ref + result.save() + frappe.db.commit() if val.get('name') != None: doc = frappe.get_doc("Feature Finder Specification", val['name']) doc.specification = val.get('specification') @@ -139,11 +142,15 @@ def delete_spec_data(values): @frappe.whitelist() -def insert_image_data(doc_name, values): +def insert_image_data(doc_name, values,tab_ref): try: val = json.loads(values) get_count = frappe.db.sql(f"""select name from `tabFeature Finder Images` where parent='{doc_name}' and feature_type='{val.get('feature_type')}'""",as_dict=1) get_count = len(get_count)+1 + result = frappe.get_doc("Feature Finder", doc_name) + result.tab_ref = tab_ref + result.save() + frappe.db.commit() if val.get('name') != None: doc = frappe.get_doc("Feature Finder Images", val['name']) doc.image = val.get('image') @@ -180,11 +187,15 @@ def delete_image_data(values): @frappe.whitelist() -def insert_content_data(doc_name, values): +def insert_content_data(doc_name, values,tab_ref): try: val = json.loads(values) get_count = frappe.db.sql(f"""select name from `tabFeature Finder Content` where parent='{doc_name}' and feature_type='{val.get('feature_type')}'""",as_dict=1) get_count = len(get_count)+1 + result = frappe.get_doc("Feature Finder", doc_name) + result.tab_ref = tab_ref + result.save() + frappe.db.commit() if val.get('name') != None: doc = frappe.get_doc("Feature Finder Content", val['name']) doc.content = val.get('content') diff --git a/smart_service/phase_2/doctype/module_publish_mapping/module_publish_mapping.json b/smart_service/phase_2/doctype/module_publish_mapping/module_publish_mapping.json index b0debfe..74c8639 100644 --- a/smart_service/phase_2/doctype/module_publish_mapping/module_publish_mapping.json +++ b/smart_service/phase_2/doctype/module_publish_mapping/module_publish_mapping.json @@ -1,7 +1,7 @@ { "actions": [], "allow_rename": 1, - "autoname": "format:{variant}-{language}", + "autoname": "format:{vehicle}-{variant}-{language}", "creation": "2023-08-07 12:44:24.978007", "doctype": "DocType", "editable_grid": 1, @@ -107,7 +107,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2023-08-18 16:49:35.315359", + "modified": "2023-08-18 18:04:39.185507", "modified_by": "Administrator", "module": "Phase-2", "name": "Module Publish Mapping", diff --git a/smart_service/transactions/doctype/publish/publish.js b/smart_service/transactions/doctype/publish/publish.js index 9e8bee9..059d6b7 100644 --- a/smart_service/transactions/doctype/publish/publish.js +++ b/smart_service/transactions/doctype/publish/publish.js @@ -342,7 +342,7 @@ frappe.ui.form.on('Publish', { } - if (frm.doc.docstatus == 1 && frm.doc.publish_status == 'To Publish' && !frm.is_new() && frm.doc.publish_type != "Global" && frm.doc.publish_module != 'Automotive System') { + if (frm.doc.docstatus == 1 && frm.doc.publish_status == 'To Publish' && !frm.is_new() && frm.doc.publish_module != 'Automotive System') { debugger frappe.call({ method: "smart_service.transactions.doctype.publish.publish.cal_ver_new_module", @@ -357,6 +357,13 @@ frappe.ui.form.on('Publish', { if (r.message) { frm.set_value('version', r.message); cur_frm.refresh_field('version') + frm.page.clear_primary_action("Global Publish"); + // if(frm.doc.publish_type == 'Internal'){ + // debugger + // frm.page.clear_primary_action("Global Publish"); + + // } + frm.set_value('actual_published_date', frappe.datetime.nowdate()); } diff --git a/smart_service/transactions/doctype/publish/publish.py b/smart_service/transactions/doctype/publish/publish.py index 1f7f684..299bd20 100644 --- a/smart_service/transactions/doctype/publish/publish.py +++ b/smart_service/transactions/doctype/publish/publish.py @@ -80,6 +80,15 @@ 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)) + frappe.log_error(str(self.variant_mapping_details)) + variant = self.variant_mapping_details.split('/n') + frappe.log_error('variant', str(variant)) + + # for v in variant: + # frappe.log_error('v', str(v)) + # if v: + # update_publish_mapping( + # self.vehicle, v, self.language, self.publish_module) def onload1(self): current_db_name = frappe.conf.get("db_name") @@ -190,6 +199,37 @@ def update_procedure(vehicle, lang, publish_type, doc): # Generate Publish versions +def update_publish_mapping(vehicle, variant, language, module): + frappe.set_user('Administrator') + pub_data = frappe.db.get_list('Module Publish Mapping', filters={ + "vehicle": vehicle, + "variant": variant, + "language": language + }, fields=['name']) + + if pub_data: + doc = frappe.get_doc('Module Publish Mapping', pub_data[0]['name']) + else: + doc = frappe.get_doc({ + 'doctype': 'Module Publish Mapping', + "vehicle": vehicle, + "variant": variant, + "language": language + }) + if module == 'Automotive System': + doc.automotive_system = 1 + doc.tsb = 1 + doc.fsa = 1 + doc.tekalert = 1 + + elif module == 'Feature Finder': + doc.feature_finder = 1 + + elif module == 'Repair service': + doc.repairservice_check_sheet = 1 + doc.save() + + def update_publish_status(self): try: update_status = frappe.db.sql( @@ -287,7 +327,7 @@ def generate_global_publish(name): "vehicle": res.vehicle, "publish_type": "Global", "language": res.language, - "publish_status": "To Publish", + "publish_status": 'To Publish', "release_description": res.release_description, "publish_module": res.publish_module, "feature_finder_publish": res.feature_finder_publish, @@ -651,8 +691,9 @@ def feature_finder_publish(vehicle=None, vehicle_id=None, feature_finder_tmp.append( feature_finder['data'][0]) - repair_checksheet_tmp = get_latest_data( + feature_finder_tmp = get_latest_data( {'data': published_data['data']}, {'data': feature_finder_tmp}) + frappe.msgprint(str(feature_finder_tmp)) else: @@ -672,15 +713,16 @@ def feature_finder_publish(vehicle=None, vehicle_id=None, {'data': feature_finder_tmp}, {'data': []}) # if publish_feature_finder == 1: - """ Save publish file """ - vehicle_data['data'] = feature_finder_tmp + """ Save publish file """ + vehicle_data['data'] = feature_finder_tmp + frappe.msgprint(str(file_path)) - with open(file_path, 'w') as outfile: - outfile.write(json.dumps(vehicle_data, indent=4, default=str)) - logger.info( - f'Repair Checksheet Data Append Start::{vehicle}-{language}-{publish_type}') + with open(file_path, 'w') as outfile: + outfile.write(json.dumps(vehicle_data, indent=4, default=str)) + logger.info( + f'Repair Checksheet Data Append Start::{vehicle}-{language}-{publish_type}') - return 1, file_path + return 1, file_path except Exception as e: logger.info(