From e06b0dce8ee4c612db2cbb76c499bf76a5c4a0fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 25 Sep 2024 12:24:54 +0200 Subject: [PATCH] Set default companies and company for user only if there is one company --- modules/company/res.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/company/res.py b/modules/company/res.py index 9850e717e9..bed70e831c 100644 --- a/modules/company/res.py +++ b/modules/company/res.py @@ -151,12 +151,17 @@ class User(metaclass=PoolMeta): @classmethod def default_companies(cls): - company = Transaction().context.get('company') - return [company] if company else [] + pool = Pool() + Company = pool.get('company.company') + companies = Company.search([]) + if len(companies) == 1: + return [c.id for c in companies] @classmethod def default_company(cls): - return Transaction().context.get('company') + if companies := cls.default_companies(): + if len(companies) == 1: + return companies[0] @classmethod def default_company_filter(cls):