From 23b846ef39e1ddc0d7e0b44102d6e814d262cc0b 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 (cherry picked from commit 14ce2337dff30616aa648c47fe827b16063a3e26) (cherry picked from commit f7e3854641246a16d33f1699c450fc975ddc8ba4) --- 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 1b299b52dd6e..37e91080d5dd 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -1039,7 +1039,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: @@ -1047,6 +1047,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