Browse Source

Filter for System Mapping n kilometer mapping

version2
venkataakhil 1 year ago
parent
commit
e6e10c5c0a
  1. 2
      smart_service/phase_2/doctype/qwik_service/qwik_service.js
  2. 78
      smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.js
  3. 9
      smart_service/transactions/doctype/kilometer_mapping/kilometer_mapping.py
  4. 123
      smart_service/transactions/doctype/system_mapping/system_mapping.js
  5. 2
      smart_service/transactions/doctype/system_mapping/system_mapping.json
  6. 21
      smart_service/transactions/doctype/system_mapping/system_mapping.py

2
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) {

78
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) {

9
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

123
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<r.message.length;i++){
let value = r.message[i]
debugger
$("select[data-fieldname='system_filter']").append(new Option(value, value));
}
// let value = r.message;
// if (value)
// if ($("select[data-fieldname='system_filter'] option[value='" + value + "']").length === 0) {
// $("select[data-fieldname='system_filter']").append(new Option(value, value));
// }
}
})
});
// });
console.log(filtered_systems)
frm.doc.system_filter = filtered_systems;
},
fnLoadmat_initial_values: function (frm) {

2
smart_service/transactions/doctype/system_mapping/system_mapping.json

@ -172,7 +172,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2022-05-31 12:01:37.798339",
"modified": "2023-11-08 17:10:55.421383",
"modified_by": "Administrator",
"module": "Transactions",
"name": "System Mapping",

21
smart_service/transactions/doctype/system_mapping/system_mapping.py

@ -267,3 +267,24 @@ def system_filter(doctype, txt, searchfield, start, page_len, filters):
(name like "%%%(txt)s%%") order by modified desc limit %(start)s, %(page_len)s """.format(current_db_name)%{"txt": txt, "start": start, "page_len": page_len})
@frappe.whitelist()
def sys_filter(parent = None , record = None, systems = None):
if record == "All":
sys = frappe.db.sql(f"""select * from `tabSystem Mapping_Sub System` where parent ="{parent}" order by systems;""",as_dict = 1)
else:
sys =frappe.db.sql(f"""select * from `tabSystem Mapping_Sub System` where parent ="{parent}" and systems ="{systems}" order by systems """,as_dict = 1)
return sys
@frappe.whitelist()
def get_syatem_value(name):
sys_list = frappe.db.sql_list(f"""select DISTINCT systems from `tabSystem Mapping_Sub System` where parent ="{name}" order by systems;""")
sys_list.insert(0,"All")
return sys_list
# if sys_list:
# return "\n".join(str(sys) for sys in sys_list)

Loading…
Cancel
Save