Skip to content

Commit

Permalink
Merge PR #2582 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by ilyasProgrammer
  • Loading branch information
OCA-git-bot committed Aug 8, 2023
2 parents 7b65223 + 4d4f934 commit 9feb7dd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
33 changes: 30 additions & 3 deletions web_field_required_invisible_manager/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

0 comments on commit 9feb7dd

Please sign in to comment.