diff --git a/smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.js b/smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.js index 33bae44..3313bed 100644 --- a/smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.js +++ b/smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.js @@ -13,10 +13,9 @@ frappe.ui.form.on('Kilometer Mapping', { }, onload: function (frm) { - $(document).on('mouseover', function (events) { - $("a:contains(Copy to Clipboard)").css({ 'pointer-events': 'none' }) - $("a:contains(Duplicate)").css({ 'pointer-events': 'none' }); + $("a:contains(Copy to Clipboard)").css({ 'pointer-events': 'none' }), + $("a:contains(Duplicate)").css({ 'pointer-events': 'none' }); }), //IDX make read only $('div[data-fieldname=config_kilometer]').find('div[class=form-grid]').find('div[class=grid-heading-row]').find('div[class="row-index sortable-handle col col-xs-1"]').find('input[class="grid-row-check pull-left"]').css({ 'visibility': 'hidden' }); @@ -57,6 +56,66 @@ frappe.ui.form.on('Kilometer Mapping', { }, validate: function (frm) { + // //custom button + // frm.add_custom_button(__("Duplicate Data"), function () { + // let d = new frappe.ui.Dialog({ + // title: 'Choose the variant', + // fields: [ + // { + // label: 'Variant', + // fieldname: 'variant', + // fieldtype: 'Link', + // options: "Kilometer Mapping" + // }, + // { + // label: '', + // fieldname: 'content_html', + // fieldtype: 'HTML', + // }, + // ], + // size: 'small', + // secondary_action_label: "No", + // primary_action_label: 'Yes', + // primary_action(values) { + // console.log(values); + // if (values) { + + // if (frm.doc.config_kilometer && frm.doc.config_kilometer.length > 0) { + // cur_frm.clear_table("config_kilometer"); + // cur_frm.refresh_fields('config_kilometer'); + // } + // cur_frm.refresh_fields("config_kilometer"); + // frappe.call({ + // "method": "smart_service.transactions.doctype.kilometer_mapping.kilometer_mapping.get_config_kilometer", + // "args": { + // "doc": values.variant, + // "docname": frm.doc.name + // }, + // callback: function (r) { + // if (r.message && r.message.length > 0) { + // cur_frm.refresh_fields("config_kilometer"); + // frm.save() + // frm.refresh() + // } + // } + // }) + // d.hide(); + + // } + + + // }, + // secondary_action(values) { + // d.hide(); + // } + // }); + + // d.show(); + // var res = $(d.fields_dict.content_html.wrapper).empty(); + // var ret = "
Upload the Kilometer
" + // res.append(ret) + // }).css({ "color": "#fff", "background-color": "red" });; + // //end frm.doc.kilometer_filter = "All"; if (frm.doc.kilometer_filter == "All") { @@ -65,30 +124,6 @@ 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(); }, @@ -104,7 +139,7 @@ frappe.ui.form.on('Kilometer Mapping', { fieldname: 'variant', fieldtype: 'Link', options: "Kilometer Mapping", - reqd:1 + reqd: 1 } ], size: 'small', @@ -131,7 +166,7 @@ frappe.ui.form.on('Kilometer Mapping', { }) d.hide(); } - else{ + else { d.hide() } }, @@ -245,73 +280,25 @@ frappe.ui.form.on('Kilometer Mapping', { kilometer_filter: function (frm) { if (frm.doc.kilometer_filter == "All") { - 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') - - } + 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(); }); - }else{ + } else { frm.get_field('config_kilometer').grid.static_rows = false; - 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.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(); } }); } + frm.refresh(); }, - kilometer_filter1: function (frm) { - frm.doc.duplicate_kilometer_mapping_items = ''; - frm.refresh_field('duplicate_kilometer_mapping_items'); - console.log("call") - frappe.call({ - "method": "smart_service.transactions.doctype.kilometer_mapping.kilometer_mapping.update_duplicate_km", - "args": { - "doc": frm.doc.name, - "kilometer": frm.doc.kilometer_filter - }, - callback: function (r) { - cur_frm.reload_doc() - } - }) - }, - - - sub_system_filter: function (frm) { if (!trigger) { trigger = true; return; } if (frm.doc.kilometer_filter != "All") { @@ -342,8 +329,8 @@ frappe.ui.form.on('Kilometer Mapping', { sort_by_kilometer: function (frm) { var idx = 1; frm.doc.config_kilometer.sort(function (a, b) { - if (parseInt(a.kilometer) < parseInt(b.kilometer)) { console.log(a.kilometer + "inside if" + b.kilometer); return -1 } - else if (parseInt(a.kilometer) > parseInt(b.kilometer)) { console.log(a.kilometer + "inside else if" + b.kilometer); return 1 } + if (parseInt(a.kilometer) < parseInt(b.kilometer)) { return -1 } + else if (parseInt(a.kilometer) > parseInt(b.kilometer)) { return 1 } return 1; }); diff --git a/smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.py b/smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.py index b214ff3..26ffeef 100644 --- a/smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.py +++ b/smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.py @@ -68,12 +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),kilometer;""",as_dict = 1) +# @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),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),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),kilometer """,as_dict = 1) - return km_filters \ No newline at end of file +# 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 5c04043..d05c5b8 100644 --- a/smart_service/transactions/doctype/system_mapping/system_mapping.js +++ b/smart_service/transactions/doctype/system_mapping/system_mapping.js @@ -16,16 +16,15 @@ cur_frm.fields_dict['system_sub_systems'].grid.get_field('procedure').get_query frappe.ui.form.on('System Mapping', { onload: function (frm) { - 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", "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) => { @@ -38,6 +37,7 @@ frappe.ui.form.on('System Mapping', { } }; }); + frm.trigger('fnLoadmat_initial_values'); }, validate: function (frm) { @@ -63,38 +63,10 @@ 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"; - frappe.db.exists('System Mapping', frm.doc.variant_mapping + "-" + frm.doc.language + "-SM") + frappe.db.exists('System Mapping', frm.doc.variant_mapping + "-" + frm.doc.language + "-SM") .then(smexists => { if (smexists) { frm.doc.variant_mapping = ''; @@ -114,16 +86,6 @@ 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(); - }); - } - - - frm.refresh(); }, after_save: function (frm) { cur_frm.reload_doc(); @@ -155,7 +117,7 @@ frappe.ui.form.on('System Mapping', { }); }, onload_post_render: function (frm) { - frm.fields_dict.system_sub_systems.grid.grid_rows.forEach((row) => { + frm.fields_dict.system_sub_systems.grid.grid_rows.forEach((row) => { if (row.doc.procedure_status == "Publish Ready") { $("div[data-fieldname=system_sub_systems]").find('div.grid-row[data-idx="' + row.doc.idx + '"]').find('div.col[data-fieldname="procedure_status"]').css({ 'background-color': '#ffc3c3' }); } else if (row.doc.procedure_status == "Published") { @@ -182,31 +144,7 @@ frappe.ui.form.on('System Mapping', { frm.trigger('fnSet_SM_KM_4_VM'); }, system_filter: function (frm) { - 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", - "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') - - } - }); + 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(); @@ -219,36 +157,13 @@ frappe.ui.form.on('System Mapping', { } else { frm.get_field('system_sub_systems').grid.static_rows = false; - 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){ - - // 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.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) => { @@ -259,9 +174,8 @@ frappe.ui.form.on('System Mapping', { } }); } - }, - special_character: function(frm){ + special_character: function (frm) { var regex = /[!@#$%^&*()_+\=\[\]{};'`~:"\\|,.<>\/?]+/; for (var i = 0; i < cur_frm.doc.system_sub_systems.length; i++) { if (regex.test(cur_frm.doc.system_sub_systems[i].rts) === true) { @@ -292,35 +206,16 @@ 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(frm.doc.name){ - frappe.call({ - "method": "smart_service.transactions.doctype.system_mapping.system_mapping.get_syatem_value", - "args": { - name:frm.doc.name - - }, - callback:function(r){ - - for(var i=0;i