From 5ba26b3dc116efa6d5636e439fad3051e2b9de63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miquel=20Ra=C3=AFch?= Date: Wed, 15 Dec 2021 14:18:00 +0100 Subject: [PATCH] [FIX] stock_account_prepare_anglo_saxon_out_lines_hook: update hook --- .../hooks.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/stock_account_prepare_anglo_saxon_out_lines_hook/hooks.py b/stock_account_prepare_anglo_saxon_out_lines_hook/hooks.py index 78fab6342..45589e0a5 100644 --- a/stock_account_prepare_anglo_saxon_out_lines_hook/hooks.py +++ b/stock_account_prepare_anglo_saxon_out_lines_hook/hooks.py @@ -8,6 +8,9 @@ def post_load_hook(): def new_stock_account_prepare_anglo_saxon_out_lines_vals(self): lines_vals_list = [] for move in self: + # Make the loop multi-company safe when accessing models like product.product + move = move.with_context(force_company=move.company_id.id) + if ( not move.is_sale_document(include_receipts=True) or not move.company_id.anglo_saxon_accounting @@ -23,9 +26,9 @@ def post_load_hook(): # FIRST HOOK ENDS # Retrieve accounts needed to generate the COGS. - accounts = line.product_id.product_tmpl_id.with_context( - force_company=line.company_id.id - ).get_product_accounts(fiscal_pos=move.fiscal_position_id) + accounts = line.product_id.product_tmpl_id.get_product_accounts( + fiscal_pos=move.fiscal_position_id + ) debit_interim_account = accounts["stock_output"] credit_expense_account = accounts["expense"] if not credit_expense_account: