Skip to content

Commit

Permalink
[MIG] partner_edit_restrict
Browse files Browse the repository at this point in the history
  • Loading branch information
AungKoKoLin1997 committed Dec 1, 2023
1 parent 71e9214 commit ba8602a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
6 changes: 3 additions & 3 deletions partner_edit_restrict/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Copyright 2023 Quartile Limited
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Partner Edit Restrict",
"category": "Partner",
"version": "15.0.1.0.0",
"version": "11.0.1.0.0",
"author": "Quartile Limited",
"website": "https://www.quartile.co",
"license": "LGPL-3",
"license": "AGPL-3",
"depends": ["base"],
"data": [
"views/res_partner_views.xml",
Expand Down
22 changes: 13 additions & 9 deletions partner_edit_restrict/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright 2023 Quartile Limited
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _, fields, models
from odoo.exceptions import UserError
Expand All @@ -13,11 +13,15 @@ class ResPartner(models.Model):
)

def write(self, values):
if self.env.user.has_group("base.group_system"):
return super(ResPartner, self).write(values)
if self.env.is_superuser():
return super(ResPartner, self).write(values)
for record in self:
if record.restrict_edit:
raise UserError(_("You are not allowed to modify this partner record."))
return super(ResPartner, self).write(values)
if (
self.env.user.has_group("base.group_system")
or self.env.user._is_superuser()
):
return super().write(values)
restricted_recs = self.filtered(lambda x: x.restrict_edit)
if restricted_recs:
names = ", ".join(restricted_recs.mapped("name"))
raise UserError(
_("You are not allowed to modify following partner(s): %s", names)
)
return super().write(values)

0 comments on commit ba8602a

Please sign in to comment.