From 3fdddda77d60e0a42682175f723366278b562ddb Mon Sep 17 00:00:00 2001 From: Joan Sisquella Date: Mon, 10 Jul 2023 10:40:46 +0200 Subject: [PATCH] [FIX] hr_employee_birthay_mail: res_users configurable --- hr_employee_birthday_mail/__manifest__.py | 7 ++++- hr_employee_birthday_mail/models/__init__.py | 1 + .../models/hr_employee.py | 2 ++ hr_employee_birthday_mail/models/res_user.py | 26 +++++++++++++++++++ .../views/res_user_views.xml | 16 ++++++++++++ 5 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 hr_employee_birthday_mail/models/res_user.py create mode 100644 hr_employee_birthday_mail/views/res_user_views.xml diff --git a/hr_employee_birthday_mail/__manifest__.py b/hr_employee_birthday_mail/__manifest__.py index d39e0563452a..7fd0d054f554 100644 --- a/hr_employee_birthday_mail/__manifest__.py +++ b/hr_employee_birthday_mail/__manifest__.py @@ -9,7 +9,12 @@ "author": "ForgeFlow, Odoo Community Association (OCA)", "website": "https://github.com/OCA/hr", "depends": ["hr", "mail"], - "data": ["data/data.xml", "data/ir_cron.xml", "views/hr_employee_views.xml"], + "data": [ + "data/data.xml", + "data/ir_cron.xml", + "views/hr_employee_views.xml", + "views/res_user_views.xml", + ], "installable": True, "application": False, "auto_install": False, diff --git a/hr_employee_birthday_mail/models/__init__.py b/hr_employee_birthday_mail/models/__init__.py index e11a62f98ca0..529f9e93739f 100644 --- a/hr_employee_birthday_mail/models/__init__.py +++ b/hr_employee_birthday_mail/models/__init__.py @@ -1 +1,2 @@ from . import hr_employee +from . import res_user diff --git a/hr_employee_birthday_mail/models/hr_employee.py b/hr_employee_birthday_mail/models/hr_employee.py index 543451cc8b9a..64873d2635ee 100644 --- a/hr_employee_birthday_mail/models/hr_employee.py +++ b/hr_employee_birthday_mail/models/hr_employee.py @@ -13,10 +13,12 @@ class HrEmployee(models.Model): default=False, help="Check this box if you want to allow birthday wishes from our company " "and allow the others to be notified of your birthday.", + groups="hr.group_hr_user", ) notify_others_birthday = fields.Boolean( default=False, help="Check this box if you want to be notified about other coworkers' birthdays.", + groups="hr.group_hr_user", ) @api.model diff --git a/hr_employee_birthday_mail/models/res_user.py b/hr_employee_birthday_mail/models/res_user.py new file mode 100644 index 000000000000..137fdea22d91 --- /dev/null +++ b/hr_employee_birthday_mail/models/res_user.py @@ -0,0 +1,26 @@ +# Copyright 2023 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models, fields + + +class User(models.Model): + _inherit = ['res.users'] + + allow_birthday_wishes = fields.Boolean( + related='employee_id.allow_birthday_wishes', readonly=False, related_sudo=False + ) + notify_others_birthday = fields.Boolean( + related='employee_id.notify_others_birthday', readonly=False, related_sudo=False + ) + + def __init__(self, pool, cr): + """ Override of __init__ to add access rights. + Access rights are disabled by default, but allowed + on some specific fields defined in self.SELF_{READ/WRITE}ABLE_FIELDS. + """ + init_res = super(User, self).__init__(pool, cr) + # duplicate list to avoid modifying the original reference + type(self).SELF_READABLE_FIELDS = type(self).SELF_READABLE_FIELDS + ['allow_birthday_wishes', 'notify_others_birthday'] + type(self).SELF_WRITEABLE_FIELDS = type(self).SELF_WRITEABLE_FIELDS + ['allow_birthday_wishes', 'notify_others_birthday'] + return init_res diff --git a/hr_employee_birthday_mail/views/res_user_views.xml b/hr_employee_birthday_mail/views/res_user_views.xml new file mode 100644 index 000000000000..c758c8c9192e --- /dev/null +++ b/hr_employee_birthday_mail/views/res_user_views.xml @@ -0,0 +1,16 @@ + + + + + res.users.birthday.mail.inherit + res.users + + + + + + + + + +