From 16492ac9f898cc1d506a244d2c0122e65bffa7ca 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 4fcb3cf98a..e46c489e51 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -999,11 +999,14 @@ def get_item_price(args, item_code, ignore_party=False, force_batch_no=False) -> if args.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) | (args.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 args.get("customer"): -- GitLab From 5beb4db3c0c894abdfbd176cca99b8e2452c0473 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 e46c489e51..9131bddc9d 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -997,17 +997,6 @@ def get_item_price(args, item_code, ignore_party=False, force_batch_no=False) -> # Prices without Company only. query = query.where(IfNull(ip.company, "") == "") - if args.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 args.get("customer"): query = query.where(ip.customer == args.get("customer")) -- GitLab