From 9ab429f84a93d1d9ba4d29bb143e5c105a9de12c Mon Sep 17 00:00:00 2001 From: Corentin Forler Date: Tue, 16 Sep 2025 12:39:24 +0200 Subject: [PATCH 1/2] fix(price): Also retrieve prices with packing_unit of 1 --- erpnext/stock/get_item_details.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index 00c48d1beb..2485d242a9 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -1196,11 +1196,14 @@ def get_item_price( if pctx.get("qty"): # Prefer where qty is multiple of packing list, if not found then generic price. - query = query.where((IfNull(ip.packing_unit, 0) == 0) | (pctx.get("qty") % ip.packing_unit == 0)) + query = query.where( + (IfNull(ip.packing_unit, 0) <= 1) + | (frappe.qb.functions("MOD", pctx.get("qty"), ip.packing_unit) == 0) + ) query = query.orderby(IfNull(ip.packing_unit, 0), order=frappe.qb.desc) else: # Prices without Packing Unit only. - query = query.where(IfNull(ip.packing_unit, 0) == 0) + query = query.where(IfNull(ip.packing_unit, 0) <= 1) if not ignore_party: if pctx.customer: -- GitLab From b0e6b52e7d7cf6e15314aaa997c9f47cb489bea6 Mon Sep 17 00:00:00 2001 From: Corentin Forler Date: Tue, 16 Sep 2025 12:39:53 +0200 Subject: [PATCH 2/2] fix: Don't check for packing_unit in query https://github.com/frappe/erpnext/blob/39049948b8ccaf949ee7ece32a10388c51959c7e/erpnext/stock/get_item_details.py#L1067 --- erpnext/stock/get_item_details.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index 2485d242a9..df1441840c 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -1194,17 +1194,6 @@ def get_item_price( # Prices without Company only. query = query.where(IfNull(ip.company, "") == "") - if pctx.get("qty"): - # Prefer where qty is multiple of packing list, if not found then generic price. - query = query.where( - (IfNull(ip.packing_unit, 0) <= 1) - | (frappe.qb.functions("MOD", pctx.get("qty"), ip.packing_unit) == 0) - ) - query = query.orderby(IfNull(ip.packing_unit, 0), order=frappe.qb.desc) - else: - # Prices without Packing Unit only. - query = query.where(IfNull(ip.packing_unit, 0) <= 1) - if not ignore_party: if pctx.customer: query = query.where(ip.customer == pctx.customer) -- GitLab