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: