[v12] Pricing Rule Does not Apply on Descendants of Item Group

It seems surprising that a feature available in version-11 is gone in version-12 as usual. There seems to be multiple issues with pricing rule based on Item Group.

  1. The javascript would not return the UOM for Item Groups which don’t have items in it. Since Item Group is a tree structure there is bound to be groups without items and with their descendants having items. Now the code in question here is as below, which only considers that the Item Groups should have items associated with them but fails to consider the parent child relation in a tree structure of Item Group.
@frappe.whitelist()
@frappe.validate_and_sanitize_search_inputs
def get_item_uoms(doctype, txt, searchfield, start, page_len, filters):
	items = [filters.get('value')]
	if filters.get('apply_on') != 'Item Code':
		field = frappe.scrub(filters.get('apply_on'))
		items = [d.name for d in frappe.db.get_all("Item", filters={field: filters.get('value')})]

	return frappe.get_all('UOM Conversion Detail', filters={
			'parent': ('in', items),
			'uom': ("like", "{0}%".format(txt))
		}, fields = ["distinct uom"], as_list=1)
  1. The second issue is that the application of the Pricing Rule based on Item Group does not consider the parent-child relationship and if we apply a pricing rule on parent group it should apply to the child group unless specified otherwise.

Anyone facing such issues on the pricing rule front since this feature was a very old feature of erpnext and with advent of v12 its gone.

Well It seems that there could be an issue with my DB since some of the Pricing Rules are applying on some Item Groups even if they are parents and applying on their children but in particular all pricing rules based on 1 parent Item Group are not getting applied in my system. This seems a bit odd and since the problem is not system wide I think the feature still exists. Its now a matter of how to debug the issue in my DB.

Ok figured out the problem the Pricing Rule does not smartly tell which pricing rule is being applied on JS Script.
Basically there is a field called “Apply Multiple Pricing Rules” and if this field is unchecked as in case of migration from v11 to v12 since this field was non-existent in version-11 as show below.


The problem would be that if we have a pricing rule on Item Code and it does not have the multiple pricing rules checked then the Item Group pricing rule would not apply since the internal priority for pricing rule is as below:

Item Code > Item Group > Brand
Customer > Customer Group > Territory
Supplier > Supplier Type

So basically I had to check the apply multiple pricing rules on all the old pricing rules which were on Item Code.