From 33fa9cff038691a98ca840fe0d72484da16276ba Mon Sep 17 00:00:00 2001
From: "David (dafr)" <dafr@odoo.com>
Date: Thu, 3 Nov 2022 15:25:28 +0000
Subject: [PATCH] [FIX] stock_account: Use correct company for SVL account_move
 creation

The valuation field of the product_id is company-dependent.
If the user validate the picking in multi-company context with his current company != picking company, then the checks may fail, and the account move can not be created.

closes odoo/odoo#105149

X-original-commit: f2a4d537c670a9c33dcf03d00baa19c1dca85c19
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
---
 addons/stock_account/models/stock_move.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/addons/stock_account/models/stock_move.py b/addons/stock_account/models/stock_move.py
index a29c89f6a71c..d1bcac3bbaa7 100644
--- a/addons/stock_account/models/stock_move.py
+++ b/addons/stock_account/models/stock_move.py
@@ -272,11 +272,11 @@ class StockMove(models.Model):
 
 
         for svl in stock_valuation_layers:
-            if not svl.product_id.valuation == 'real_time':
+            if not svl.with_company(svl.company_id).product_id.valuation == 'real_time':
                 continue
             if svl.currency_id.is_zero(svl.value):
                 continue
-            svl.stock_move_id._account_entry_move(svl.quantity, svl.description, svl.id, svl.value)
+            svl.stock_move_id.with_company(svl.company_id)._account_entry_move(svl.quantity, svl.description, svl.id, svl.value)
 
         stock_valuation_layers._check_company()
 
-- 
GitLab