From 74fe3714151dfa39be55fcc26b95a780dc0cd146 Mon Sep 17 00:00:00 2001 From: venkataakhil Date: Thu, 9 Nov 2023 14:50:01 +0530 Subject: [PATCH] FIlters working --- smart_service/apis/publish_api.py | 2 +- .../kilometer_mapping/kilometer_mapping.py | 4 +- .../transactions/doctype/publish/publish.js | 68 +++++----- .../doctype/system_mapping/system_mapping.js | 126 ++++++++++-------- 4 files changed, 105 insertions(+), 95 deletions(-) diff --git a/smart_service/apis/publish_api.py b/smart_service/apis/publish_api.py index 1e455e3..0b1aefd 100644 --- a/smart_service/apis/publish_api.py +++ b/smart_service/apis/publish_api.py @@ -489,7 +489,7 @@ def new_publish(args, publish_type, vehicle, language, version): else: pub_ver = frappe.db.sql(""" SELECT vehicle,language,format(version,2) as version,modified,publish_type FROM tabPublish where vehicle = "{}" - and publish_type = "Global" AND `language` = "{}" and publish_module="Automotive System" order by modified desc work 2 ;""".format(vehicle, language), as_dict=1) + and publish_type = "Global" AND `language` = "{}" and publish_module="Automotive System" order by modified desc;""".format(vehicle, language), as_dict=1) if pub_ver: prev_update_ver = pub_ver[1]["version"] diff --git a/smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.py b/smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.py index e496b7e..b214ff3 100644 --- a/smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.py +++ b/smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.py @@ -71,9 +71,9 @@ def get_config_kilometer(doc,docname): @frappe.whitelist() def km_filter(parent = None , record = None, km = None): if record == "All": - km_filters = frappe.db.sql(f"""select * from `tabKilometer Mapping_Items` where parent ="{parent}" order by LENGTH(kilometer);""",as_dict = 1) + km_filters = frappe.db.sql(f"""select * from `tabKilometer Mapping_Items` where parent ="{parent}" order by length(kilometer),kilometer;""",as_dict = 1) else: - km_filters =frappe.db.sql(f"""select * from `tabKilometer Mapping_Items` where parent ="{parent}" and kilometer ="{km}" order by LENGTH(kilometer) """,as_dict = 1) + km_filters =frappe.db.sql(f"""select * from `tabKilometer Mapping_Items` where parent ="{parent}" and kilometer ="{km}" order by length(kilometer),kilometer """,as_dict = 1) return km_filters \ No newline at end of file diff --git a/smart_service/transactions/doctype/publish/publish.js b/smart_service/transactions/doctype/publish/publish.js index ab4d104..6e51942 100644 --- a/smart_service/transactions/doctype/publish/publish.js +++ b/smart_service/transactions/doctype/publish/publish.js @@ -446,41 +446,43 @@ frappe.ui.form.on("Publish", { version: frm.doc.version, }, callback: function (r) { - debugger + + console.log(r.message,"r.message") if (r.message[0] == true) { - 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'); - // cur_frm.reload_doc() - }, - }); - frappe.msgprint({ - title: __("Notification"), - message: __( - "Successfully Published: " + r.message[1] - ), - primary_action: { - action(values) { - frm.save("Update"); + console.log("calling",r.message) + 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], }, - }, - }); - } - else{ - frappe.msgprint('Failed To Publish') - } + callback: (r) => { + // frm.save('Update'); + // cur_frm.reload_doc() + }, + }); + frappe.msgprint({ + title: __("Notification"), + message: __( + "Successfully Published: " + r.message[1] + ), + primary_action: { + action(values) { + frm.save("Update"); + }, + }, + }); + } + else{ + frappe.msgprint('Failed To Publish') + } }, }); } diff --git a/smart_service/transactions/doctype/system_mapping/system_mapping.js b/smart_service/transactions/doctype/system_mapping/system_mapping.js index a4aa4da..5c04043 100644 --- a/smart_service/transactions/doctype/system_mapping/system_mapping.js +++ b/smart_service/transactions/doctype/system_mapping/system_mapping.js @@ -16,15 +16,16 @@ cur_frm.fields_dict['system_sub_systems'].grid.get_field('procedure').get_query frappe.ui.form.on('System Mapping', { onload: function (frm) { - - frm.set_query("systems", "system_sub_systems", function (doc, cdt, cdn) { - return { - "query": "smart_service.transactions.doctype.system_mapping.system_mapping.system_filter", - filters: { - "system_filter": frm.doc.system_filter - } - }; - }); + if(frm.doc.system_filter){ + frm.set_query("systems", "system_sub_systems", function (doc, cdt, cdn) { + return { + "query": "smart_service.transactions.doctype.system_mapping.system_mapping.system_filter", + filters: { + "system_filter": frm.doc.system_filter + } + }; + }); + } frm.set_query("systems", "systems_assets", function (doc, cdt, cdn) { var system = []; frm.fields_dict.system_sub_systems.grid.grid_rows.forEach((row) => { @@ -62,6 +63,34 @@ frappe.ui.form.on('System Mapping', { } } } + if(!frm.is_new() && frm.doc.system_filter!=""){ + if(frm.doc.name){ + frappe.call({ + "method": "smart_service.transactions.doctype.system_mapping.system_mapping.sys_filter", + "args": { + "parent": frm.doc.name, + "systems":"", + "record":"All" + }, + callback:function(r){ + frm.set_value("system_sub_systems", ""); + debugger + for(var i=0;i<=r.message.length;i++){ + frm.add_child("system_sub_systems", { + 'systems': r.message[i].systems, + 'sub_systems': r.message[i].sub_systems, + 'active_status': r.message[i].active_status, + 'procedure': r.message[i].procedure, + 'procedure_status':r.message[i].procedure_status + }); + } + refresh_field('system_sub_systems') + + } + }); + } + + } if (frm.is_new()) { if (frm.doc.variant_mapping) var km_doc_name = frm.doc.variant_mapping + "-" + frm.doc.language + "-KM"; @@ -85,36 +114,15 @@ frappe.ui.form.on('System Mapping', { } else { frm.trigger('fnSave_caller'); } - frm.doc.system_filter = "All"; + // frm.doc.system_filter = "All"; if (frm.doc.system_filter == "All") { frm.get_field('system_sub_systems').grid.static_rows = false; frm.fields_dict.system_sub_systems.grid.grid_rows.forEach((row) => { $("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="' + row.doc.idx + '"]').show(); }); } - frappe.call({ - "method": "smart_service.transactions.doctype.system_mapping.system_mapping.sys_filter", - "args": { - "parent": frm.doc.name, - "systems":"", - "record":"All" - }, - callback:function(r){ - frm.set_value("system_sub_systems", ""); - for(var i=0;i<=r.message.length;i++){ - frm.add_child("system_sub_systems", { - 'systems': r.message[i].systems, - 'sub_systems': r.message[i].sub_systems, - 'active_status': r.message[i].active_status, - 'procedure': r.message[i].procedure, - 'procedure_status':r.message[i].procedure_status - }); - } - refresh_field('system_sub_systems') - - } - }); - + + frm.refresh(); }, after_save: function (frm) { @@ -174,7 +182,7 @@ frappe.ui.form.on('System Mapping', { frm.trigger('fnSet_SM_KM_4_VM'); }, system_filter: function (frm) { - if (frm.doc.system_filter == "All") { + if (frm.doc.system_filter == "All" && frm.doc.name) { frm.doc.sub_system_filter = "All"; frappe.call({ "method": "smart_service.transactions.doctype.system_mapping.system_mapping.sys_filter", @@ -184,7 +192,7 @@ frappe.ui.form.on('System Mapping', { "record":"All" }, callback:function(r){ - debugger + frm.set_value("system_sub_systems", ""); for(var i=0;i<=r.message.length;i++){ frm.add_child("system_sub_systems", { @@ -218,8 +226,8 @@ frappe.ui.form.on('System Mapping', { "systems":frm.doc.system_filter }, callback:function(r){ - debugger - frm.set_value("system_sub_systems", ""); + + // frm.set_value("system_sub_systems", ""); for(var i=0;i<=r.message.length;i++){ frm.add_child("system_sub_systems", { 'systems': r.message[i].systems, @@ -288,31 +296,31 @@ frappe.ui.form.on('System Mapping', { // $("select[data-fieldname='system_filter']").append(new Option("All", "All")); // frm.fields_dict.system_sub_systems.grid.grid_rows.forEach((row) => { // let value = row.doc.systems; - frappe.call({ - "method": "smart_service.transactions.doctype.system_mapping.system_mapping.get_syatem_value", - "args": { - name:frm.doc.name - - }, - callback:function(r){ - debugger - for(var i=0;i