Skip to content

Commit

Permalink
Merge PR #174 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by legalsylvain
  • Loading branch information
github-grap-bot committed Dec 17, 2024
2 parents 03a44ca + 247551d commit ce34630
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions partner_hide_technical_user/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,22 @@ class ResPartner(models.Model):

# Overload Section
def write(self, vals):
self._check_technical_partner_access_user()
self._check_technical_partner_access_user("write")
return super().write(vals)

def unlink(self):
self._check_technical_partner_access_user()
self._check_technical_partner_access_user("unlink")
return super().unlink()

# Custom section
def _check_technical_partner_access_user(self):
def _check_technical_partner_access_user(self, operation):
# We use SUPERUSER_ID to be sure to not skip some users, due to
# some custom access rules deployed on databases
ResUsers = self.env["res.users"].sudo()
users = ResUsers.with_context(active_test=False).search(
[("partner_id", "in", self.ids)]
ResUsers = self.env["res.users"]
users = (
ResUsers.sudo()
.with_context(active_test=False)
.search([("partner_id", "in", self.ids)])
)
if not users:
return
Expand All @@ -49,13 +51,9 @@ def _check_technical_partner_access_user(self):
return

# Check if current user has correct access right
if not self.env.user.has_group("base.group_erp_manager"):
if not ResUsers.check_access_rights(operation, raise_exception=False):
raise UserError(
_(
"You must be part of the group Administration / Access"
" Rights to update partners associated to"
" users.\n- %s"
)
_("You have no right to update partners associated to" " users.\n- %s")
% ("\n- ".join(users.mapped("name")))
)

Expand Down

0 comments on commit ce34630

Please sign in to comment.