[IMP] base: allow company selection while creating a user

Currently, when creating a new user, even if there are multiple
companies to select from, the  "Multi Companies" related fields are
not visible in the form view. However once the record is saved, they
simply appear. This happens because the `companies_count` field based
on which the visibility changes, is a computed one but is not dependent
on any other field, and so while creating a new record, the value is
always zero for our compute field.

This commit improves the behavior by making the compute method
dependent on `company_id` field so that it can be triggered while
creating the record (thanks to default value being set for this field),
and thus shows / hides the company related fields properly.

taskID-2819559

Part-of: odoo/odoo#88738
This commit is contained in:
D J
2022-06-15 09:59:56 +02:00
committed by Umesh Gupta
parent 13eab9aa84
commit 010ae983ea
+1
View File
@@ -415,6 +415,7 @@ class Users(models.Model):
internal_users.share = False
(self - internal_users).share = True
@api.depends('company_id')
def _compute_companies_count(self):
self.companies_count = self.env['res.company'].sudo().search_count([])