Skip to content

Commit

Permalink
[FIX] hr_employee_birthay_mail: res_users configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
JoanSForgeFlow committed Jul 10, 2023
1 parent a3b2131 commit 3fdddda
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 1 deletion.
7 changes: 6 additions & 1 deletion hr_employee_birthday_mail/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions hr_employee_birthday_mail/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import hr_employee
from . import res_user
2 changes: 2 additions & 0 deletions hr_employee_birthday_mail/models/hr_employee.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions hr_employee_birthday_mail/models/res_user.py
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions hr_employee_birthday_mail/views/res_user_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<data>
<record id="res_users_birthday_mail_inherit" model="ir.ui.view">
<field name="name">res.users.birthday.mail.inherit</field>
<field name="model">res.users</field>
<field name="inherit_id" ref="hr.res_users_view_form_profile"/>
<field name="arch" type="xml">
<field name="birthday" position="after">
<field name="allow_birthday_wishes" attrs="{'readonly': [('can_edit', '=', False)]}"/>
<field name="notify_others_birthday" attrs="{'readonly': [('can_edit', '=', False)], 'invisible': [('allow_birthday_wishes', '=', False)]}"/>
</field>
</field>
</record>
</data>
</odoo>

0 comments on commit 3fdddda

Please sign in to comment.