From 3084e3654c32c954a97412db15d540ae3dc5ff03 Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Wed, 20 May 2026 17:18:15 +0530 Subject: [PATCH] fix: item price with party condition (#55100) --- erpnext/stock/doctype/batch/test_batch.py | 1 + erpnext/stock/doctype/item/test_item.py | 1 + erpnext/stock/get_item_details.py | 13 ++++++++----- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/erpnext/stock/doctype/batch/test_batch.py b/erpnext/stock/doctype/batch/test_batch.py index 1ba25cb44f3..ed4a8c5509c 100644 --- a/erpnext/stock/doctype/batch/test_batch.py +++ b/erpnext/stock/doctype/batch/test_batch.py @@ -543,6 +543,7 @@ class TestBatch(ERPNextTestSuite): "plc_conversion_rate": 1, "customer": "_Test Customer", "name": None, + "qty": 1, } ) diff --git a/erpnext/stock/doctype/item/test_item.py b/erpnext/stock/doctype/item/test_item.py index 5404c58fb07..0725dacc18b 100644 --- a/erpnext/stock/doctype/item/test_item.py +++ b/erpnext/stock/doctype/item/test_item.py @@ -161,6 +161,7 @@ class TestItem(ERPNextTestSuite): "conversion_factor": 1, "price_list_uom_dependant": 1, "ignore_pricing_rule": 1, + "qty": 1, } ) ) diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index 69553153efa..4e9126c40c1 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -1202,9 +1202,15 @@ def get_item_price( if not ignore_party: if pctx.customer: - query = query.where(ip.customer == pctx.customer) + query = query.where( + (ip.customer == pctx.customer) + | ((IfNull(ip.customer, "") == "") & (IfNull(ip.supplier, "") == "")) + ).orderby(IfNull(ip.customer, ""), order=frappe.qb.desc) elif pctx.supplier: - query = query.where(ip.supplier == pctx.supplier) + query = query.where( + (ip.supplier == pctx.supplier) + | ((IfNull(ip.customer, "") == "") & (IfNull(ip.supplier, "") == "")) + ).orderby(IfNull(ip.supplier, ""), order=frappe.qb.desc) else: query = query.where((IfNull(ip.customer, "") == "") & (IfNull(ip.supplier, "") == "")) @@ -1262,9 +1268,6 @@ def get_price_list_rate_for(ctx: ItemDetailsCtx, item_code: str): if desired_qty and check_packing_list(price_list_rate[0].name, desired_qty, item_code): item_price_data = price_list_rate else: - for field in ["customer", "supplier"]: - del pctx[field] - general_price_list_rate = get_item_price(pctx, item_code, ignore_party=ctx.get("ignore_party")) if not general_price_list_rate and ctx.get("uom") != ctx.get("stock_uom"):