From f41bcc6fecfe1c4aad32dab16da28cef3d3f110e Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Sat, 24 May 2025 17:27:20 +0530 Subject: [PATCH] fix: absence of rounding causing discrepancy in the valuation rate calculation (backport #47700) (#47711) fix: absence of rounding causing discrepancy in the valuation rate calculation (#47700) (cherry picked from commit 1e8ed22421cf70803c41dc342b405b52ca55321a) Co-authored-by: rohitwaghchaure --- erpnext/stock/stock_ledger.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index ebf4973b066..0cda4baaadd 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -882,6 +882,12 @@ class update_entries_after: self.wh_data.stock_value = flt(self.wh_data.qty_after_transaction) * flt( self.wh_data.valuation_rate ) + + if sle.actual_qty < 0 and self.wh_data.qty_after_transaction != 0: + self.wh_data.valuation_rate = flt( + self.wh_data.stock_value, self.currency_precision + ) / flt(self.wh_data.qty_after_transaction, self.flt_precision) + else: self.update_queue_values(sle)