From e6e10c5c0a1669b10039a017e8e488f52870a044 Mon Sep 17 00:00:00 2001 From: venkataakhil Date: Thu, 9 Nov 2023 10:49:24 +0530 Subject: [PATCH] Filter for System Mapping n kilometer mapping --- .../doctype/qwik_service/qwik_service.js | 2 +- .../kilometer_mapping/kilometer_mapping.js | 78 +++++++++-- .../kilometer_mapping/kilometer_mapping.py | 9 ++ .../doctype/system_mapping/system_mapping.js | 123 ++++++++++++++++-- .../system_mapping/system_mapping.json | 2 +- .../doctype/system_mapping/system_mapping.py | 21 +++ 6 files changed, 208 insertions(+), 27 deletions(-) diff --git a/smart_service/phase_2/doctype/qwik_service/qwik_service.js b/smart_service/phase_2/doctype/qwik_service/qwik_service.js index 5a74be5..d8e3d47 100644 --- a/smart_service/phase_2/doctype/qwik_service/qwik_service.js +++ b/smart_service/phase_2/doctype/qwik_service/qwik_service.js @@ -117,7 +117,7 @@ frappe.ui.form.on('Qwik Service', { frappe.call({ method: "smart_service.phase_2.doctype.qwik_service.qwik_service.get_kilometer", args: { - vehicle: frm.doc.vehicle, + vehicle: frm.doc.vehicle, service_kilometers: frm.doc.service_kilometers }, callback: function (r) { diff --git a/smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.js b/smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.js index 5a5ffd7..33bae44 100644 --- a/smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.js +++ b/smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.js @@ -65,6 +65,30 @@ frappe.ui.form.on('Kilometer Mapping', { $("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="' + row.doc.idx + '"]').show(); }); } + frappe.call({ + "method": "smart_service.transactions.doctype.kilometer_mapping.kilometer_mapping.km_filter", + "args": { + "parent": frm.doc.name, + "km":"", + "record":"All" + }, + callback:function(r){ + // debugger + frm.set_value("config_kilometer", ""); + for(var i=0;i<=r.message.length;i++){ + frm.add_child("config_kilometer", { + 'kilometer': r.message[i].kilometer, + 'mat': r.message[i].mat, + 'sub_systems': r.message[i].sub_systems, + 'applicable': r.message[i].applicable + }); + } + refresh_field('config_kilometer') + + } + }); + + frm.refresh(); frm.refresh(); }, @@ -221,23 +245,53 @@ frappe.ui.form.on('Kilometer Mapping', { kilometer_filter: function (frm) { if (frm.doc.kilometer_filter == "All") { - frm.doc.sub_system_filter = "All"; - cur_frm.refresh_field('sub_system_filter'); - frm.get_field('config_kilometer').grid.static_rows = false; - frm.fields_dict.config_kilometer.grid.grid_rows.forEach((row) => { - $("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="' + row.doc.idx + '"]').show(); + frm.doc.kilometer_filter = "All"; + frappe.call({ + "method": "smart_service.transactions.doctype.kilometer_mapping.kilometer_mapping.km_filter", + "args": { + "parent": frm.doc.name, + "km":"", + "record":"All" + }, + callback:function(r){ + // debugger + frm.set_value("config_kilometer", ""); + for(var i=0;i<=r.message.length;i++){ + frm.add_child("config_kilometer", { + 'kilometer': r.message[i].kilometer, + 'mat': r.message[i].mat, + 'sub_systems': r.message[i].sub_systems, + 'applicable': r.message[i].applicable + }); + } + refresh_field('config_kilometer') + + } }); - } else { + }else{ frm.get_field('config_kilometer').grid.static_rows = false; - frm.fields_dict.config_kilometer.grid.grid_rows.forEach((row) => { - if (row.doc.kilometer != frm.doc.kilometer_filter) { - $("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="' + row.doc.idx + '"]').hide(); - } else { - $("div[data-fieldname=config_kilometer]").find('div.grid-row[data-idx="' + row.doc.idx + '"]').show(); + frappe.call({ + "method": "smart_service.transactions.doctype.kilometer_mapping.kilometer_mapping.km_filter", + "args": { + "parent": frm.doc.name, + "km":frm.doc.kilometer_filter + }, + callback:function(r){ + // debugger + frm.set_value("config_kilometer", ""); + for(var i=0;i<=r.message.length;i++){ + frm.add_child("config_kilometer", { + 'kilometer': r.message[i].kilometer, + 'mat': r.message[i].mat, + 'sub_systems': r.message[i].sub_systems, + 'applicable': r.message[i].applicable + }); + } + refresh_field('config_kilometer') + } }); } - frm.refresh(); }, kilometer_filter1: function (frm) { diff --git a/smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.py b/smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.py index 8c0e962..e496b7e 100644 --- a/smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.py +++ b/smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.py @@ -68,3 +68,12 @@ def get_config_kilometer(doc,docname): return {"status":"success"} +@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) + + 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) + + return km_filters \ No newline at end of file diff --git a/smart_service/transactions/doctype/system_mapping/system_mapping.js b/smart_service/transactions/doctype/system_mapping/system_mapping.js index b513a0c..a4aa4da 100644 --- a/smart_service/transactions/doctype/system_mapping/system_mapping.js +++ b/smart_service/transactions/doctype/system_mapping/system_mapping.js @@ -37,7 +37,6 @@ frappe.ui.form.on('System Mapping', { } }; }); - frm.trigger('fnLoadmat_initial_values'); }, validate: function (frm) { @@ -86,6 +85,37 @@ frappe.ui.form.on('System Mapping', { } else { frm.trigger('fnSave_caller'); } + 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) { cur_frm.reload_doc(); @@ -145,6 +175,30 @@ frappe.ui.form.on('System Mapping', { }, system_filter: function (frm) { if (frm.doc.system_filter == "All") { + frm.doc.sub_system_filter = "All"; + frappe.call({ + "method": "smart_service.transactions.doctype.system_mapping.system_mapping.sys_filter", + "args": { + "parent": frm.doc.name, + "systems":"", + "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", { + '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.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(); @@ -157,13 +211,36 @@ frappe.ui.form.on('System Mapping', { } else { frm.get_field('system_sub_systems').grid.static_rows = false; - frm.fields_dict.system_sub_systems.grid.grid_rows.forEach((row) => { - if (row.doc.systems != frm.doc.system_filter) { - $("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="' + row.doc.idx + '"]').hide(); - } else { - $("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":frm.doc.system_filter + }, + 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", { + '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.fields_dict.system_sub_systems.grid.grid_rows.forEach((row) => { + // if (row.doc.systems != frm.doc.system_filter) { + // $("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="' + row.doc.idx + '"]').hide(); + // } else { + // $("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="' + row.doc.idx + '"]').show(); + // } + // }); frm.get_field('systems_assets').grid.static_rows = false; frm.fields_dict.systems_assets.grid.grid_rows.forEach((row) => { @@ -174,6 +251,7 @@ frappe.ui.form.on('System Mapping', { } }); } + }, special_character: function(frm){ var regex = /[!@#$%^&*()_+\=\[\]{};'`~:"\\|,.<>\/?]+/; @@ -206,16 +284,35 @@ frappe.ui.form.on('System Mapping', { }, fnsetsystemsfilter: function (frm) { var filtered_systems = frm.doc.system_filter; - $("select[data-fieldname='system_filter']").empty(); - $("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; - if (value) - if ($("select[data-fieldname='system_filter'] option[value='" + value + "']").length === 0) { + // $("select[data-fieldname='system_filter']").empty(); + // $("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