From 0e713a597df2576cd523ecae29dcfd60d84fdc20 Mon Sep 17 00:00:00 2001 From: pilarvargas-tecnativa Date: Thu, 29 Jun 2023 11:42:00 +0200 Subject: [PATCH] [ADD] hr_announcement: New module TT42581 --- hr_announcement/README.rst | 95 ++++ hr_announcement/__init__.py | 1 + hr_announcement/__manifest__.py | 15 + hr_announcement/models/__init__.py | 1 + hr_announcement/models/announcement.py | 107 +++++ hr_announcement/models/res_users.py | 62 +++ hr_announcement/readme/CONTRIBUTORS.rst | 3 + hr_announcement/readme/DESCRIPTION.rst | 3 + hr_announcement/readme/USAGE.rst | 14 + hr_announcement/static/description/index.html | 438 ++++++++++++++++++ hr_announcement/views/announcement_views.xml | 29 ++ .../odoo/addons/hr_announcement | 1 + setup/hr_announcement/setup.py | 6 + 13 files changed, 775 insertions(+) create mode 100644 hr_announcement/README.rst create mode 100644 hr_announcement/__init__.py create mode 100644 hr_announcement/__manifest__.py create mode 100644 hr_announcement/models/__init__.py create mode 100644 hr_announcement/models/announcement.py create mode 100644 hr_announcement/models/res_users.py create mode 100644 hr_announcement/readme/CONTRIBUTORS.rst create mode 100644 hr_announcement/readme/DESCRIPTION.rst create mode 100644 hr_announcement/readme/USAGE.rst create mode 100644 hr_announcement/static/description/index.html create mode 100644 hr_announcement/views/announcement_views.xml create mode 120000 setup/hr_announcement/odoo/addons/hr_announcement create mode 100644 setup/hr_announcement/setup.py diff --git a/hr_announcement/README.rst b/hr_announcement/README.rst new file mode 100644 index 000000000000..126656b5edbd --- /dev/null +++ b/hr_announcement/README.rst @@ -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 `_. +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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Tecnativa + +Contributors +~~~~~~~~~~~~ + +* `Tecnativa `__: + + * 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 `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/hr_announcement/__init__.py b/hr_announcement/__init__.py new file mode 100644 index 000000000000..0650744f6bc6 --- /dev/null +++ b/hr_announcement/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/hr_announcement/__manifest__.py b/hr_announcement/__manifest__.py new file mode 100644 index 000000000000..ee530ee69e82 --- /dev/null +++ b/hr_announcement/__manifest__.py @@ -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", + ], +} diff --git a/hr_announcement/models/__init__.py b/hr_announcement/models/__init__.py new file mode 100644 index 000000000000..340be8514f4b --- /dev/null +++ b/hr_announcement/models/__init__.py @@ -0,0 +1 @@ +from . import announcement, res_users diff --git a/hr_announcement/models/announcement.py b/hr_announcement/models/announcement.py new file mode 100644 index 000000000000..e294d40946a9 --- /dev/null +++ b/hr_announcement/models/announcement.py @@ -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 diff --git a/hr_announcement/models/res_users.py b/hr_announcement/models/res_users.py new file mode 100644 index 000000000000..3b9739f4a28a --- /dev/null +++ b/hr_announcement/models/res_users.py @@ -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) + ] diff --git a/hr_announcement/readme/CONTRIBUTORS.rst b/hr_announcement/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000000..27a339c31b0c --- /dev/null +++ b/hr_announcement/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Tecnativa `__: + + * Pilar Vargas diff --git a/hr_announcement/readme/DESCRIPTION.rst b/hr_announcement/readme/DESCRIPTION.rst new file mode 100644 index 000000000000..ef74d8f03986 --- /dev/null +++ b/hr_announcement/readme/DESCRIPTION.rst @@ -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. diff --git a/hr_announcement/readme/USAGE.rst b/hr_announcement/readme/USAGE.rst new file mode 100644 index 000000000000..302ac326fb48 --- /dev/null +++ b/hr_announcement/readme/USAGE.rst @@ -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. diff --git a/hr_announcement/static/description/index.html b/hr_announcement/static/description/index.html new file mode 100644 index 000000000000..63766779d971 --- /dev/null +++ b/hr_announcement/static/description/index.html @@ -0,0 +1,438 @@ + + + + + + +Announcement + + + +
+

Announcement

+ + +

Beta License: AGPL-3 OCA/hr Translate me on Weblate Try me on Runboat

+

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

+ +
+

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. +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.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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 project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/hr_announcement/views/announcement_views.xml b/hr_announcement/views/announcement_views.xml new file mode 100644 index 000000000000..fc4643837574 --- /dev/null +++ b/hr_announcement/views/announcement_views.xml @@ -0,0 +1,29 @@ + + + + announcement + + + + + + + + + + diff --git a/setup/hr_announcement/odoo/addons/hr_announcement b/setup/hr_announcement/odoo/addons/hr_announcement new file mode 120000 index 000000000000..d06c0499e856 --- /dev/null +++ b/setup/hr_announcement/odoo/addons/hr_announcement @@ -0,0 +1 @@ +../../../../hr_announcement \ No newline at end of file diff --git a/setup/hr_announcement/setup.py b/setup/hr_announcement/setup.py new file mode 100644 index 000000000000..28c57bb64031 --- /dev/null +++ b/setup/hr_announcement/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)