[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#105476

X-original-commit: c29c668d694ef8d675116d42393e496636072d13
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
Signed-off-by: David <dafr@odoo.com>
This commit is contained in:
David (dafr)
2022-11-10 07:14:53 +01:00
parent 1709cba800
commit a64a3dc90b
@@ -42,14 +42,14 @@ class StockValuationLayer(models.Model):
def _validate_accounting_entries(self):
am_vals = []
for svl in self:
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
move = svl.stock_move_id
if not move:
move = svl.stock_valuation_layer_id.stock_move_id
am_vals += move._account_entry_move(svl.quantity, svl.description, svl.id, svl.value)
am_vals += move.with_company(svl.company_id)._account_entry_move(svl.quantity, svl.description, svl.id, svl.value)
if am_vals:
account_moves = self.env['account.move'].sudo().create(am_vals)
account_moves._post()