From c71b571b68933796e32329660ba55b2ec8721f2c Mon Sep 17 00:00:00 2001 From: "Guillaume (guva)" Date: Thu, 7 Sep 2023 15:25:43 +0200 Subject: [PATCH] [FIX] base: superuser on company creation When creating a new company, SUPERUSER_ID is not added in `user_ids`. Therefore, when installing a new module, the newly created company is not in `self.env.companies`, which leads to an issue when computing `company_id`. Steps: - Install Accounting module - Create a new company with any localisation - Delete the tax closing entry - Try to install `stock_account` module -> Error: `_check_company` failed With this commit we add the company newly created to the superuser's `company_ids` opw-3488788 closes odoo/odoo#135276 X-original-commit: 771fdaf25eefdc30443e96b03b029346bebb50be Signed-off-by: Guillaume Vanleynseele (guva) --- odoo/addons/base/models/res_company.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/odoo/addons/base/models/res_company.py b/odoo/addons/base/models/res_company.py index 7c904eb52de..6d73b90d9a2 100644 --- a/odoo/addons/base/models/res_company.py +++ b/odoo/addons/base/models/res_company.py @@ -5,7 +5,7 @@ import base64 import logging import warnings -from odoo import api, fields, models, tools, _, Command +from odoo import api, fields, models, tools, _, Command, SUPERUSER_ID from odoo.exceptions import ValidationError, UserError from odoo.tools import html2plaintext, file_open, ormcache @@ -266,7 +266,7 @@ class Company(models.Model): # The write is made on the user to set it automatically in the multi company group. if companies: - self.env.user.write({ + (self.env.user | self.env['res.users'].browse(SUPERUSER_ID)).write({ 'company_ids': [Command.link(company.id) for company in companies], })