From b140ce71d75fdc6c24664c2ec68a693a63e9d0f8 Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Tue, 4 Feb 2025 10:54:57 +0530 Subject: [PATCH] fix: fetch rate from item price list when document is saved (cherry picked from commit 1e4b9fbdf09aa998da5f829303a4c859f341e484) --- erpnext/controllers/accounts_controller.py | 2 +- erpnext/stock/get_item_details.py | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 2aadd6b584e..87671568bd8 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -817,7 +817,7 @@ class AccountsController(TransactionBase): item.get(fieldname) is None or fieldname in force_item_fields or ( - fieldname in ["serial_no", "batch_no"] + fieldname in ["serial_no", "batch_no", "rate", "price_list_rate"] and item.get("use_serial_batch_fields") ) ): diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index c604c4cd87c..e565b5c6015 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -206,13 +206,21 @@ def update_stock(ctx, out, doc=None): filter_batches(batches, doc) for batch_no, batch_qty in batches.items(): + rate = get_batch_based_item_price( + {"price_list": doc.selling_price_list, "uom": out.uom, "batch_no": batch_no}, + out.item_code, + ) if batch_qty >= qty: out.update({"batch_no": batch_no, "actual_batch_qty": qty}) + if rate: + out.update({"rate": rate, "price_list_rate": rate}) break else: qty -= batch_qty - out.update({"batch_no": batch_no, "actual_batch_qty": batch_qty}) + out.update({"batch_no": batch_no, "actual_batch_qty": qty}) + if rate: + out.update({"rate": rate, "price_list_rate": rate}) if out.has_serial_no and out.has_batch_no and has_incorrect_serial_nos(ctx, out): kwargs["batches"] = [ctx.get("batch_no")] if ctx.get("batch_no") else [out.get("batch_no")]