diff --git a/web_field_required_invisible_manager/models/models.py b/web_field_required_invisible_manager/models/models.py index 78555ee24026..3858887673d5 100644 --- a/web_field_required_invisible_manager/models/models.py +++ b/web_field_required_invisible_manager/models/models.py @@ -44,9 +44,7 @@ def fields_view_get( ("group_ids", "in", self.env.user.groups_id.ids), ] ) - if not restrictions: - return arch - else: + if restrictions: return self.create_restrictions_fields(restrictions, view_type, arch) return arch @@ -127,3 +125,32 @@ def _compute_restrictions_fields(self): elif r.group_ids: if r.group_ids & self.env.user.groups_id: record[field_name] = True + + def default_get(self, fields_list): + res = super(Base, self).default_get(fields_list) + vals = self._default_get_compute_restrictions_fields() + if vals: + res.update(vals) + return res + + def _default_get_compute_restrictions_fields(self): + restrictions = self.env["custom.field.restriction"].search( + [("model_name", "=", self._name)] + ) + values = {} + if not restrictions: + return values + for r in restrictions: + if r.visibility_field_id: + field_name = r.visibility_field_id.name + values[field_name] = False + if r.required_field_id: + field_name = r.required_field_id.name + values[field_name] = False + if r.readonly_field_id: + field_name = r.readonly_field_id.name + values[field_name] = False + if r.group_ids: + if r.group_ids & self.env.user.groups_id: + values[field_name] = True + return values diff --git a/web_field_required_invisible_manager/tests/test_web_field_required_invisible_manager.py b/web_field_required_invisible_manager/tests/test_web_field_required_invisible_manager.py index 2d31132977b8..1e9bb32356af 100644 --- a/web_field_required_invisible_manager/tests/test_web_field_required_invisible_manager.py +++ b/web_field_required_invisible_manager/tests/test_web_field_required_invisible_manager.py @@ -130,3 +130,8 @@ def test_all_web_field_required_invisible_manager(self): self.invisible_title_rec_id.unlink() field_id = self.env["ir.model.fields"].search([("name", "=", field_name)]) self.assertFalse(field_id) + # default get + self.env["res.partner"].default_get(["name"]) + self.env["res.partner"].default_get(["city"]) + self.env["res.partner.title"].default_get(["name"]) + self.env["res.partner.title"].default_get(["shortcut"])