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 Jun 29, 2023
1 parent 6a306f1 commit c288114
Show file tree
Hide file tree
Showing 13 changed files with 759 additions and 0 deletions.
82 changes: 82 additions & 0 deletions hr_announcement/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
============
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 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
106 changes: 106 additions & 0 deletions hr_announcement/models/announcement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# 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",
relation="hr_employee_announcements",
column1="announcement",
column2="employee",
string="Employees",
)
department_ids = fields.Many2many(
comodel_name="hr.department",
relation="hr_department_announcements",
column1="announcement",
column2="department",
string="Departments",
)
position_ids = fields.Many2many(
comodel_name="hr.job",
relation="hr_job_position_announcements",
column1="announcement",
column2="job_position",
string="Job Positions",
)

@api.depends(
"specific_user_ids",
"user_group_ids",
"employee_ids",
"department_ids",
"position_ids",
)
def _compute_allowed_user_ids(self):
res = super()._compute_allowed_user_ids()
for announcement in self.filtered(
lambda a: a.announcement_type in ["employee", "department", "job_position"]
):
if announcement.announcement_type == "employee":
announcement.allowed_user_ids = announcement.employee_ids.mapped(
"user_id"
)
announcement.allowed_users_count = len(
announcement.employee_ids.mapped("user_id")
)
elif announcement.announcement_type == "department":
announcement.allowed_user_ids = (
announcement.department_ids.member_ids.mapped("user_id")
)
announcement.allowed_users_count = len(
announcement.department_ids.member_ids.mapped("user_id")
)
elif announcement.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
82 changes: 82 additions & 0 deletions hr_announcement/models/res_users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# 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()
employee_announcements = self.env["announcement"].search_read(
[
("announcement_type", "=", "employee"),
("in_date", "=", True),
("id", "not in", self.env.user.read_announcement_ids.ids),
],
["employee_ids"],
)
announcements = self.env["announcement"].browse(
[
announcement["id"]
for announcement in employee_announcements
if announcement["employee_ids"]
and any(
id in self.env["hr.employee"].search([("user_id", "!=", False)]).ids
for id in announcement["employee_ids"]
)
]
)
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"],
)
departments_with_members = self.env["hr.department"].search(
[("member_ids.user_id", "!=", False)]
)
announcements += self.env["announcement"].browse(
[
announcement["id"]
for announcement in department_announcements
if any(
department_id in departments_with_members.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"],
)
jobs_with_employees = self.env["hr.job"].search(
[("employee_ids.user_id", "!=", False)]
)
announcements += self.env["announcement"].browse(
[
announcement["id"]
for announcement in position_announcements
if any(
position_id in jobs_with_employees.ids
for position_id in announcement["position_ids"]
)
]
)

return super().announcement_user_count() + [
{
"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.
1 change: 1 addition & 0 deletions hr_announcement/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
To learn about the usage of this module, please refer to the announcement module.
Loading

0 comments on commit c288114

Please sign in to comment.