diff --git a/smart_service/apis/master_api.py b/smart_service/apis/master_api.py index 35011a0..53a3d4c 100644 --- a/smart_service/apis/master_api.py +++ b/smart_service/apis/master_api.py @@ -348,7 +348,8 @@ def variant(LSD, language): return {"status": 0, "error": " 'LSD' format error"} try: data = frappe.db.sql(f''' - select name,vehicle,vehicle_id,name as variant_name,variant,variant_id,fuel,fuel_id,transmission,transmission_id,drive,drive_id,family_code, + select name,vehicle,vehicle_id,name as variant_name,variant,variant_id,fuel,fuel_id,transmission,transmission_id, + drive,drive_id,family_code, 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: @@ -357,7 +358,7 @@ def variant(LSD, language): 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 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']} diff --git a/smart_service/masters/doctype/role_master/role_master.js b/smart_service/masters/doctype/role_master/role_master.js index ca14c49..7119d1a 100644 --- a/smart_service/masters/doctype/role_master/role_master.js +++ b/smart_service/masters/doctype/role_master/role_master.js @@ -1,86 +1,86 @@ // Copyright (c) 2023, Hard n Soft Technologies Pvt Ltd and contributors // For license information, please see license.txt var original_display_order = 0; -var role_name_count=0; -frappe.require('assets/smart_service/js/utils.js', () => {}) +var role_name_count = 0; +frappe.require('assets/smart_service/js/utils.js', () => { }) frappe.ui.form.on('Role Master', { - onload: function (frm) { + onload: function (frm) { // Set Display Order - if (frm.is_new()) { - frm.set_df_property('display_order', 'read_only', 1); - } else { - frm.set_df_property('display_order', 'read_only', 0); - } - frappe.db.count('Role Master') - .then(count => { - role_name_count = count + 1; - if (frm.is_new()) { - frm.set_value("display_order", role_name_count); - } else { - original_display_order = frm.doc.display_order; - } - }); + // if (frm.is_new()) { + // frm.set_df_property('display_order', 'read_only', 1); + // } else { + // frm.set_df_property('display_order', 'read_only', 0); + // } + // frappe.db.count('Role Master') + // .then(count => { + // role_name_count = count + 1; + // if (frm.is_new()) { + // frm.set_value("display_order", role_name_count); + // } else { + // original_display_order = frm.doc.display_order; + // } + // }); }, - refresh: function (frm) { + refresh: function (frm) { // Set Display Order - if (frm.is_new()) { - frm.set_df_property('display_order', 'read_only', 1); - } else { - frm.set_df_property('display_order', 'read_only', 0); - } - frappe.db.count('Role Master') - .then(count => { - role_name_count = count + 1; - if (frm.is_new()) { - frm.set_value("display_order", role_name_count); - } else { - original_display_order = frm.doc.display_order; - } - }); + // if (frm.is_new()) { + // frm.set_df_property('display_order', 'read_only', 1); + // } else { + // frm.set_df_property('display_order', 'read_only', 0); + // } + // frappe.db.count('Role Master') + // .then(count => { + // role_name_count = count + 1; + // if (frm.is_new()) { + // frm.set_value("display_order", role_name_count); + // } else { + // original_display_order = frm.doc.display_order; + // } + // }); - //for Module Master + //for Module Master // frappe.db.get_list('Module Master', { // fields: ['module_name', 'name'], // filters: { // } // }).then(records => { - frappe.call({ - method: "smart_service.masters.doctype.role_master.role_master.get_module_names", - args: { vehicle: frm.doc.vehicle, language_label: frm.doc.language_label, publish_type: frm.doc.publish_type }, - callback: function (r) { - if (r.message) { - let res = cur_frm.fields_dict.module_master_html.$wrapper.empty() - let module_html = "
" - module_html ="
" - r.message.map(val => { - if (!frm.is_new() &&frm.doc.modules &&frm.doc.modules.includes(val.module_name) ) { - module_html += "
" - module_html += "" - module_html += "
" - } else { - module_html += "
" - module_html += "" - module_html += "
" - } - }) - res.append(module_html) - } + frappe.call({ + method: "smart_service.masters.doctype.role_master.role_master.get_module_names", + args: { vehicle: frm.doc.vehicle, language_label: frm.doc.language_label, publish_type: frm.doc.publish_type }, + callback: function (r) { + if (r.message) { + let res = cur_frm.fields_dict.module_master_html.$wrapper.empty() + let module_html = "
" + module_html = "
" + r.message.map(val => { + if (!frm.is_new() && frm.doc.modules && frm.doc.modules.includes(val.module_name)) { + module_html += "
" + module_html += "" + module_html += "
" + } else { + module_html += "
" + module_html += "" + module_html += "
" + } + }) + res.append(module_html) } + } }) }, - after_save:function(frm){ + after_save: function (frm) { cur_frm.refresh_fields("display_order") - }, + }, - validate: function (frm) { + validate: function (frm) { //check html if has Module name value var val = "" $(':checkbox:checked').each(function (i) { let value = $(this).val(); - val += $(this).val() + "," + val += $(this).val() + "," }); val = val.substring(0, val.length - 1); frm.set_value('modules', val); @@ -89,8 +89,8 @@ frappe.ui.form.on('Role Master', { //For Display Order - cur_frm.refresh_fields("display_order") + // cur_frm.refresh_fields("display_order") // console.log(module_name_count,"----",original_display_order) - display_order_validation(frm, role_name_count, original_display_order,frm.doc.role) - } + // display_order_validation(frm, role_name_count, original_display_order,frm.doc.role) + } }); 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 69b8cad..3cdb9dc 100644 --- a/smart_service/phase_2/doctype/feature_finder/feature_finder.js +++ b/smart_service/phase_2/doctype/feature_finder/feature_finder.js @@ -471,7 +471,7 @@ function custom_tab_html(frm) { $('.specification_bl').find('table > tbody > tr').each(function (index, tr) { spec_id_dis.push(this.id); }); - // set_display_order_child("Feature Finder Specification", spec_id_dis) + set_display_order_child("Feature Finder Specification", spec_id_dis) }) }) 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 af7c30c..71425cc 100644 --- a/smart_service/phase_2/doctype/feature_finder/feature_finder.json +++ b/smart_service/phase_2/doctype/feature_finder/feature_finder.json @@ -190,7 +190,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2023-08-14 18:42:42.356900", + "modified": "2023-08-16 18:15:43.233327", "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 c074f37..42f9acb 100644 --- a/smart_service/phase_2/doctype/feature_finder/feature_finder.py +++ b/smart_service/phase_2/doctype/feature_finder/feature_finder.py @@ -43,6 +43,9 @@ class FeatureFinder(Document): if not check_exe: if self.language != "en": frappe.throw("First language will be english only") + + if not self.is_new() and self.is_published == 1: + self.is_published = 0 # if len(self.specification)>0: # specification = frappe.db.sql(f"""select * from `tabFeature Finder Specification` where parent = '{self.name}'""",as_dict=1) @@ -97,17 +100,22 @@ def get_list_data(name, val): def insert_spec_data(doc_name, values): try: val = json.loads(values) - if val.get('name') != None: + 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)) + if val.get('name') != None: doc = frappe.get_doc("Feature Finder Specification", val['name']) doc.specification = val.get('specification') doc.value = val.get('value') doc.active_status = val.get('active_status') doc.feature_type = val.get('feature_type') + doc.display_order = val.get('display_order') doc.save() frappe.db.commit() else: res = frappe.get_doc("Feature Finder", doc_name) + val['display_order'] = get_count res.append("specification", val) res.save() @@ -134,16 +142,20 @@ def delete_spec_data(values): def insert_image_data(doc_name, values): 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 if val.get('name') != None: doc = frappe.get_doc("Feature Finder Images", val['name']) doc.image = val.get('image') doc.active_status = val.get('active_status') doc.feature_type = val.get('feature_type') + doc.display_order = val.get('display_order') doc.save() frappe.db.commit() else: res = frappe.get_doc("Feature Finder", doc_name) + val['display_order'] = get_count res.append("feature_finder_images", val) res.save() frappe.db.commit() @@ -171,16 +183,20 @@ def delete_image_data(values): def insert_content_data(doc_name, values): 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 if val.get('name') != None: doc = frappe.get_doc("Feature Finder Content", val['name']) doc.content = val.get('content') doc.active_status = val.get('active_status') doc.feature_type = val.get('feature_type') + doc.display_order = val.get('display_order') doc.save() frappe.db.commit() else: res = frappe.get_doc("Feature Finder", doc_name) + val['display_order'] = get_count res.append("feature_finder_content", val) res.save() frappe.db.commit() diff --git a/smart_service/phase_2/doctype/publish_test/publish_test.py b/smart_service/phase_2/doctype/publish_test/publish_test.py index 6a90fa4..7a23e74 100644 --- a/smart_service/phase_2/doctype/publish_test/publish_test.py +++ b/smart_service/phase_2/doctype/publish_test/publish_test.py @@ -65,6 +65,9 @@ class PublishTest(Document): # for i in 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) + feature_finder_publish(self.vehicle, self.vehicle_id, + self.language, self.publish_type, + self.release_description,self.feature_finder_publish) update_published_docs(self) update_publish_status = frappe.db.sql( """update `tabPublish Test` set publish_status='Published' where name='{0}'""".format(self.name)) @@ -447,6 +450,48 @@ def update_procedure_value(name, file_path): "Publish", self.name, "published_by", str(name)) frappe.db.commit() +def update_published_docs(self): + try: + if self.repair_checksheet_publish: + try: + for d in self.repair_checksheet_publish: + + 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)) + if self.repair_checksheet_publish: + + try: + for d in self.feature_finder_publish: + + frappe.db.sql( + """UPDATE `tabRepair Service Mapping` set published=1 where name='{0}'""".format(d.parent1)) + frappe.db.commit() + except Exception as e: + frappe.throw(str(e)) + + except: + frappe.throw(str(e)) + + +def create_publish_folders(folder_url): + try: + + if not os.path.isdir(folder_url + "/" + "Global"): + os.makedirs(folder_url + "/" + "Global") + + if not os.path.isdir(folder_url + "/" + "Internal"): + os.makedirs(folder_url + "/" + "Internal") + return True + + except Exception as e: + frappe.throw(str(e)) + return False + + +'''New Module Publish Section''' @frappe.whitelist() def get_service_repair(vehicle, @@ -543,8 +588,6 @@ def feature_finder_publish(vehicle=None,vehicle_id=None, language=None,publish_type=None, release_description=None,parent=None): try: - frappe.msgprint(str('res')) - logger_file = f'{vehicle} - {language} - {publish_type} - {module_name}' logger = frappe.logger(logger_file, allow_site=True, file_count=100) @@ -578,36 +621,35 @@ def feature_finder_publish(vehicle=None,vehicle_id=None, f'Repair Checksheet Data Append Start::{vehicle}-{language}-{publish_type}') '''update existing global json file''' if os.path.isfile(file_path): - pass - # with open(file_path) as f: - # published_data = json.load(f) - # for i in parent: - # repair_checksheet = repair_checksheet_data(vehicle, language, - # publish_type, i.parent_name) - # if repair_checksheet['status'] == 1: - # publish_repair_checksheet = 1 - # repair_checksheet_tmp.append( - # repair_checksheet['data'][0]) + with open(file_path) as f: + published_data = json.load(f) + for i in parent: + feature_finder = feature_finder_data(vehicle, language, + publish_type, i.parent1) + 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':repair_checksheet_tmp}) + 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) - - if feature_finder['status'] == 1: publish_feature_finder = 1 if len(feature_finder['data']): feature_finder_tmp.append( feature_finder['data'][0]) - frappe.msgprint(str(feature_finder_tmp)) + else: + frappe.throw('failed to publish') 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 @@ -624,41 +666,6 @@ def feature_finder_publish(vehicle=None,vehicle_id=None, f'{vehicle} - {language} - {publish_type} - {module_name} error in json creation' + str(e)) frappe.throw('Failed To Publish') - -def update_published_docs(self): - try: - if self.repair_checksheet_publish: - try: - for d in self.repair_checksheet_publish: - - 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)) - - except: - frappe.throw(str(e)) - - -def create_publish_folders(folder_url): - try: - - if not os.path.isdir(folder_url + "/" + "Global"): - os.makedirs(folder_url + "/" + "Global") - - if not os.path.isdir(folder_url + "/" + "Internal"): - os.makedirs(folder_url + "/" + "Internal") - return True - - except Exception as e: - frappe.throw(str(e)) - return False - - -'''New Module Publish Section''' - - def get_key_value_data(data): module_dic = {} for d in data['data']: @@ -729,7 +736,6 @@ def repair_checksheet_data(vehicle=None, language=None, def feature_finder_data(vehicle=None, language=None, publish_type=None, parent=None): try: - frappe.msgprint(str(parent)) logger_file = f'{vehicle} - {language} - {publish_type} - {module_name} - fetch data' logger = frappe.logger(logger_file, allow_site=True, file_count=100) @@ -741,9 +747,10 @@ def feature_finder_data(vehicle=None, language=None, ff.features_names as feature_name,ff.feature_category,ff.display_order,ff.active_status, ffm.feature_pdf as pdf from `tabFeature Finder` ff left join `tabFeature Finder Master` ffm on ff.features_names = ffm.feature_name - where ff.vehicle = "{vehicle}" and ffm.vehicle = "{vehicle}" and ff.variant = "{variant}" - and ff.language = "{language}" and ffm.language = "{language} and ff.name="{parent}"; + where ff.vehicle = "THAR" and ffm.vehicle = "{vehicle}" + and ff.language = "{language}" and ffm.language = "{language}" and ff.name="{parent}"; """, as_dict=1) + logger.info(feature_finder_details) else: feature_finder_details = frappe.db.sql(f"""select ff.name,ff.vehicle,ff.vehicle_id,ff.variant,ff.variant_id,ff.language, ff.translated_feature_name as feature_name,ff.feature_category, @@ -751,21 +758,21 @@ 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` where parent = '{str(f['vehicle'])+ str('-')+ str(f['feature_name']) +str('-')+str(f['language'])}'; ''', as_dict=1) - sop_images = frappe.db.sql(f""" select image,idx as display_order,active_status from `tabFeature Finder Images` where - parent = '{f['name']}' and feature_type ='SOP';""", as_dict=1) + sop_images = frappe.db.sql(f""" select image,display_order,active_status from `tabFeature Finder Images` where + parent = '{f['name']}' and feature_type ='SOP' order by display_order desc;""", as_dict=1) - sop_content = frappe.db.sql(f"""select content,idx as display_order, active_status from `tabFeature Finder Content` - where parent = '{f['name']}' and feature_type ='SOP';""", as_dict=1) + sop_content = frappe.db.sql(f"""select content,display_order, active_status from `tabFeature Finder Content` + where parent = '{f['name']}' and feature_type ='SOP' order by display_order desc;""", as_dict=1) - sop_specification = frappe.db.sql(f"""select specification,value,idx as display_order,active_status from `tabFeature Finder Specification` - where parent = '{f['name']}' and feature_type ='SOP';""", as_dict=1) + sop_specification = frappe.db.sql(f"""select specification,value,display_order,active_status from `tabFeature Finder Specification` + where parent = '{f['name']}' and feature_type ='SOP' order by display_order desc;""", as_dict=1) f['sop'] = {'content': sop_content, 'images': sop_images, 'specificaton': sop_specification} @@ -773,21 +780,20 @@ def feature_finder_data(vehicle=None, language=None, from `tabPost Vin Cutoff ID` where parent = '{f['name']}';''', as_dict=1) for p in post_vin_data: - vin_content = frappe.db.sql(f"""select content,idx as display_order, active_status from `tabFeature Finder Content` - where parent = '{f['name']}' and post_vin_cutoff_name ='{p['post_vin_cutoff_name']}';""", as_dict=1) + vin_content = frappe.db.sql(f"""select content,display_order, active_status from `tabFeature Finder Content` + where parent = '{f['name']}' and post_vin_cutoff_name ='{p['post_vin_cutoff_name']}' order by display_order desc;""", as_dict=1) - vin_images = frappe.db.sql(f""" select image,idx as display_order,active_status from `tabFeature Finder Images` where - parent = '{f['name']}' and post_vin_cutoff_name ='{p['post_vin_cutoff_name']}';""", as_dict=1) + vin_images = frappe.db.sql(f""" select image,display_order,active_status from `tabFeature Finder Images` where + parent = '{f['name']}' and post_vin_cutoff_name ='{p['post_vin_cutoff_name']}' order by display_order desc;""", as_dict=1) - vin_specification = frappe.db.sql(f"""select specification,value,idx as display_order,active_status from `tabFeature Finder Specification` - where parent = '{f['name']}' and post_vin_cutoff_name ='{p['post_vin_cutoff_name']}';""", as_dict=1) + vin_specification = frappe.db.sql(f"""select specification,value,display_order,active_status from `tabFeature Finder Specification` + where parent = '{f['name']}' and post_vin_cutoff_name ='{p['post_vin_cutoff_name']}' order by display_order desc;""", as_dict=1) p['content'] = vin_content p['images'] = vin_images p['specificaton'] = vin_specification f['post_vin'] = post_vin_data - logger.info( f"end of fetching feature finder data {vehicle} - {language}") success_reponse['data'] = feature_finder_details diff --git a/smart_service/phase_2/doctype/repair_service_mapping/repair_service_mapping.json b/smart_service/phase_2/doctype/repair_service_mapping/repair_service_mapping.json index 8ec53fe..f53bd45 100644 --- a/smart_service/phase_2/doctype/repair_service_mapping/repair_service_mapping.json +++ b/smart_service/phase_2/doctype/repair_service_mapping/repair_service_mapping.json @@ -1,6 +1,4 @@ { - "_comments": "[]", - "_liked_by": "[\"Administrator\"]", "actions": [], "allow_rename": 1, "autoname": "format:{vehicle}-{check_list_name}-{language}", @@ -29,7 +27,8 @@ "default": "0", "fieldname": "published", "fieldtype": "Check", - "label": "Published" + "label": "Published", + "read_only": 1 }, { "fieldname": "section_break_ci53z", @@ -126,7 +125,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2023-08-10 12:22:29.663210", + "modified": "2023-08-17 11:14:15.960174", "modified_by": "Administrator", "module": "Phase-2", "name": "Repair Service Mapping", diff --git a/smart_service/phase_2/doctype/repair_service_mapping/repair_service_mapping.py b/smart_service/phase_2/doctype/repair_service_mapping/repair_service_mapping.py index a9d5fe6..1c8da59 100644 --- a/smart_service/phase_2/doctype/repair_service_mapping/repair_service_mapping.py +++ b/smart_service/phase_2/doctype/repair_service_mapping/repair_service_mapping.py @@ -21,8 +21,10 @@ class RepairServiceMapping(Document): if self.translated_check_list_name: self.translated_check_list_name=self.translated_check_list_name.strip() - try: + if not self.is_new() and self.published == 1: + self.published = 0 + try: if self.is_new(): if self.vehicle and self.language and self.check_list_name: check_exe = frappe.db.get_list("Repair Service Mapping", @@ -60,3 +62,4 @@ class RepairServiceMapping(Document): res.save() except Exception as e: raise e + diff --git a/smart_service/phase_2/doctype/repair_service_publish_data/repair_service_publish_data.json b/smart_service/phase_2/doctype/repair_service_publish_data/repair_service_publish_data.json index 497522d..b4291f2 100644 --- a/smart_service/phase_2/doctype/repair_service_publish_data/repair_service_publish_data.json +++ b/smart_service/phase_2/doctype/repair_service_publish_data/repair_service_publish_data.json @@ -20,56 +20,64 @@ "fieldname": "vehicle", "fieldtype": "Link", "label": "Vehicle", - "options": "Vehicle" + "options": "Vehicle", + "read_only": 1 }, { "fieldname": "parent_name", "fieldtype": "Link", "in_list_view": 1, "label": "Parent Name", - "options": "Repair Service Mapping" + "options": "Repair Service Mapping", + "read_only": 1 }, { "fieldname": "language", "fieldtype": "Link", "in_list_view": 1, "label": "Language", - "options": "Custom Languages" + "options": "Custom Languages", + "read_only": 1 }, { "fieldname": "check_list_name", "fieldtype": "Link", "in_list_view": 1, "label": "Check List Name", - "options": "Repair Service Master" + "options": "Repair Service Master", + "read_only": 1 }, { "fieldname": "active_status", "fieldtype": "Select", "in_list_view": 1, "label": "Active Status", - "options": "Active\nInactive" + "options": "Active\nInactive", + "read_only": 1 }, { "fieldname": "display_order", "fieldtype": "Int", - "label": "Display Order" + "label": "Display Order", + "read_only": 1 }, { "fieldname": "my_id", "fieldtype": "Int", - "label": "My Id" + "label": "My Id", + "read_only": 1 }, { "fieldname": "lang_myid", "fieldtype": "Int", - "label": "Lang MyId" + "label": "Lang MyId", + "read_only": 1 } ], "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2023-08-09 12:35:45.411733", + "modified": "2023-08-17 10:40:27.362070", "modified_by": "Administrator", "module": "Phase-2", "name": "Repair Service Publish Data", diff --git a/smart_service/phase_2/doctype/special_tool_information/special_tool_information.json b/smart_service/phase_2/doctype/special_tool_information/special_tool_information.json index bcd309c..d47287c 100644 --- a/smart_service/phase_2/doctype/special_tool_information/special_tool_information.json +++ b/smart_service/phase_2/doctype/special_tool_information/special_tool_information.json @@ -1,6 +1,4 @@ { - "_comments": "[]", - "_liked_by": "[]", "actions": [], "allow_rename": 1, "autoname": "format:{vehicle}-{category}-{sub_category}", @@ -69,7 +67,8 @@ "default": "0", "fieldname": "published", "fieldtype": "Check", - "label": "Published" + "label": "Published", + "read_only": 1 }, { "fieldname": "column_break_cyo0a", @@ -78,7 +77,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2023-08-10 16:12:57.846488", + "modified": "2023-08-17 12:30:22.392056", "modified_by": "Administrator", "module": "Phase-2", "name": "Special Tool Information", diff --git a/smart_service/phase_2/doctype/special_tool_information/special_tool_information.py b/smart_service/phase_2/doctype/special_tool_information/special_tool_information.py index 1aa7d2d..a6820a1 100644 --- a/smart_service/phase_2/doctype/special_tool_information/special_tool_information.py +++ b/smart_service/phase_2/doctype/special_tool_information/special_tool_information.py @@ -5,10 +5,13 @@ import frappe from frappe.model.document import Document class SpecialToolInformation(Document): - def autoname(self): + def validate(self): if self.is_new(): count = frappe.db.sql('''select max(my_id) as max_count from `tabSpecial Tool Information`;''') if count[0][0] is not None: self.my_id = count[0][0] + 1 else: self.my_id = 1 + + if not self.is_new() and self.published == 1: + self.published = 0 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 7e27572..877b746 100644 --- a/smart_service/phase_2/doctype/training_information/training_information.json +++ b/smart_service/phase_2/doctype/training_information/training_information.json @@ -87,7 +87,8 @@ "default": "0", "fieldname": "published", "fieldtype": "Check", - "label": "Published" + "label": "Published", + "read_only": 1 }, { "fieldname": "section_break_jqjts", @@ -96,7 +97,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2023-08-08 18:17:00.667481", + "modified": "2023-08-17 12:29:42.814356", "modified_by": "Administrator", "module": "Phase-2", "name": "Training Information", diff --git a/smart_service/phase_2/doctype/training_information/training_information.py b/smart_service/phase_2/doctype/training_information/training_information.py index cbd9ea7..8842404 100644 --- a/smart_service/phase_2/doctype/training_information/training_information.py +++ b/smart_service/phase_2/doctype/training_information/training_information.py @@ -15,3 +15,6 @@ class TrainingInformation(Document): self.my_id = count[0][0] + 1 else: self.my_id = 1 + + if not self.is_new() and self.published == 1: + self.published = 0 diff --git a/smart_service/transactions/doctype/publish/publish.js b/smart_service/transactions/doctype/publish/publish.js index 46267af..be6db49 100644 --- a/smart_service/transactions/doctype/publish/publish.js +++ b/smart_service/transactions/doctype/publish/publish.js @@ -1,6 +1,6 @@ // Copyright (c) 2021, Hard n Soft Technologies Pvt Ltd and contributors // For license information, please see license.txt -var selected_module=0 + cur_frm.fields_dict['variant_mapping'].get_query = function (doc, cdt, cdn) { return { @@ -10,25 +10,29 @@ cur_frm.fields_dict['variant_mapping'].get_query = function (doc, cdt, cdn) { } }; }; - +var selected_module = '' cur_frm.fields_dict['vehicle'].get_query = function (doc, cdt, cdn) { return { query: "smart_service.masters.doctype.vehicle.vehicle.vehicle_filter", }; }; let lang_set_first_time = true; frappe.ui.form.on('Publish', { - publish_module:function(frm){ - if(cur_frm.doc.publish_module=='Automotive'){ - selected_module=1 + onload: function (frm) { + // $('[data-route="Form/Publish/' + frm.doc.name + '"]').find('.primary-action').html("Internal Publish") + if (frm.doc.docstatus == 0 && !frm.is_new() && frm.doc.publish_type != "Global" && frm.doc.publish_module != 'Automotive System') { + $('[data-route="Form/Publish/' + frm.doc.name + '"]').find('.primary-action').html("Internal Publish") } - else{ - selected_module=0 - + if (frm.doc.docstatus == 0 && frm.doc.publish_type == "Global" && frm.doc.publish_module != 'Automotive System') { + $('[data-route="Form/Publish/' + frm.doc.name + '"]').find('.primary-action').html("Global Publish") } - }, - onload: function (frm) { + // if (frm.doc.status = "Published" && frm.doc.publish_module != 'Automotive System') { + // frm.set_df_property('repair_checksheet_publish', 'hidden', 0) + // frm.refresh_field('repair_checksheet_publish') + + + // } $(document).on('mouseover', function (events) { $("a:contains(Copy to Clipboard)").css({ 'pointer-events': 'none' }), $("a:contains(Duplicate)").css({ 'pointer-events': 'none' }); @@ -49,266 +53,330 @@ frappe.ui.form.on('Publish', { }, refresh: function (frm) { - cur_frm.set_df_property('system_mapping', "read_only", 1); - cur_frm.fields_dict['system_mapping'].grid.wrapper.find('.grid-add-row').hide(); - cur_frm.fields_dict['system_mapping'].grid.wrapper.find('.grid-upload').hide(); - cur_frm.fields_dict['system_mapping'].grid.wrapper.find('.grid-remove-rows').hide(); - cur_frm.fields_dict['system_mapping'].grid.wrapper.find('.grid-insert-row').hide(); - cur_frm.fields_dict['system_mapping'].grid.wrapper.find('.grid-append-row').hide(); - frm.fields_dict.system_mapping.grid.wrapper.find('.grid-append-row').hide(); + + if (frm.doc.docstatus == 0 && !frm.is_new() && frm.doc.publish_type != "Global") { + $('[data-route="Form/Publish/' + frm.doc.name + '"]').find('.primary-action').html("Internal Publish") + } + if (frm.doc.docstatus == 0 && frm.doc.publish_type == "Global") { + $('[data-route="Form/Publish/' + frm.doc.name + '"]').find('.primary-action').html("Global Publish") + } + 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(); + cur_frm.fields_dict['system_mapping'].grid.wrapper.find('.grid-upload').hide(); + cur_frm.fields_dict['system_mapping'].grid.wrapper.find('.grid-remove-rows').hide(); + cur_frm.fields_dict['system_mapping'].grid.wrapper.find('.grid-insert-row').hide(); + cur_frm.fields_dict['system_mapping'].grid.wrapper.find('.grid-append-row').hide(); + frm.fields_dict.system_mapping.grid.wrapper.find('.grid-append-row').hide(); + + cur_frm.fields_dict['variant_mapping_assets'].grid.wrapper.find('.grid-add-row').hide(); + cur_frm.fields_dict['variant_mapping_assets'].grid.wrapper.find('.grid-upload').hide(); + cur_frm.fields_dict['variant_mapping_assets'].grid.wrapper.find('.grid-remove-rows').hide(); + cur_frm.fields_dict['variant_mapping_assets'].grid.wrapper.find('.grid-insert-row').hide(); + cur_frm.fields_dict['variant_mapping_assets'].grid.wrapper.find('.grid-append-row').hide(); + frm.fields_dict.variant_mapping_assets.grid.wrapper.find('.grid-append-row').hide(); + + cur_frm.fields_dict['publish_documents'].grid.wrapper.find('.grid-add-row').hide(); + cur_frm.fields_dict['publish_documents'].grid.wrapper.find('.grid-upload').hide(); + cur_frm.fields_dict['publish_documents'].grid.wrapper.find('.grid-remove-all-rows').hide(); + cur_frm.fields_dict['publish_documents'].grid.wrapper.find('.grid-remove-rows').hide(); + cur_frm.fields_dict['publish_documents'].grid.wrapper.find('.grid-delete-row').hide(); + cur_frm.fields_dict['publish_documents'].grid.wrapper.find('.grid-delete_all_rows').hide(); + cur_frm.fields_dict['publish_documents'].grid.wrapper.find('.grid-move-row').hide(); + cur_frm.fields_dict['publish_documents'].grid.wrapper.find('.grid-append-row').hide(); + frm.fields_dict.publish_documents.grid.wrapper.find('.grid-append-row').hide(); + + document.querySelectorAll("[data-fieldname='km_report']")[1].style.backgroundColor = "#e31a37"; + document.querySelectorAll("[data-fieldname='km_report']")[1].style.color = "#FFFFFF"; + document.querySelectorAll("[data-fieldname='add_variant_mapping_to_publish']")[1].style.backgroundColor = "#e31a37"; + document.querySelectorAll("[data-fieldname='add_variant_mapping_to_publish']")[1].style.color = "#FFFFFF"; + if (frm.doc.docstatus === 1 && frm.doc.publish_type == "Internal" && frm.doc.publish_status == 'Published' && !frm.doc.global_publish && frappe.user.has_role('_Publisher')) { + frappe.call({ + method: "smart_service.transactions.doctype.publish.publish.max_publish", + args: { + "doc": frm.doc.name, + }, + callback: function (r) { + if (r.message) { + if (r.message == frm.doc.version) { + frm.add_custom_button(__('Global Publish'), function () { + frappe.call({ + method: "smart_service.transactions.doctype.publish.publish.global_publish", + args: { + "doc": frm.doc.name, + }, + callback: function (r) { + cur_frm.reload_doc(); + } + }); + }).addClass("btn-warning").css({ 'background-color': '#f5b0cd', 'color': 'black' }); + } + } + } + }) + } + + + if (frm.doc.docstatus === 1 && frm.doc.publish_status == 'To Publish' && frappe.user.has_role('_Publisher') && frm.doc.publish_module == 'Automotive System') { + + frm.add_custom_button(__('Publish'), function () { + frappe.confirm('Are you sure you want to Publish?', + () => { + // action to perform if Yes is selected + if (frm.doc.vehicle && frm.doc.language && frm.doc.publish_type && frm.doc.publish_module == 'Automotive System') { + debugger + frappe.call({ + method: 'smart_service.transactions.doctype.publish.publish.cal_ver', + args: { + vehicle: frm.doc.vehicle, + lang: frm.doc.language, + publish_type: frm.doc.publish_type, + doc: frm.doc.name + }, + callback: (r) => { + debugger + frm.set_value('version', r.message); + cur_frm.refresh_field('version') + if (frm.doc.docstatus === 1 && frm.doc.publish_status == 'To Publish') { + frappe.call({ + // method: "smart_service.apis.publish_api.api_procedure", + method: "smart_service.apis.publish_api.new_publish", + args: { + "args": frm.doc.name, + "publish_type": frm.doc.publish_type, + "vehicle": frm.doc.vehicle, + "language": frm.doc.language, + "version": frm.doc.version + }, + callback: function (r) { + // if (r.message[0]) { + frm.set_value('publish_status', 'Published'); + frm.page.clear_primary_action("Publish"); + frm.set_value('actual_published_date', frappe.datetime.nowdate()); + frappe.call({ + method: "smart_service.transactions.doctype.publish.publish.update_procedure_value", + args: { + "name": frm.doc.name, + "file_path": r.message[1], + }, + callback: (r) => { + // frm.save('Update'); + } + }) + frappe.msgprint({ + title: __('Notification'), + message: __('Successfully Published: ' + r.message[1]), + primary_action: { + action(values) { + frm.save('Update'); + } + } + }); + // } + // else { + // frappe.msgprint({ + // title: __('Notification'), + // message: __('Not Successfully Published: ' + r.message[1]), + // // primary_action: { + // // action(values) { + // // frm.save('Update'); + // // } + // // } + // }); + // } + + + // if (r.message != "Failed to save file") { + // frm.set_value('publish_status', 'Published'); + // frm.set_value('actual_published_date', frappe.datetime.nowdate()); + // frappe.call({ + // method: "smart_service.transactions.doctype.publish.publish.update_procedure_value", + // args: { + // "name": frm.doc.name, + // "file_path": r.message, + // }, + // callback: (r) => { + // // frm.save('Update'); + // } + // }) + // frappe.msgprint({ + // title: __('Notification'), + // message: __('Successfully Published: ' + r.message), + // primary_action: { + // action(values) { + // frm.save('Update'); + // } + // } + // }); + // } else { + // frappe.msgprint('Publish Failed') + // } + } + }); + } + }, + }) + } + }, () => { + // action to perform if No is selected + }); + }).addClass("btn-warning").css({ 'background-color': '#f5b0cd', 'color': 'black' }); + } else if (frm.doc.publish_status == 'Published') { + frm.set_read_only(); + frm.set_df_property('add_variant_mapping_to_publish', 'hidden', 1); + } + + + + if (frm.doc.docstatus === 0 && frm.doc.publish_status == 'To Publish') { + frm.get_field('system_mapping').grid.add_custom_button(__('Add to Publish'), function () { + let added = 0; + let topublish = []; + if (frm.doc.publish_type == 'Global') { topublish = ['Publish Ready']; } else { topublish = ['Review Pending', 'Publish Ready', 'Approval Pending']; } + frm.doc.system_mapping.forEach(row => { + if (topublish.indexOf(row.procedure_status) > -1) { + let dulicate = false; + if (frm.doc.publish_documents) { + frm.doc.publish_documents.forEach(publishrow => { + if (frm.doc.variant_mapping == publishrow.variant_mapping && + row.systems == publishrow.system && + row.sub_systems == publishrow.sub_system && row.procedure == publishrow.procedure_link) { + dulicate = true; + } + }); + } + if (dulicate === false) { + let child = cur_frm.add_child("publish_documents"); + child.variant_mapping = frm.doc.variant_mapping; + child.system = row.systems; + child.sub_system = row.sub_systems; + child.procedure_link = row.procedure; + child.procedure_status = row.procedure_status; + child.update_procedure_status = row.procedure_status; + child.item_category = "System Mapping"; + child.variant = frm.doc.variant; + refresh_field("publish_documents"); + added += 1; + } + } + }); + + if (added) { frappe.msgprint(__(added + " Doc(s) Added")); } + else { frappe.msgprint(__("No Doc Added")); } + }); + frm.fields_dict.system_mapping.grid.grid_buttons.find('.btn-custom').removeClass('btn-default').addClass('btn-primary'); - cur_frm.fields_dict['variant_mapping_assets'].grid.wrapper.find('.grid-add-row').hide(); - cur_frm.fields_dict['variant_mapping_assets'].grid.wrapper.find('.grid-upload').hide(); - cur_frm.fields_dict['variant_mapping_assets'].grid.wrapper.find('.grid-remove-rows').hide(); - cur_frm.fields_dict['variant_mapping_assets'].grid.wrapper.find('.grid-insert-row').hide(); - cur_frm.fields_dict['variant_mapping_assets'].grid.wrapper.find('.grid-append-row').hide(); - frm.fields_dict.variant_mapping_assets.grid.wrapper.find('.grid-append-row').hide(); - - cur_frm.fields_dict['publish_documents'].grid.wrapper.find('.grid-add-row').hide(); - cur_frm.fields_dict['publish_documents'].grid.wrapper.find('.grid-upload').hide(); - cur_frm.fields_dict['publish_documents'].grid.wrapper.find('.grid-remove-all-rows').hide(); - cur_frm.fields_dict['publish_documents'].grid.wrapper.find('.grid-remove-rows').hide(); - cur_frm.fields_dict['publish_documents'].grid.wrapper.find('.grid-delete-row').hide(); - cur_frm.fields_dict['publish_documents'].grid.wrapper.find('.grid-delete_all_rows').hide(); - cur_frm.fields_dict['publish_documents'].grid.wrapper.find('.grid-move-row').hide(); - cur_frm.fields_dict['publish_documents'].grid.wrapper.find('.grid-append-row').hide(); - frm.fields_dict.publish_documents.grid.wrapper.find('.grid-append-row').hide(); - - document.querySelectorAll("[data-fieldname='km_report']")[1].style.backgroundColor = "#e31a37"; - document.querySelectorAll("[data-fieldname='km_report']")[1].style.color = "#FFFFFF"; - document.querySelectorAll("[data-fieldname='add_variant_mapping_to_publish']")[1].style.backgroundColor = "#e31a37"; - document.querySelectorAll("[data-fieldname='add_variant_mapping_to_publish']")[1].style.color = "#FFFFFF"; - if (frm.doc.docstatus === 1 && frm.doc.publish_type == "Internal" && frm.doc.publish_status == 'Published' && !frm.doc.global_publish && frappe.user.has_role('_Publisher')) { + } + if (frm.doc.docstatus === 0 && frm.doc.publish_status == 'To Publish') { + frm.get_field('variant_mapping_assets').grid.add_custom_button(__('Add to Publish'), function () { + let added = 0; + frm.doc.variant_mapping_assets.forEach(row => { + if (row.active_status == "Active" || row.active_status == "Inactive") { + let dulicate = false; + if (frm.doc.publish_documents) { + frm.doc.publish_documents.forEach(publishrow => { + if (frm.doc.variant_mapping == publishrow.variant_mapping && + row.category == publishrow.asset_category && row.attach_file == publishrow.attach_file) { + dulicate = true; + } + }); + } + if (dulicate === false) { + let child = cur_frm.add_child("publish_documents"); + child.variant_mapping = frm.doc.variant_mapping; + child.asset_category = row.category; + child.item_category = "Variant Mapping Assets"; + child.variant = frm.doc.variant; + child.attach_file = row.attach_file; + refresh_field("publish_documents"); + added += 1; + } + } + }); + if (added) { frappe.msgprint(__(added + " Doc(s) Added")); } + else { frappe.msgprint(__("No Doc Added")); } + }); + + frm.fields_dict.variant_mapping_assets.grid.grid_buttons.find('.btn-custom').removeClass('btn-default').addClass('btn-primary'); + } + if (frm.doc.docstatus == 1) { + $(".grid-buttons").hide(); + + } + + } + + if (frm.doc.docstatus == 1 && !frm.is_new() && frm.doc.publish_type != "Global" && frm.doc.publish_module != 'Automotive System') { frappe.call({ - method: "smart_service.transactions.doctype.publish.publish.max_publish", + method: "smart_service.transactions.doctype.publish.publish.max_publish_new_module", args: { "doc": frm.doc.name, }, callback: function (r) { + debugger if (r.message) { - if (r.message == frm.doc.version) { + debugger + if (r.message) { frm.add_custom_button(__('Global Publish'), function () { frappe.call({ - method: "smart_service.transactions.doctype.publish.publish.global_publish", + method: "smart_service.transactions.doctype.publish.publish.generate_global_publish", args: { - "doc": frm.doc.name, + name: frm.doc.name }, callback: function (r) { - cur_frm.reload_doc(); + + if (r.message.status == "success") { + + window.location.href = r.message.url + "/app/publish" + "/" + r.message.message + } } - }); - }).addClass("btn-warning").css({ 'background-color': '#f5b0cd', 'color': 'black' }); + }) + }).addClass("btn-primary"); } } } }) + } - if (frm.doc.docstatus === 1 && frm.doc.publish_status == 'To Publish' && frappe.user.has_role('_Publisher')) { - frm.add_custom_button(__('Publish'), function () { - frappe.confirm('Are you sure you want to Publish?', - () => { - // action to perform if Yes is selected - if (frm.doc.vehicle && frm.doc.language && frm.doc.publish_type) { - frappe.call({ - method: 'smart_service.transactions.doctype.publish.publish.cal_ver', - args: { - vehicle: frm.doc.vehicle, - lang: frm.doc.language, - publish_type: frm.doc.publish_type, - doc: frm.doc.name - }, - callback: (r) => { - frm.set_value('version', r.message); - cur_frm.refresh_field('version') - if (frm.doc.docstatus === 1 && frm.doc.publish_status == 'To Publish') { - frappe.call({ - // method: "smart_service.apis.publish_api.api_procedure", - method: "smart_service.apis.publish_api.new_publish", - args: { - "args": frm.doc.name, - "publish_type": frm.doc.publish_type, - "vehicle": frm.doc.vehicle, - "language": frm.doc.language, - "version": frm.doc.version - }, - callback: function (r) { - // if (r.message[0]) { - frm.set_value('publish_status', 'Published'); - frm.page.clear_primary_action("Publish"); - frm.set_value('actual_published_date', frappe.datetime.nowdate()); - frappe.call({ - method: "smart_service.transactions.doctype.publish.publish.update_procedure_value", - args: { - "name": frm.doc.name, - "file_path": r.message[1], - }, - callback: (r) => { - // frm.save('Update'); - } - }) - frappe.msgprint({ - title: __('Notification'), - message: __('Successfully Published: ' + r.message[1]), - primary_action: { - action(values) { - frm.save('Update'); - } - } - }); - // } - // else { - // frappe.msgprint({ - // title: __('Notification'), - // message: __('Not Successfully Published: ' + r.message[1]), - // // primary_action: { - // // action(values) { - // // frm.save('Update'); - // // } - // // } - // }); - // } - - - // if (r.message != "Failed to save file") { - // frm.set_value('publish_status', 'Published'); - // frm.set_value('actual_published_date', frappe.datetime.nowdate()); - // frappe.call({ - // method: "smart_service.transactions.doctype.publish.publish.update_procedure_value", - // args: { - // "name": frm.doc.name, - // "file_path": r.message, - // }, - // callback: (r) => { - // // frm.save('Update'); - // } - // }) - // frappe.msgprint({ - // title: __('Notification'), - // message: __('Successfully Published: ' + r.message), - // primary_action: { - // action(values) { - // frm.save('Update'); - // } - // } - // }); - // } else { - // frappe.msgprint('Publish Failed') - // } - } - }); - } - }, - }) - } - }, () => { - // action to perform if No is selected - }); - }).addClass("btn-warning").css({ 'background-color': '#f5b0cd', 'color': 'black' }); - } else if (frm.doc.publish_status == 'Published') { - frm.set_read_only(); - frm.set_df_property('add_variant_mapping_to_publish', 'hidden', 1); - } - - if (frm.doc.docstatus === 0 && frm.doc.publish_status == 'To Publish') { - frm.get_field('system_mapping').grid.add_custom_button(__('Add to Publish'), function () { - let added = 0; - let topublish = []; - if (frm.doc.publish_type == 'Global') { topublish = ['Publish Ready']; } else { topublish = ['Review Pending', 'Publish Ready', 'Approval Pending']; } - frm.doc.system_mapping.forEach(row => { - if (topublish.indexOf(row.procedure_status) > -1) { - let dulicate = false; - if (frm.doc.publish_documents) { - frm.doc.publish_documents.forEach(publishrow => { - if (frm.doc.variant_mapping == publishrow.variant_mapping && - row.systems == publishrow.system && - row.sub_systems == publishrow.sub_system && row.procedure == publishrow.procedure_link) { - dulicate = true; - } - }); - } - if (dulicate === false) { - let child = cur_frm.add_child("publish_documents"); - child.variant_mapping = frm.doc.variant_mapping; - child.system = row.systems; - child.sub_system = row.sub_systems; - child.procedure_link = row.procedure; - child.procedure_status = row.procedure_status; - child.update_procedure_status = row.procedure_status; - child.item_category = "System Mapping"; - child.variant = frm.doc.variant; - refresh_field("publish_documents"); - added += 1; - } - } - }); - - if (added) { frappe.msgprint(__(added + " Doc(s) Added")); } - else { frappe.msgprint(__("No Doc Added")); } - }); - frm.fields_dict.system_mapping.grid.grid_buttons.find('.btn-custom').removeClass('btn-default').addClass('btn-primary'); + }, + validate: function (frm) { + if (frm.doc.publish_module == 'Automotive System') { + let regex = /[!@#$%^*_+\=\[\]{};'`~\\|.<>\?]+/; + if (regex.test(frm.doc.release_description) === true) { + frm.doc.release_description = ''; + frm.refresh_fields(); + frappe.msgprint(__("Publish Description: Only letters, numbers and / - () & , ' : are allowed.")); + } - } - if (frm.doc.docstatus === 0 && frm.doc.publish_status == 'To Publish') { - frm.get_field('variant_mapping_assets').grid.add_custom_button(__('Add to Publish'), function () { - let added = 0; - frm.doc.variant_mapping_assets.forEach(row => { - if (row.active_status == "Active" || row.active_status == "Inactive") { - let dulicate = false; - if (frm.doc.publish_documents) { - frm.doc.publish_documents.forEach(publishrow => { - if (frm.doc.variant_mapping == publishrow.variant_mapping && - row.category == publishrow.asset_category && row.attach_file == publishrow.attach_file) { - dulicate = true; - } - }); - } - if (dulicate === false) { - let child = cur_frm.add_child("publish_documents"); - child.variant_mapping = frm.doc.variant_mapping; - child.asset_category = row.category; - child.item_category = "Variant Mapping Assets"; - child.variant = frm.doc.variant; - child.attach_file = row.attach_file; - refresh_field("publish_documents"); - added += 1; - } - } - }); - if (added) { frappe.msgprint(__(added + " Doc(s) Added")); } - else { frappe.msgprint(__("No Doc Added")); } - }); + if (frm.doc.vehicle && frm.doc.release_description && frm.fields_dict.publish_documents.grid.grid_rows.length === 0) { + frappe.msgprint(__("No item selected to Publish")); + frappe.validated = false; + } + if (frm.doc.planned_publish_date < frappe.datetime.get_today()) { + frappe.msgprint(__("Planned Publish Date: You can not select past date")); + frappe.validated = false; + } - frm.fields_dict.variant_mapping_assets.grid.grid_buttons.find('.btn-custom').removeClass('btn-default').addClass('btn-primary'); } - if (frm.doc.docstatus == 1) { - $(".grid-buttons").hide(); + //check for atleast one data to publish + if (frm.doc.publish_module != 'Automotive System' && !frm.doc.hasOwnProperty('repair_checksheet_publish') && !frm.doc.hasOwnProperty('feature_finder_publish')) { + frappe.throw('No Data Found To Publish') - } - }, - validate: function (frm) { - let regex = /[!@#$%^*_+\=\[\]{};'`~\\|.<>\?]+/; - if (regex.test(frm.doc.release_description) === true) { - frm.doc.release_description = ''; - frm.refresh_fields(); - frappe.msgprint(__("Publish Description: Only letters, numbers and / - () & , ' : are allowed.")); - } - if (frm.doc.vehicle && frm.doc.release_description && frm.fields_dict.publish_documents.grid.grid_rows.length === 0) { - frappe.msgprint(__("No item selected to Publish")); - frappe.validated = false; - } - if (frm.doc.planned_publish_date < frappe.datetime.get_today()) { - frappe.msgprint(__("Planned Publish Date: You can not select past date")); - frappe.validated = false; } + }, 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'); }) + if(frm.doc.publish_module=='Feature Finder'){ + add_feature_finder(frm) + + } let km_name = frm.doc.variant_mapping + "-" + frm.doc.language + "-KM"; frappe.db.get_value('Kilometer Mapping', { name: km_name }, 'workflow_state', (r) => { @@ -342,7 +410,7 @@ frappe.ui.form.on('Publish', { }, km_active_status: function (frm) { - if (frm.doc.variant_mapping) { + if (frm.doc.variant_mapping && frm.doc.publish_module == 'Automotive System') { frappe.show_alert({ message: __('Please wait until variant mapping details are loaded.'), indicator: 'yellow' @@ -350,7 +418,7 @@ frappe.ui.form.on('Publish', { } if (frm.doc.km_active_status === "" || frm.doc.km_active_status === null) { return; } let filter = frm.doc.variant_mapping + "-" + frm.doc.language + "-SM"; - if (frm.doc.variant_mapping_status == "Active" && frm.doc.km_active_status == "Active") { + if (frm.doc.variant_mapping_status == "Active" && frm.doc.km_active_status == "Active" && frm.doc.publish_module == 'Automotive System') { frappe.call({ "method": "smart_service.transactions.doctype.publish.publish.get_system", "args": { @@ -423,7 +491,7 @@ frappe.ui.form.on('Publish', { }) } else { - if (frm.doc.variant_mapping_status) { + if (frm.doc.variant_mapping_status && frm.doc.publish_module == 'Automotive System') { frappe.msgprint({ title: __('Notification'), indicator: 'red', @@ -434,7 +502,7 @@ frappe.ui.form.on('Publish', { }, add_variant_mapping_to_publish: function (frm) { let dulicate = false; - if (frm.doc.publish_documents) { + if (frm.doc.publish_documents && frm.doc.publish_module == 'Automotive System') { frm.doc.publish_documents.forEach(publishrow => { if (frm.doc.variant_mapping == publishrow.variant_mapping && publishrow.systems === undefined && publishrow.sub_systems === undefined && publishrow.procedure === undefined) { dulicate = true; @@ -442,7 +510,7 @@ frappe.ui.form.on('Publish', { }); frappe.msgprint("Variant Mapping already added"); } - if (dulicate === false) { + if (dulicate === false && frm.doc.publish_module == 'Automotive System') { let child = cur_frm.add_child("publish_documents"); child.variant_mapping = frm.doc.variant_mapping; child.item_category = "Variant Mapping"; @@ -453,8 +521,15 @@ frappe.ui.form.on('Publish', { km_report: function (frm, cdt, cdn) { 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) + frm.refresh_field('repair_checksheet_publish') + + }, vehicle: function (frm) { + if (frm.doc.publish_module=='Automotive System') { + frappe.call({ method: "smart_service.transactions.doctype.publish.publish.old_publish", async: false, @@ -473,15 +548,56 @@ frappe.ui.form.on('Publish', { } } }); + } + if (frm.doc.publish_module=='Repair service') { - if (frm.doc.vehicle === undefined || frm.doc.vehicle === null) { return; } + add_to_publish(frm) + } + if (frm.doc.vehicle === undefined || frm.doc.vehicle === null && frm.doc.publish_module == 'Automotive System') { return; } $("[data-fieldname=variant_mapping]").focus(); if (frm.doc.vehicle) { frm.set_df_property('vehicle', 'read_only', 1); } + //other modules-Repair Checksheet + if (frm.doc.publish_module == 'Repair service') { + if (frm.doc.repair_checksheet_publish && frm.doc.repair_checksheet_publish.length > 0) { + content_flag = 1 + cur_frm.clear_table("repair_checksheet_publish"); + cur_frm.refresh_fields('repair_checksheet_publish'); + + } + + + + } + }, language: function (frm) { - if (!lang_set_first_time) { + if (frm.doc.publish_module == 'Repair service') { + + if (frm.doc.repair_checksheet_publish && frm.doc.repair_checksheet_publish.length > 0) { + + cur_frm.clear_table("repair_checksheet_publish"); + cur_frm.refresh_fields('repair_checksheet_publish'); + + } + + add_to_publish(frm) + } + + if (frm.doc.publish_module == 'Feature Finder') { + + if (frm.doc.feature_finder_publish && frm.doc.feature_finder_publish.length > 0) { + + cur_frm.clear_table("feature_finder_publish"); + cur_frm.refresh_fields('feature_finder_publish'); + + } + + add_feature_finder(frm) + } + + if (!lang_set_first_time && frm.doc.publish_module=='Automotive System') { frappe.confirm('This will clear all the data, are you sure you want to proceed?', () => { // action to perform if Yes is selected @@ -494,10 +610,36 @@ frappe.ui.form.on('Publish', { }, () => { // action to perform if No is selected }); - } else { lang_set_first_time = false; } + + } + if (!lang_set_first_time && frm.doc.publish_module=='Repair service') { + 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('feature_finder_publish', null); + lang_set_first_time = false; + }, () => { + // action to perform if No is selected + }); + + + } + if (!lang_set_first_time && frm.doc.publish_module=='Feature Finder') { + 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('feature_finder_publish', null); + frm.set_value('variant_mapping','') + lang_set_first_time = false; + }, () => { + // action to perform if No is selected + }); + + } + else { lang_set_first_time = false; } }, auto_version_update: function (frm) { - if (frm.doc.vehicle && frm.doc.language && frm.doc.publish_type) { + if (frm.doc.vehicle && frm.doc.language && frm.doc.publish_type && frm.doc.publish_module=='Automotive System') { frappe.call({ method: 'smart_service.transactions.doctype.publish.publish.cal_ver', args: { @@ -515,7 +657,11 @@ frappe.ui.form.on('Publish', { } }); } - }, + else{ + + + } + } }); frappe.ui.form.on('Publish_Temp Doc', { @@ -528,3 +674,66 @@ frappe.ui.form.on('Publish_Temp Doc', { frm.fields_dict.system_mapping.grid.wrapper.find('.grid-insert-row').hide(); }, }) + +function add_to_publish(frm) { + if(frm.doc.vehicle){ + frappe.call({ + method: "smart_service.transactions.doctype.publish.publish.get_service_repair", + args: { vehicle: frm.doc.vehicle, language_label: frm.doc.language, publish_type: frm.doc.publish_type }, + callback: function (r) { + debugger + if (r.message.length>0) { + + var records = r.message + records.map(v => { + var childTable = cur_frm.add_child("repair_checksheet_publish"); + childTable.parent_name = v['name']; + childTable.vehicle = v['vehicle']; + childTable.language = v['language']; + childTable.lang_myid = v['lang_myid']; + childTable.display_order = v['display_order']; + childTable.check_list_name = v['check_list_name']; + + childTable.active_status = v['active_status']; + childTable.my_id = v['my_id']; + childTable.lang_myid = v['lang_myid']; + }) + cur_frm.set_df_property('repair_checksheet_publish', 'hidden', 0) + cur_frm.refresh_field("repair_checksheet_publish"); + } + } + }) + + + } + +} +function add_feature_finder(frm){ + debugger + 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 }, + callback: function (r) { + debugger + if (r.message.length>0) { + cur_frm.set_df_property('feature_finder_publish', 'hidden', 0) + var records = r.message + records.map(v => { + var childTable = cur_frm.add_child("feature_finder_publish"); + childTable.parent1 = v['name']; + childTable.vehicle = v['vehicle']; + childTable.language = v['language']; + childTable.variant = v['variant']; + childTable.active_status = v['active_status']; + + }) + + cur_frm.refresh_field("feature_finder_publish"); + } + } + }) + + + + +} \ No newline at end of file diff --git a/smart_service/transactions/doctype/publish/publish.json b/smart_service/transactions/doctype/publish/publish.json index 66f80d6..528903a 100644 --- a/smart_service/transactions/doctype/publish/publish.json +++ b/smart_service/transactions/doctype/publish/publish.json @@ -14,6 +14,7 @@ "file_path", "column_break_3", "release_description", + "publish_module", "version", "published_by", "global_publish", @@ -42,7 +43,9 @@ "variant_mapping_assets", "section_break_5", "publish_documents", - "amended_from" + "amended_from", + "feature_finder_publish", + "repair_checksheet_publish" ], "fields": [ { @@ -97,7 +100,7 @@ "set_only_once": 1 }, { - "depends_on": "eval:doc.vehicle && doc.docstatus == 0", + "depends_on": "eval:doc.vehicle && doc.docstatus == 0 && doc.publish_module=='Automotive System' || doc.publish_module=='Feature Finder'", "fieldname": "variant_mapping", "fieldtype": "Link", "label": "Variant Mapping", @@ -140,6 +143,7 @@ "set_only_once": 1 }, { + "depends_on": "eval:doc.publish_module", "fieldname": "section_break_7", "fieldtype": "Section Break", "label": "Vehicle Details" @@ -191,14 +195,14 @@ "read_only": 1 }, { - "depends_on": "eval:doc.variant_mapping && doc.publish_type == \"Internal\" && doc.docstatus == 0", + "depends_on": "eval:doc.variant_mapping && doc.publish_type == \"Internal\" && doc.docstatus == 0 && doc.publish_module=='Automotive System';", "fieldname": "add_variant_mapping_to_publish", "fieldtype": "Button", "label": "Add Variant Mapping to Publish", "read_only_depends_on": "eval:doc.publish_type == \"Global\"" }, { - "depends_on": "eval:doc.variant_mapping && doc.docstatus == 0", + "depends_on": "eval:doc.variant_mapping && doc.docstatus == 0 && doc.publish_module=='Automotive System'", "fieldname": "kilometer_mapping_section", "fieldtype": "Section Break", "label": "Kilometer Mapping" @@ -274,7 +278,7 @@ "read_only": 1 }, { - "depends_on": "eval:doc.variant_mapping && doc.docstatus == 0", + "depends_on": "eval:doc.variant_mapping && doc.docstatus == 0 && doc.publish_module=='Automotive System' && doc.publish_module=='Feature Finder'", "fieldname": "variant", "fieldtype": "Small Text", "hidden": 1, @@ -306,12 +310,33 @@ "fieldname": "file_path", "fieldtype": "Data", "label": "File Path" + }, + { + "fieldname": "publish_module", + "fieldtype": "Select", + "label": "Module", + "options": "\nAutomotive System\nRepair service\nFeature Finder", + "reqd": 1 + }, + { + "fieldname": "feature_finder_publish", + "fieldtype": "Table", + "hidden": 1, + "label": "Feature Finder Publish", + "options": "Feature Finder Publish Data" + }, + { + "fieldname": "repair_checksheet_publish", + "fieldtype": "Table", + "hidden": 1, + "label": "Repair Checksheet Publish", + "options": "Repair Service Publish Data" } ], "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], - "modified": "2023-08-07 12:34:32.740534", + "modified": "2023-08-17 10:11:07.549614", "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 8a9771d..f08cd12 100644 --- a/smart_service/transactions/doctype/publish/publish.py +++ b/smart_service/transactions/doctype/publish/publish.py @@ -4,14 +4,29 @@ import sys from html import unescape import frappe +import os from frappe.model.document import Document import json +from datetime import date +from frappe.utils import cstr +from frappe.utils import logger current_db_name = frappe.conf.get("db_name") 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.utils.logger.set_log_level("DEBUG") +success_reponse = {"status": 1, "data": "", "message": ""} +failure_reponse = {"status": 0, "data": "", "error": ""} +module_name='feature_finder' class Publish(Document): def validate(self): + self.published_date = str(date.today()) + self.published_by = frappe.session.user # Selected variant and kilometer mapping details list variant = [] for vm in self.get('publish_documents'): @@ -33,6 +48,36 @@ class Publish(Document): self.kilometer_mapping_details = self.kilometer_mapping_details + \ 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_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 == '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) + update_feature_published_docs(self) + update_publish_status = frappe.db.sql( + """update `tabPublish Test` set publish_status='Published' where name='{0}'""".format(self.name)) + if self.docstatus == 1 and self.publish_status == 'To Publish' and self.publish_module == 'Repair service' and self.publish_type == 'Global' and self.feature_finder_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 @@ -142,6 +187,14 @@ def update_procedure(vehicle, lang, publish_type, doc): # Generate Publish versions +def update_publish_status(self): + try: + update_status = frappe.db.sql( + """update `tabPublish Test` set publish_status="Published" where name='{0}' """.format(self.name)) + except Exception as e: + return e + + @frappe.whitelist() def cal_ver(vehicle, lang, publish_type, doc): update_procedure(vehicle, lang, publish_type, doc) @@ -180,7 +233,7 @@ def global_publish(doc): procedure_link is not null; """.format(current_db_name, doc.name)) asset = frappe.db.sql("""select parent,name from {0}.`tabPublish_Docs` where parent = "{1}" and variant_mapping is not null and procedure_link is null""".format(current_db_name, doc.name)) - + if not procedure and not asset: frappe.throw("There is no item for global publish") @@ -220,17 +273,37 @@ def global_publish(doc): frappe.msgprint('Global Publish Created for ' + publish_record.name) +@frappe.whitelist() +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, + "release_description": res.release_description, + "publish_module": res.publish_module, + "feature_finder_publish":res.feature_finder_publish, + "repair_checksheet_publish":res.repair_checksheet_publish + }) + ret.insert() + return {"status": "success", "message": ret.name, "url": frappe.utils.get_url()} + except Exception as e: + frappe.throw(str(e)) + + @frappe.whitelist() def old_publish(vehicle, language): current_db_name = frappe.conf.get("db_name") publish_record = frappe.db.sql("""select name,publish_type from {0}.`tabPublish` where vehicle = "{1}" and language = "{2}" and publish_status='To Publish' and publish_type = 'Internal' and docstatus != '2'""".format( - current_db_name, vehicle, language), as_dict=1) + current_db_name, vehicle, language), as_dict=1) if publish_record: return publish_record global_publish_record = frappe.db.sql("""select name,publish_type from {0}.`tabPublish` where vehicle = "{1}" and language = "{2}" and publish_status='To Publish' and publish_type = 'Global' and docstatus != '2'""".format( - current_db_name, vehicle, language), as_dict=1) + current_db_name, vehicle, language), as_dict=1) if global_publish_record: return global_publish_record @@ -277,29 +350,29 @@ def update_mapping(variant_mapping, doc): @frappe.whitelist() -def get_vm_asset(doc,lang): +def get_vm_asset(doc, lang): doc = frappe.get_doc("Variant Mapping", doc) vm_assets = frappe.db.sql("""select category,language,attach_file,active_status from {0}.`tabVariant Mapping_Assets` - where parent = "{1}" and language '{2}' and published = '0'; """.format(current_db_name, doc.name,lang), as_dict=1) + where parent = "{1}" and language '{2}' and published = '0'; """.format(current_db_name, doc.name, lang), as_dict=1) return vm_assets @frappe.whitelist() -def get_sm_asset(doc, name,lang): +def get_sm_asset(doc, name, lang): system_map = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping="{1}" and name = "{2}" and language = '{3}'; """.format( - current_db_name, doc, name,lang), as_dict=1) + current_db_name, doc, name, lang), as_dict=1) if system_map: for s in system_map: doc = frappe.get_doc("System Mapping", s.name) system_asset = frappe.db.sql("""select systems,language,active_status,system_asset from {0}.`tabSystem Mapping_System Assets` - where parent = "{1}" and language = "{2}" and published = '0'; """.format(current_db_name, s.name,lang), as_dict=1) + where parent = "{1}" and language = "{2}" and published = '0'; """.format(current_db_name, s.name, lang), as_dict=1) return system_asset @frappe.whitelist() -def get_system(doc, name,lang): +def get_system(doc, name, lang): system_map = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping="{1}" and name = "{2}" and language = "{3}";""".format( - current_db_name, doc, name,lang), as_dict=1) + current_db_name, doc, name, lang), as_dict=1) if system_map: for s in system_map: doc = frappe.get_doc("System Mapping", s.name) @@ -308,6 +381,7 @@ def get_system(doc, name,lang): procedure_is_published = "0";""".format(current_db_name, s.name), as_dict=1) return system + @frappe.whitelist() def max_publish(doc): doc = frappe.get_doc("Publish", doc) @@ -381,3 +455,400 @@ def update_procedure_value(name, file_path): frappe.db.set_value( "Publish", self.name, "published_by", str(name)) frappe.db.commit() + +def update_feature_published_docs(self): + try: + + for d in self.feature_finder_publish: + + 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: + + for d in self.repair_checksheet_publish: + + 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)) + + +def create_publish_folders(folder_url): + try: + + if not os.path.isdir(folder_url + "/" + "Global"): + os.makedirs(folder_url + "/" + "Global") + + if not os.path.isdir(folder_url + "/" + "Internal"): + os.makedirs(folder_url + "/" + "Internal") + return True + + except Exception as e: + frappe.throw(str(e)) + return False + + +'''New Module Publish Section''' + +@frappe.whitelist() +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): + 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) + return data + except Exception as e: + return str(e) + + +def repair_checksheet_publish(vehicle, vehicle_id, + language, publish_type, release_description, + variant, parent): + try: + logger_file = f'{vehicle} - {language} - {publish_type} - repair checksheet' + logger = frappe.logger(logger_file, allow_site=True, file_count=100) + logger.info( + f'Repair Checksheet Started-{vehicle}-{language}-{publish_type}-{parent}') + + folder_url = base_url+"/"+vehicle.replace(' ', '-') + "/"+language + logger.info(f'Created Folder-{vehicle}-{language}-{publish_type}') + + '''Publish Ready Flags''' + publish_repair_checksheet = 0 + repair_checksheet_tmp = [] + + '''Create Folder For Publish''' + create_publish_folders(folder_url) + file_path = folder_url + "/" + publish_type + "/" + \ + vehicle.replace(' ', '-') + '-repair_check_sheet' + '.json' + + '''Append Published Data to Json''' + logger.info( + f'Repair Checksheet Data Append Start::{vehicle}-{language}-{publish_type}') + vehicle_data = { + 'vehicle': vehicle, + 'vehicle_myid': vehicle_id, + 'publish_type': publish_type, + 'publish_description': release_description, + 'publish_language': language, + 'data': '' + } + + '''update existing global json file''' + if os.path.isfile(file_path): + with open(file_path) as f: + published_data = json.load(f) + for i in parent: + repair_checksheet = repair_checksheet_data(vehicle, language, + publish_type, i.parent_name) + if repair_checksheet['status'] == 1: + publish_repair_checksheet = 1 + repair_checksheet_tmp.append( + repair_checksheet['data'][0]) + + repair_checksheet_tmp=get_latest_data({'data':published_data['data']},{'data':repair_checksheet_tmp}) + + else: + for i in parent: + repair_checksheet = repair_checksheet_data( + vehicle, language, publish_type, i.parent_name) + + if repair_checksheet['status'] == 1: + publish_repair_checksheet = 1 + if len(repair_checksheet['data']): + repair_checksheet_tmp.append( + repair_checksheet['data'][0]) + # frappe.msgprint(str(repair_checksheet['data'][0])) + repair_checksheet_tmp=get_latest_data({'data':repair_checksheet_tmp},{'data':[]}) + + if publish_repair_checksheet == 1: + """ Save publish file """ + vehicle_data['data'] = repair_checksheet_tmp + + with open(file_path, 'w') as outfile: + outfile.write(json.dumps(vehicle_data, indent=4, default=str)) + + return 1, file_path + + except Exception as e: + logger.info( + f'{vehicle} - {language} - {publish_type} 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): + 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 repair checksheet 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': '' + } + + '''Publish Ready Flags''' + publish_feature_finder = 0 + feature_finder_tmp = [] + + '''Create Folder For Publish''' + create_publish_folders(folder_url) + file_path = folder_url + "/" + publish_type + "/" + \ + vehicle.replace(' ', '-') + '-feature_finder' + '.json' + + '''Append Published Data to Json''' + logger.info( + f'Repair Checksheet Data Append Start::{vehicle}-{language}-{publish_type}') + '''update existing global json file''' + if os.path.isfile(file_path): + with open(file_path) as f: + published_data = json.load(f) + for i in parent: + feature_finder = feature_finder_data(vehicle, language, + publish_type, i.parent1,i.variant) + if feature_finder['status'] == 1: + publish_repair_checksheet = 1 + feature_finder_tmp.append( + feature_finder['data'][0]) + + 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) + 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':[]}) + + + # 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}') + + + 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']: + module_dic.update({d['name']: d}) + return module_dic + + +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: + if data_dic1[d1]['active_status'] == 'Inactive': + final_dic.pop(d1) + + for d2 in data_dic2: + if data_dic2[d2]['active_status'] == 'Inactive': + 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)) + + +def repair_checksheet_data(vehicle=None, language=None, + publish_type=None, parent=None): + try: + logger_file = f'{vehicle} - {language} - {publish_type} - repair_checksheet_data' + logger = frappe.logger(logger_file, + allow_site=True, file_count=100) + logger.info( + f"start of fetching repair checksheet data - {vehicle} - {language}") + + repair_service_details = frappe.db.sql(f"""select vehicle,vehicle_id, + name,language,check_list_name, + active_status,display_order,my_id + from `tabRepair Service Mapping` + where vehicle = '{vehicle}' + and language = '{language}' + and name = '{parent}'""", as_dict=1) + + for d in repair_service_details: + d['complaint'] = frappe.db.sql(f"""select complaint,remedial_action_ok, + remedial_action_not_ok,idx as display_order, + active_status from `tabRepair Service Child` + where parent = '{d['name']}' + order by display_order ;""", as_dict=1) + + logger.info( + f"end of fetching repair checksheet data {vehicle} - {language}") + success_reponse['data'] = repair_service_details + success_reponse[ + 'message'] = f'Repair Checksheet Fecthed Succesfully for {vehicle} - {language} - repair_checksheet_data ' + return success_reponse + + except Exception as e: + failure_reponse['error'] = f"{vehicle} - {language} has following error - " + str( + e) + logger.error('error in repair checksheet' + str(e)) + return failure_reponse + + +def feature_finder_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 feature finder checksheet data - {vehicle} - {language} - {variant} - {module_name}") + feature_finder_details = [] + if language == 'en': + feature_finder_details = frappe.db.sql(f"""select ff.name,ff.vehicle,ff.vehicle_id,ff.variant,ff.variant_id,ff.language, + ff.features_names as feature_name,ff.feature_category,ff.display_order,ff.active_status, + ffm.feature_pdf as pdf from `tabFeature Finder` ff left join `tabFeature Finder Master` ffm on + ff.features_names = ffm.feature_name + where ff.vehicle = "THAR" and ffm.vehicle = "{vehicle}" + and ff.variant = "{variant}" + and ff.language = "{language}" and ffm.language = "{language}" and ff.name="{parent}"; + """, as_dict=1) + logger.info(feature_finder_details) + else: + feature_finder_details = frappe.db.sql(f"""select ff.name,ff.vehicle,ff.vehicle_id,ff.variant,ff.variant_id,ff.language, + ff.translated_feature_name as feature_name,ff.feature_category, + ff.display_order,ff.active_status,ffm.feature_pdf as pdf from `tabFeature Finder` ff + left join `tabFeature Finder Master` ffm on ff.features_names = ffm.feature_name + where ff.vehicle = "{vehicle}" and ffm.vehicle = "{vehicle}" and ff.variant = "{variant}" + and ff.language = "{language}" and ff.name="{parent}" ; """, as_dict=1) + + for f in feature_finder_details: + f['disclaimer'] = frappe.db.sql(f''' + SELECT name,content,active_status,idx as display_order FROM `tabFeature Finder Disclaimer` + where parent = '{str(f['vehicle'])+ str('-')+ str(f['feature_name']) +str('-')+str(f['language'])}'; + ''', as_dict=1) + + sop_images = frappe.db.sql(f""" select image,display_order,active_status from `tabFeature Finder Images` where + parent = '{f['name']}' and feature_type ='SOP' order by display_order desc;""", as_dict=1) + + sop_content = frappe.db.sql(f"""select content,display_order, active_status from `tabFeature Finder Content` + where parent = '{f['name']}' and feature_type ='SOP' order by display_order desc;""", as_dict=1) + + sop_specification = frappe.db.sql(f"""select specification,value,display_order,active_status from `tabFeature Finder Specification` + where parent = '{f['name']}' and feature_type ='SOP' order by display_order desc;""", as_dict=1) + + f['sop'] = {'content': sop_content, 'images': sop_images, + 'specificaton': sop_specification} + post_vin_data = frappe.db.sql(f'''select name,idx as display_order,post_vin_cutoff_name,post_vin_cutoff_id + from `tabPost Vin Cutoff ID` where parent = '{f['name']}';''', as_dict=1) + for p in post_vin_data: + + vin_content = frappe.db.sql(f"""select content,display_order, active_status from `tabFeature Finder Content` + where parent = '{f['name']}' and post_vin_cutoff_name ='{p['post_vin_cutoff_name']}' order by display_order desc;""", as_dict=1) + + vin_images = frappe.db.sql(f""" select image,display_order,active_status from `tabFeature Finder Images` where + parent = '{f['name']}' and post_vin_cutoff_name ='{p['post_vin_cutoff_name']}' order by display_order desc;""", as_dict=1) + + vin_specification = frappe.db.sql(f"""select specification,value,display_order,active_status from `tabFeature Finder Specification` + where parent = '{f['name']}' and post_vin_cutoff_name ='{p['post_vin_cutoff_name']}' order by display_order desc;""", as_dict=1) + p['content'] = vin_content + p['images'] = vin_images + p['specificaton'] = vin_specification + + f['post_vin'] = post_vin_data + + logger.info( + f"end of fetching feature finder data {vehicle} - {language}") + success_reponse['data'] = feature_finder_details + success_reponse[ + 'message'] = f'Repair Checksheet Fecthed Succesfully for {vehicle} - {language}' + return success_reponse + + except Exception as e: + failure_reponse['error'] = f"{vehicle} - {language} has following error - " + str( + e) + 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( + current_db_name, doc.vehicle, doc.language)) + if ver: + return ver + + +@frappe.whitelist() +def cal_ver_new_module(vehicle, lang, publish_type, doc): + update_procedure(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(creation) from `tabPublish` where vehicle = "{vehi}" and language = "{lang}";""" + .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 \ No newline at end of file