[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) <guva@odoo.com>
This commit is contained in:
Guillaume (guva)
2023-09-13 12:19:09 +00:00
parent 945b96378f
commit c71b571b68
+2 -2
View File
@@ -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],
})