-
-
Notifications
You must be signed in to change notification settings - Fork 670
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
13 changed files
with
793 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
============ | ||
Announcement | ||
============ | ||
|
||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png | ||
:target: https://odoo-community.org/page/development-status | ||
:alt: Beta | ||
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png | ||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fhr-lightgray.png?logo=github | ||
:target: https://github.com/OCA/hr/tree/15.0/hr_announcement | ||
:alt: OCA/hr | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/hr-15-0/hr-15-0-hr_announcement | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png | ||
:target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/hr&target_branch=15.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
The hr_announcement module extends the announcement module by adding 3 new options to | ||
the announcement type. This module allows the creation and management of announcements, | ||
which can be sent to employees, departments, or job positions. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Usage | ||
===== | ||
|
||
To create an announcement: | ||
|
||
Users with ad management and configuration permissions can go to | ||
*Discussion > Announcements* to create or edit an announcement. | ||
In the announcement form you can see the new `Employee/Departmen/Job Position` | ||
options included in the *Announcement type* field. | ||
|
||
To check the announcements: | ||
|
||
When users associated with an employee, department or job position log in, | ||
announcement notices will appear. They can also check current or past | ||
announcements under *Discussion > Announcements*. | ||
|
||
To learn about the usage of this module, please refer to the announcement module. | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/hr/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us smashing it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/hr/issues/new?body=module:%20hr_announcement%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
Do not contact contributors directly about support or help with technical issues. | ||
|
||
Credits | ||
======= | ||
|
||
Authors | ||
~~~~~~~ | ||
|
||
* Tecnativa | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* `Tecnativa <https://www.tecnativa.com>`__: | ||
|
||
* Pilar Vargas | ||
|
||
Maintainers | ||
~~~~~~~~~~~ | ||
|
||
This module is maintained by the OCA. | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
|
||
OCA, or the Odoo Community Association, is a nonprofit organization whose | ||
mission is to support the collaborative development of Odoo features and | ||
promote its widespread use. | ||
|
||
This module is part of the `OCA/hr <https://github.com/OCA/hr/tree/15.0/hr_announcement>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Copyright 2023 Tecnativa - Pilar Vargas | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
{ | ||
"name": "Announcement", | ||
"version": "15.0.1.0.0", | ||
"summary": "", | ||
"author": "Tecnativa, Odoo Community Association (OCA)", | ||
"license": "AGPL-3", | ||
"category": "Server UX", | ||
"website": "https://github.com/OCA/hr", | ||
"depends": ["mail", "hr", "announcement"], | ||
"data": [ | ||
"views/announcement_views.xml", | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import announcement | ||
from . import res_users |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
# Copyright 2023 Tecnativa - Pilar Vargas | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from odoo import api, fields, models | ||
|
||
|
||
class Announcement(models.Model): | ||
_inherit = "announcement" | ||
|
||
announcement_type = fields.Selection( | ||
selection_add=[ | ||
("employee", "Employee"), | ||
("department", "Department"), | ||
("job_position", "Job Position"), | ||
], | ||
ondelete={ | ||
"employee": "set default", | ||
"department": "set default", | ||
"job_position": "set default", | ||
}, | ||
) | ||
employee_ids = fields.Many2many( | ||
comodel_name="hr.employee", | ||
string="Employees", | ||
) | ||
department_ids = fields.Many2many( | ||
comodel_name="hr.department", | ||
string="Departments", | ||
) | ||
position_ids = fields.Many2many( | ||
comodel_name="hr.job", | ||
string="Job Positions", | ||
) | ||
|
||
def _update_read_unread_announcements(self): | ||
"""Used to set users unread announcements when they're set in the announcement | ||
itself""" | ||
for announcement in self: | ||
for employee in announcement.employee_ids.filtered( | ||
lambda x: x.user_id | ||
and announcement | ||
not in ( | ||
x.user_id.read_announcement_ids + x.user_id.unread_announcement_ids | ||
) | ||
): | ||
employee.user_id.unread_announcement_ids |= announcement | ||
|
||
@api.model | ||
def create(self, vals): | ||
announcement = super().create(vals) | ||
if vals.get("employee_ids"): | ||
announcement._update_read_unread_announcements() | ||
return announcement | ||
|
||
def write(self, vals): | ||
res = super().write(vals) | ||
if vals.get("employee_ids"): | ||
self._update_read_unread_announcements() | ||
return res | ||
|
||
@api.depends( | ||
"specific_user_ids", | ||
"user_group_ids", | ||
"employee_ids", | ||
"department_ids", | ||
"position_ids", | ||
) | ||
def _compute_allowed_user_ids(self): | ||
excluded_announcement_types = self.filtered( | ||
lambda a: a.announcement_type in ["employee", "department", "job_position"] | ||
) | ||
res = super( | ||
Announcement, self - excluded_announcement_types | ||
)._compute_allowed_user_ids() | ||
for announcement in self.filtered(lambda a: a.announcement_type == "employee"): | ||
announcement.allowed_user_ids = announcement.employee_ids.user_id | ||
announcement.allowed_users_count = len(announcement.employee_ids.user_id) | ||
for announcement in self.filtered( | ||
lambda a: a.announcement_type == "department" | ||
): | ||
announcement.allowed_user_ids = ( | ||
announcement.department_ids.member_ids.user_id | ||
) | ||
announcement.allowed_users_count = len( | ||
announcement.department_ids.member_ids.user_id | ||
) | ||
for announcement in self.filtered( | ||
lambda a: a.announcement_type == "job_position" | ||
): | ||
announcement.allowed_user_ids = announcement.position_ids.mapped( | ||
"employee_ids.user_id" | ||
) | ||
announcement.allowed_users_count = len( | ||
announcement.position_ids.mapped("employee_ids.user_id") | ||
) | ||
return res | ||
|
||
@api.onchange("announcement_type") | ||
def _onchange_announcement_type(self): | ||
"""We want to reset the values on screen""" | ||
if self.announcement_type == "specific_users": | ||
self.user_group_ids = False | ||
self.employee_ids = False | ||
self.department_ids = False | ||
self.position_ids = False | ||
elif self.announcement_type == "user_group": | ||
self.specific_user_ids = False | ||
self.employee_ids = False | ||
self.department_ids = False | ||
self.position_ids = False | ||
elif self.announcement_type == "employee": | ||
self.user_group_ids = False | ||
self.specific_user_ids = False | ||
self.department_ids = False | ||
self.position_ids = False | ||
elif self.announcement_type == "department": | ||
self.user_group_ids = False | ||
self.specific_user_ids = False | ||
self.employee_ids = False | ||
self.position_ids = False | ||
elif self.announcement_type == "job_position": | ||
self.user_group_ids = False | ||
self.specific_user_ids = False | ||
self.employee_ids = False | ||
self.department_ids = False | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Copyright 2023 Tecnativa - Pilar Vargas | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from odoo import api, models | ||
|
||
|
||
class ResUsers(models.Model): | ||
_inherit = "res.users" | ||
|
||
@api.model | ||
def announcement_user_count(self): | ||
res = super().announcement_user_count() | ||
department_announcements = self.env["announcement"].search_read( | ||
[ | ||
("announcement_type", "=", "department"), | ||
("in_date", "=", True), | ||
("id", "not in", self.env.user.read_announcement_ids.ids), | ||
], | ||
["department_ids"], | ||
) | ||
announcements = self.env["announcement"].browse( | ||
[ | ||
announcement["id"] | ||
for announcement in department_announcements | ||
if any( | ||
department_id | ||
in self.env["hr.department"] | ||
.search([("member_ids.user_id", "!=", False)]) | ||
.ids | ||
for department_id in announcement["department_ids"] | ||
) | ||
] | ||
) | ||
|
||
position_announcements = self.env["announcement"].search_read( | ||
[ | ||
("announcement_type", "=", "job_position"), | ||
("in_date", "=", True), | ||
("id", "not in", self.env.user.read_announcement_ids.ids), | ||
], | ||
["position_ids"], | ||
) | ||
announcements += self.env["announcement"].browse( | ||
[ | ||
announcement["id"] | ||
for announcement in position_announcements | ||
if any( | ||
position_id | ||
in self.env["hr.job"] | ||
.search([("employee_ids.user_id", "!=", False)]) | ||
.ids | ||
for position_id in announcement["position_ids"] | ||
) | ||
] | ||
) | ||
return res + [ | ||
{ | ||
"id": announcement.id, | ||
"name": announcement.name, | ||
"content": announcement.content, | ||
} | ||
for announcement in announcements.sorted(lambda k: k.sequence) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
* `Tecnativa <https://www.tecnativa.com>`__: | ||
|
||
* Pilar Vargas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
The hr_announcement module extends the announcement module by adding 3 new options to | ||
the announcement type. This module allows the creation and management of announcements, | ||
which can be sent to employees, departments, or job positions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
To create an announcement: | ||
|
||
Users with ad management and configuration permissions can go to | ||
*Discussion > Announcements* to create or edit an announcement. | ||
In the announcement form you can see the new `Employee/Departmen/Job Position` | ||
options included in the *Announcement type* field. | ||
|
||
To check the announcements: | ||
|
||
When users associated with an employee, department or job position log in, | ||
announcement notices will appear. They can also check current or past | ||
announcements under *Discussion > Announcements*. | ||
|
||
To learn about the usage of this module, please refer to the announcement module. |
Oops, something went wrong.