From 14ce2337dff30616aa648c47fe827b16063a3e26 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Fri, 10 Jan 2025 14:20:48 +0530 Subject: [PATCH] fix: incorrect valuation rate for PI based revaluation --- erpnext/stock/stock_ledger.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index 997922c638ac..9c35ba55b3b8 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -1040,7 +1040,7 @@ def validate_negative_stock(self, sle): def get_dynamic_incoming_outgoing_rate(self, sle): # Get updated incoming/outgoing rate from transaction - if sle.recalculate_rate: + if sle.recalculate_rate or self.has_landed_cost_based_on_pi(sle): rate = self.get_incoming_outgoing_rate_from_transaction(sle) if flt(sle.actual_qty) >= 0: @@ -1048,6 +1048,14 @@ def get_dynamic_incoming_outgoing_rate(self, sle): else: sle.outgoing_rate = rate + def has_landed_cost_based_on_pi(self, sle): + if sle.voucher_type == "Purchase Receipt" and frappe.db.get_single_value( + "Buying Settings", "set_landed_cost_based_on_purchase_invoice_rate" + ): + return True + + return False + def get_incoming_outgoing_rate_from_transaction(self, sle): rate = 0 # Material Transfer, Repack, Manufacturing