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 10, 2023
1 parent 6a306f1 commit 0e713a5
Show file tree
Hide file tree
Showing 13 changed files with 775 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",
],
}
1 change: 1 addition & 0 deletions hr_announcement/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import announcement, res_users
107 changes: 107 additions & 0 deletions hr_announcement/models/announcement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# 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",
inverse="_inverse_employee_ids",
)
department_ids = fields.Many2many(
comodel_name="hr.department",
string="Departments",
)
position_ids = fields.Many2many(
comodel_name="hr.job",
string="Job Positions",
)

def _inverse_employee_ids(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.depends(
"specific_user_ids",
"user_group_ids",
"employee_ids",
"department_ids",
"position_ids",
)
def _compute_allowed_user_ids(self):
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 super()._compute_allowed_user_ids()

@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
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(
[
("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)
]
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 0e713a5

Please sign in to comment.