ERPNext Conference 2019* ERPNext.com Blog

Help Filtering Child Items based on same child table field


#1

This is the case:

In doctype UOM i have created a child doctype wich contains a new field called uos
In Quotation Item i have a custom field called UOS.

i am trying to filter the uos field in quotation child table based on item stock_uom

for example UOM doctype has
Kg
---- uos Child Table contains
pounds
ounces
grams.

In quotation item when selection any item wich stock_uom is kg the uos values should only those.


#2

Hello,

You might have to write a custom script to make it work. If you have written any, and needs help in debugging, please share that custom script here.


#3

Hello @umair umair thanks for feedback i know how to custom scrips works as for parent doctype and for child tables base in parent doctype field. this one is diferent and i could not find any example before posting my question.

My custon scrips looks like this

frappe.ui.form.on("Quotation", "refresh", function(frm) {
cur_frm.fields_dict['items'].grid.get_field('uos').get_query = function(doc, cdt, cdn) {
	return {
		filters:[
			['parent', '=', 'Kilogramo']
		]
	}
}
});

That scrip work if i want to filter only the UOS under Kilogram parent Doctype but i want to make it dinamic by using the stock_uom field in quoation item doctype


#4

@rohit_w @kolate_sambhaji can you help?


#5

I’m looking to do the same thing in the next couple of days, and I’ll be watching this thread. The most immediate comparison I could think of was this:

which looks very similar to what you have done already… I don’t know if the selection is dynamic… I believe Rohit mentioned something about asynchronous behavior of JS that creates difficulty for client side scripting of these things.


#6

thanks for pointing out a solution the scrip works as this:

frappe.ui.form.on("Quotation", "refresh", function(frm) {
frm.fields_dict['items'].grid.get_field('uos').get_query = function(doc, cdt, cdn) {
child = locals[cdt][cdn];
			return{	
		filters:[
			['parent', '=', child.stock_uom]
		]
	}
}
});

Now is filtering uos based on a field in each row at child table.

Thank again!


Filter Child Table Based on Child Field using Query
#7

Great! Good to hear; I’ll be doing that soon. Thanks


#8

We have used something like this

frappe.ui.form.on("Delivery Note", "refresh", function(frm) {
	frm.fields_dict['items'].grid.get_field('batch_no').get_query = function(doc, cdt, cdn) {
		var child = locals[cdt][cdn];
		//console.log(child);
		return {	
			filters:[
				['en', '=', child.en]
			]
		}
	}
});