Skip to content

Commit

Permalink
[ADD] hr_announcement: New module
Browse files Browse the repository at this point in the history
TT42581
  • Loading branch information
pilarvargas-tecnativa committed Jul 25, 2023
1 parent 6a306f1 commit 28a3e3a
Show file tree
Hide file tree
Showing 13 changed files with 792 additions and 0 deletions.
95 changes: 95 additions & 0 deletions hr_announcement/README.rst
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.
1 change: 1 addition & 0 deletions hr_announcement/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
15 changes: 15 additions & 0 deletions hr_announcement/__manifest__.py
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",
],
}
2 changes: 2 additions & 0 deletions hr_announcement/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import announcement
from . import res_users
123 changes: 123 additions & 0 deletions hr_announcement/models/announcement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# 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

Check warning on line 45 in hr_announcement/models/announcement.py

View check run for this annotation

Codecov / codecov/patch

hr_announcement/models/announcement.py#L45

Added line #L45 was not covered by tests

@api.model
def create(self, vals):
announcement = super().create(vals)

Check warning on line 49 in hr_announcement/models/announcement.py

View check run for this annotation

Codecov / codecov/patch

hr_announcement/models/announcement.py#L49

Added line #L49 was not covered by tests
if vals.get("employee_ids"):
announcement._update_read_unread_announcements()
return announcement

Check warning on line 52 in hr_announcement/models/announcement.py

View check run for this annotation

Codecov / codecov/patch

hr_announcement/models/announcement.py#L51-L52

Added lines #L51 - L52 were not covered by tests

def write(self, vals):
res = super().write(vals)

Check warning on line 55 in hr_announcement/models/announcement.py

View check run for this annotation

Codecov / codecov/patch

hr_announcement/models/announcement.py#L55

Added line #L55 was not covered by tests
if vals.get("employee_ids"):
self._update_read_unread_announcements()
return res

Check warning on line 58 in hr_announcement/models/announcement.py

View check run for this annotation

Codecov / codecov/patch

hr_announcement/models/announcement.py#L57-L58

Added lines #L57 - L58 were not covered by tests

@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(

Check warning on line 71 in hr_announcement/models/announcement.py

View check run for this annotation

Codecov / codecov/patch

hr_announcement/models/announcement.py#L71

Added line #L71 was not covered by tests
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)

Check warning on line 76 in hr_announcement/models/announcement.py

View check run for this annotation

Codecov / codecov/patch

hr_announcement/models/announcement.py#L75-L76

Added lines #L75 - L76 were not covered by tests
for announcement in self.filtered(
lambda a: a.announcement_type == "department"
):
announcement.allowed_user_ids = (

Check warning on line 80 in hr_announcement/models/announcement.py

View check run for this annotation

Codecov / codecov/patch

hr_announcement/models/announcement.py#L80

Added line #L80 was not covered by tests
announcement.department_ids.member_ids.user_id
)
announcement.allowed_users_count = len(

Check warning on line 83 in hr_announcement/models/announcement.py

View check run for this annotation

Codecov / codecov/patch

hr_announcement/models/announcement.py#L83

Added line #L83 was not covered by tests
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(

Check warning on line 89 in hr_announcement/models/announcement.py

View check run for this annotation

Codecov / codecov/patch

hr_announcement/models/announcement.py#L89

Added line #L89 was not covered by tests
"employee_ids.user_id"
)
announcement.allowed_users_count = len(

Check warning on line 92 in hr_announcement/models/announcement.py

View check run for this annotation

Codecov / codecov/patch

hr_announcement/models/announcement.py#L92

Added line #L92 was not covered by tests
announcement.position_ids.mapped("employee_ids.user_id")
)
return res

Check warning on line 95 in hr_announcement/models/announcement.py

View check run for this annotation

Codecov / codecov/patch

hr_announcement/models/announcement.py#L95

Added line #L95 was not covered by tests

@api.onchange("announcement_type")
def _onchange_announcement_type(self):
res = super()._onchange_announcement_type()

Check warning on line 99 in hr_announcement/models/announcement.py

View check run for this annotation

Codecov / codecov/patch

hr_announcement/models/announcement.py#L99

Added line #L99 was not covered by tests
if self.announcement_type == "specific_users":
self.employee_ids = False
self.department_ids = False
self.position_ids = False

Check warning on line 103 in hr_announcement/models/announcement.py

View check run for this annotation

Codecov / codecov/patch

hr_announcement/models/announcement.py#L101-L103

Added lines #L101 - L103 were not covered by tests
elif self.announcement_type == "user_group":
self.employee_ids = False
self.department_ids = False
self.position_ids = False

Check warning on line 107 in hr_announcement/models/announcement.py

View check run for this annotation

Codecov / codecov/patch

hr_announcement/models/announcement.py#L105-L107

Added lines #L105 - L107 were not covered by tests
elif self.announcement_type == "employee":
self.user_group_ids = False
self.specific_user_ids = False
self.department_ids = False
self.position_ids = False

Check warning on line 112 in hr_announcement/models/announcement.py

View check run for this annotation

Codecov / codecov/patch

hr_announcement/models/announcement.py#L109-L112

Added lines #L109 - L112 were not covered by tests
elif self.announcement_type == "department":
self.user_group_ids = False
self.specific_user_ids = False
self.employee_ids = False
self.position_ids = False

Check warning on line 117 in hr_announcement/models/announcement.py

View check run for this annotation

Codecov / codecov/patch

hr_announcement/models/announcement.py#L114-L117

Added lines #L114 - L117 were not covered by tests
elif self.announcement_type == "job_position":
self.user_group_ids = False
self.specific_user_ids = False
self.employee_ids = False
self.department_ids = False
return res

Check warning on line 123 in hr_announcement/models/announcement.py

View check run for this annotation

Codecov / codecov/patch

hr_announcement/models/announcement.py#L119-L123

Added lines #L119 - L123 were not covered by tests
62 changes: 62 additions & 0 deletions hr_announcement/models/res_users.py
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(

Check warning on line 12 in hr_announcement/models/res_users.py

View check run for this annotation

Codecov / codecov/patch

hr_announcement/models/res_users.py#L11-L12

Added lines #L11 - L12 were not covered by tests
[
("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(

Check warning on line 34 in hr_announcement/models/res_users.py

View check run for this annotation

Codecov / codecov/patch

hr_announcement/models/res_users.py#L34

Added line #L34 was not covered by tests
[
("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)
]
3 changes: 3 additions & 0 deletions hr_announcement/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* `Tecnativa <https://www.tecnativa.com>`__:

* Pilar Vargas
3 changes: 3 additions & 0 deletions hr_announcement/readme/DESCRIPTION.rst
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.
14 changes: 14 additions & 0 deletions hr_announcement/readme/USAGE.rst
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.
Loading

0 comments on commit 28a3e3a

Please sign in to comment.