2021-03-23 19:15:27 +00:00
|
|
|
# © 2016 Opener B.V. (<https://opener.am>)
|
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
|
|
|
from flectra import api, fields, models
|
|
|
|
from flectra.exceptions import AccessError
|
|
|
|
from flectra.tools.translate import _
|
|
|
|
|
|
|
|
|
|
|
|
class ResUsers(models.Model):
|
|
|
|
_inherit = "res.users"
|
|
|
|
|
|
|
|
technical_features = fields.Boolean(
|
|
|
|
compute="_compute_technical_features", inverse="_inverse_technical_features"
|
|
|
|
)
|
|
|
|
show_technical_features = fields.Boolean(
|
|
|
|
string="Show field Technical Features",
|
|
|
|
compute="_compute_show_technical_features",
|
|
|
|
help=(
|
|
|
|
"Whether to display the technical features field in the user "
|
|
|
|
"preferences."
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
@api.depends("groups_id")
|
|
|
|
def _compute_show_technical_features(self):
|
|
|
|
"""Only display the technical features checkbox in the user
|
|
|
|
preferences if the user has access to them"""
|
|
|
|
for user in self:
|
2021-12-05 03:14:22 +00:00
|
|
|
user.show_technical_features = user.has_group("base.group_no_one")
|
2021-03-23 19:15:27 +00:00
|
|
|
|
|
|
|
@api.depends("groups_id")
|
|
|
|
def _compute_technical_features(self):
|
2022-06-29 18:41:04 +00:00
|
|
|
"""Map user membership to boolean field value"""
|
2021-03-23 19:15:27 +00:00
|
|
|
for user in self:
|
2021-12-05 03:14:22 +00:00
|
|
|
user.technical_features = user.has_group(
|
|
|
|
"base_technical_features.group_technical_features"
|
|
|
|
)
|
2021-03-23 19:15:27 +00:00
|
|
|
|
|
|
|
def _inverse_technical_features(self):
|
|
|
|
"""Map boolean field value to group membership, but checking
|
|
|
|
access"""
|
|
|
|
group = self.env.ref("base_technical_features.group_technical_features")
|
|
|
|
for user in self:
|
|
|
|
if self.env.ref("base.group_no_one") not in user.groups_id:
|
|
|
|
raise AccessError(
|
|
|
|
_("The user does not have access to technical " "features.")
|
|
|
|
)
|
|
|
|
if user.technical_features:
|
|
|
|
self.sudo().write({"groups_id": [(4, group.id)]})
|
|
|
|
else:
|
|
|
|
self.sudo().write({"groups_id": [(3, group.id)]})
|
|
|
|
|
|
|
|
def __init__(self, pool, cr):
|
|
|
|
super().__init__(pool, cr)
|
|
|
|
type(self).SELF_READABLE_FIELDS += [
|
|
|
|
"technical_features",
|
|
|
|
"show_technical_features",
|
|
|
|
]
|
|
|
|
type(self).SELF_WRITEABLE_FIELDS.append("technical_features")
|