Items only need to shows based on Company

Dear sir,

I had multiple company and item group are assigned based on the company, In sales Invoice, if i select company that particular company items only need to display in item table.but items shows for every company.


These are the items assigned to particular company

i need only this company but, its shows for all company

Right now all items only assigned for one company.how to solve this any client script required?

thanks in advance,
Mohamed.

@Mohamed2335

  1. Have you written any Custom Filter Query for this ?
  2. By Default It Has filter of Is Sales = 1 and Disabled = 0

You Need to write your custom script or may be customer filter query on server side also based on setup you have to add company in item.

yeah, i wrote client script, but in company fields other company names are disappeared.

frappe.ui.form.on(‘Sales Invoice’, {
refresh: function(frm) {
frm.fields_dict[‘company’].get_query = function(doc, cdt, cdn) {
return {
filters: [
[‘name’, ‘=’, ‘Value Deal Trading LLC’]
]
};
};

    frm.fields_dict['items'].grid.get_field('item_code').get_query = function(doc, cdt, cdn) {
        if (frm.doc.company !== 'Value Deal Trading LLC') {
            return {
                filters: [
                    ['item_group', '=', 'Value Deal Item Group']
                ]
            };
        }
    };
}

});

frappe.ui.form.on('Sales Invoice', {
    refresh: function(frm) {
		setTimeout(function(){
			frm.fields_dict['items'].grid.get_field('item_code').get_query = function(doc, cdt, cdn) {
				return {
					filters: {
						'item_group' : frm.doc.company
					},
				}
			};
		}, 500);
	}
});

@Mohamed2335 Try this once, also try with increasing timeout if not worked on first go

1 Like