diff --git a/hr_announcement/README.rst b/hr_announcement/README.rst new file mode 100644 index 00000000000..97e9c011b89 --- /dev/null +++ b/hr_announcement/README.rst @@ -0,0 +1,101 @@ +============ +Announcement +============ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:9039171d476e33c87abb633b1edfd08292463842622a23e310c8e0e371a7730a + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/18.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-18-0/hr-18-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/builds?repo=OCA/hr&target_branch=18.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 to smash 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 + - Juan José Seguí + +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 00000000000..0650744f6bc --- /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 00000000000..c8daea6fae9 --- /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": "18.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/i18n/es.po b/hr_announcement/i18n/es.po new file mode 100644 index 00000000000..816d9a1ee18 --- /dev/null +++ b/hr_announcement/i18n/es.po @@ -0,0 +1,62 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_announcement +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-03-27 12:39+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: none\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: hr_announcement +#: model:ir.model.fields,field_description:hr_announcement.field_announcement__announcement_type +msgid "Announcement Type" +msgstr "Tipo de Anuncio" + +#. module: hr_announcement +#: model:ir.model.fields.selection,name:hr_announcement.selection__announcement__announcement_type__department +msgid "Department" +msgstr "Departamento" + +#. module: hr_announcement +#: model:ir.model.fields,field_description:hr_announcement.field_announcement__department_ids +msgid "Departments" +msgstr "Departamentos" + +#. module: hr_announcement +#: model:ir.model.fields.selection,name:hr_announcement.selection__announcement__announcement_type__employee +msgid "Employee" +msgstr "Empleado/a" + +#. module: hr_announcement +#: model:ir.model.fields,field_description:hr_announcement.field_announcement__employee_ids +msgid "Employees" +msgstr "Empleados" + +#. module: hr_announcement +#: model:ir.model.fields.selection,name:hr_announcement.selection__announcement__announcement_type__job_position +msgid "Job Position" +msgstr "Puesto de Trabajo" + +#. module: hr_announcement +#: model:ir.model.fields,field_description:hr_announcement.field_announcement__position_ids +msgid "Job Positions" +msgstr "Posiciones de Trabajo" + +#. module: hr_announcement +#: model:ir.model,name:hr_announcement.model_announcement +msgid "User announcements" +msgstr "Anuncios del usuario" + +#. module: hr_announcement +#: model:ir.model,name:hr_announcement.model_res_users +msgid "Users" +msgstr "Usuarios" diff --git a/hr_announcement/i18n/hr_announcement.pot b/hr_announcement/i18n/hr_announcement.pot new file mode 100644 index 00000000000..4efbe7ed8d9 --- /dev/null +++ b/hr_announcement/i18n/hr_announcement.pot @@ -0,0 +1,59 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_announcement +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: hr_announcement +#: model:ir.model.fields,field_description:hr_announcement.field_announcement__announcement_type +msgid "Announcement Type" +msgstr "" + +#. module: hr_announcement +#: model:ir.model.fields.selection,name:hr_announcement.selection__announcement__announcement_type__department +msgid "Department" +msgstr "" + +#. module: hr_announcement +#: model:ir.model.fields,field_description:hr_announcement.field_announcement__department_ids +msgid "Departments" +msgstr "" + +#. module: hr_announcement +#: model:ir.model.fields.selection,name:hr_announcement.selection__announcement__announcement_type__employee +msgid "Employee" +msgstr "" + +#. module: hr_announcement +#: model:ir.model.fields,field_description:hr_announcement.field_announcement__employee_ids +msgid "Employees" +msgstr "" + +#. module: hr_announcement +#: model:ir.model.fields.selection,name:hr_announcement.selection__announcement__announcement_type__job_position +msgid "Job Position" +msgstr "" + +#. module: hr_announcement +#: model:ir.model.fields,field_description:hr_announcement.field_announcement__position_ids +msgid "Job Positions" +msgstr "" + +#. module: hr_announcement +#: model:ir.model,name:hr_announcement.model_res_users +msgid "User" +msgstr "" + +#. module: hr_announcement +#: model:ir.model,name:hr_announcement.model_announcement +msgid "User announcements" +msgstr "" diff --git a/hr_announcement/i18n/it.po b/hr_announcement/i18n/it.po new file mode 100644 index 00000000000..2063c322704 --- /dev/null +++ b/hr_announcement/i18n/it.po @@ -0,0 +1,62 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_announcement +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-11-12 17:41+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: hr_announcement +#: model:ir.model.fields,field_description:hr_announcement.field_announcement__announcement_type +msgid "Announcement Type" +msgstr "Tipo comunicazione" + +#. module: hr_announcement +#: model:ir.model.fields.selection,name:hr_announcement.selection__announcement__announcement_type__department +msgid "Department" +msgstr "Reparto" + +#. module: hr_announcement +#: model:ir.model.fields,field_description:hr_announcement.field_announcement__department_ids +msgid "Departments" +msgstr "Reparti" + +#. module: hr_announcement +#: model:ir.model.fields.selection,name:hr_announcement.selection__announcement__announcement_type__employee +msgid "Employee" +msgstr "Dipendente" + +#. module: hr_announcement +#: model:ir.model.fields,field_description:hr_announcement.field_announcement__employee_ids +msgid "Employees" +msgstr "Dipendenti" + +#. module: hr_announcement +#: model:ir.model.fields.selection,name:hr_announcement.selection__announcement__announcement_type__job_position +msgid "Job Position" +msgstr "Posizione lavorativa" + +#. module: hr_announcement +#: model:ir.model.fields,field_description:hr_announcement.field_announcement__position_ids +msgid "Job Positions" +msgstr "Posizioni lavorative" + +#. module: hr_announcement +#: model:ir.model,name:hr_announcement.model_announcement +msgid "User announcements" +msgstr "Comunicazioni utenti" + +#. module: hr_announcement +#: model:ir.model,name:hr_announcement.model_res_users +msgid "Users" +msgstr "Utenti" diff --git a/hr_announcement/models/__init__.py b/hr_announcement/models/__init__.py new file mode 100644 index 00000000000..10bbbac2671 --- /dev/null +++ b/hr_announcement/models/__init__.py @@ -0,0 +1,2 @@ +from . import announcement +from . import res_users diff --git a/hr_announcement/models/announcement.py b/hr_announcement/models/announcement.py new file mode 100644 index 00000000000..e5357e7ff7c --- /dev/null +++ b/hr_announcement/models/announcement.py @@ -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, ann=announcement: x.user_id + and ann + not in ( + x.user_id.read_announcement_ids + x.user_id.unread_announcement_ids + ) + ): + employee.user_id.unread_announcement_ids |= announcement + + @api.model_create_multi + def create(self, vals_list): + announcements = super().create(vals_list) + if any(vals.get("employee_ids") for vals in vals_list): + announcements._update_read_unread_announcements() + return announcements + + 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): + res = super()._onchange_announcement_type() + if self.announcement_type == "specific_users": + self.employee_ids = False + self.department_ids = False + self.position_ids = False + elif self.announcement_type == "user_group": + 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 + return res diff --git a/hr_announcement/models/res_users.py b/hr_announcement/models/res_users.py new file mode 100644 index 00000000000..c3368558c48 --- /dev/null +++ b/hr_announcement/models/res_users.py @@ -0,0 +1,51 @@ +# 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() + + user = self.env.user + Announcement = self.env["announcement"] + + department_ids = user.employee_ids.mapped("department_id").ids + position_ids = user.employee_ids.mapped("job_id").ids + + base_domain = [ + ("in_date", "=", True), + ("id", "not in", user.read_announcement_ids.ids), + ] + + announcements = Announcement + + if department_ids: + announcements |= Announcement.search( + base_domain + + [ + ("announcement_type", "=", "department"), + ("department_ids", "in", department_ids), + ] + ) + + if position_ids: + announcements |= Announcement.search( + base_domain + + [ + ("announcement_type", "=", "job_position"), + ("position_ids", "in", position_ids), + ] + ) + + return res + [ + { + "id": announcement.id, + "name": announcement.name, + "content": announcement.content, + } + for announcement in announcements.sorted("sequence") + ] diff --git a/hr_announcement/pyproject.toml b/hr_announcement/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/hr_announcement/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/hr_announcement/readme/CONTRIBUTORS.md b/hr_announcement/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..150b2772da8 --- /dev/null +++ b/hr_announcement/readme/CONTRIBUTORS.md @@ -0,0 +1,3 @@ +- [Tecnativa](https://www.tecnativa.com): + - Pilar Vargas + - Juan José Seguí diff --git a/hr_announcement/readme/DESCRIPTION.md b/hr_announcement/readme/DESCRIPTION.md new file mode 100644 index 00000000000..75aa823ee10 --- /dev/null +++ b/hr_announcement/readme/DESCRIPTION.md @@ -0,0 +1,4 @@ +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.md b/hr_announcement/readme/USAGE.md new file mode 100644 index 00000000000..b4465861ea0 --- /dev/null +++ b/hr_announcement/readme/USAGE.md @@ -0,0 +1,15 @@ +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/icon.png b/hr_announcement/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/hr_announcement/static/description/icon.png differ diff --git a/hr_announcement/static/description/index.html b/hr_announcement/static/description/index.html new file mode 100644 index 00000000000..048a0067572 --- /dev/null +++ b/hr_announcement/static/description/index.html @@ -0,0 +1,445 @@ + + + + + +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 to smash 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
    • +
    • Juan José Seguí
    • +
    +
  • +
+
+
+

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/tests/__init__.py b/hr_announcement/tests/__init__.py new file mode 100644 index 00000000000..04d6c3df9b2 --- /dev/null +++ b/hr_announcement/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) + +from . import test_hr_announcement diff --git a/hr_announcement/tests/test_hr_announcement.py b/hr_announcement/tests/test_hr_announcement.py new file mode 100644 index 00000000000..c6b849a5a28 --- /dev/null +++ b/hr_announcement/tests/test_hr_announcement.py @@ -0,0 +1,279 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +# Copyright 2023 Tecnativa - Pilar Vargas + +from odoo.tests.common import TransactionCase + + +class TestHrAnnouncement(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + + cls.hr_department = cls.env["hr.department"].create({"name": "HR"}) + cls.sales_department = cls.env["hr.department"].create({"name": "Sales"}) + + cls.manager_job = cls.env["hr.job"].create({"name": "Manager"}) + cls.developer_job = cls.env["hr.job"].create({"name": "Developer"}) + + cls.user_a = ( + cls.env["res.users"] + .with_context(no_reset_password=True) + .create( + { + "name": "User A", + "login": "user_a", + "email": "user_a@example.com", + } + ) + ) + + cls.user_b = ( + cls.env["res.users"] + .with_context(no_reset_password=True) + .create( + { + "name": "User B", + "login": "user_b", + "email": "user_b@example.com", + } + ) + ) + + cls.user_c = ( + cls.env["res.users"] + .with_context(no_reset_password=True) + .create( + { + "name": "User C", + "login": "user_c", + "email": "user_c@example.com", + } + ) + ) + + cls.employee_a = cls.env["hr.employee"].create( + { + "name": "Employee A", + "user_id": cls.user_a.id, + "department_id": cls.hr_department.id, + "job_id": cls.manager_job.id, + } + ) + + cls.employee_b = cls.env["hr.employee"].create( + { + "name": "Employee B", + "user_id": cls.user_b.id, + "department_id": cls.hr_department.id, + "job_id": cls.developer_job.id, + } + ) + + cls.employee_c = cls.env["hr.employee"].create( + { + "name": "Employee C", + "user_id": cls.user_c.id, + "department_id": cls.sales_department.id, + "job_id": cls.developer_job.id, + } + ) + + def _announcement_ids_for_user(self, user): + result = user.with_user(user).announcement_user_count() + return {rec["id"] for rec in result if isinstance(rec, dict)} + + def test_employee_announcement_visibility(self): + announcement = self.env["announcement"].create( + { + "name": "Employee Announcement", + "announcement_type": "employee", + "employee_ids": [(6, 0, [self.employee_a.id])], + } + ) + + announcement._compute_allowed_user_ids() + + self.assertIn( + self.user_a, + announcement.allowed_user_ids, + ) + self.assertNotIn( + self.user_b, + announcement.allowed_user_ids, + ) + self.assertNotIn( + self.user_c, + announcement.allowed_user_ids, + ) + + def test_department_announcement_visibility(self): + announcement = self.env["announcement"].create( + { + "name": "Department Announcement", + "announcement_type": "department", + "department_ids": [(6, 0, [self.hr_department.id])], + } + ) + + announcement._compute_allowed_user_ids() + + self.assertIn( + self.user_a, + announcement.allowed_user_ids, + ) + self.assertIn( + self.user_b, + announcement.allowed_user_ids, + ) + self.assertNotIn( + self.user_c, + announcement.allowed_user_ids, + ) + + def test_job_position_announcement_visibility(self): + announcement = self.env["announcement"].create( + { + "name": "Developer Announcement", + "announcement_type": "job_position", + "position_ids": [(6, 0, [self.developer_job.id])], + } + ) + + announcement._compute_allowed_user_ids() + + self.assertNotIn( + self.user_a, + announcement.allowed_user_ids, + ) + self.assertIn( + self.user_b, + announcement.allowed_user_ids, + ) + self.assertIn( + self.user_c, + announcement.allowed_user_ids, + ) + + def test_employee_announcement_write_employee_ids(self): + announcement = self.env["announcement"].create( + { + "name": "Write Announcement", + "announcement_type": "employee", + } + ) + + announcement.write( + { + "employee_ids": [(6, 0, [self.employee_a.id])], + } + ) + + self.assertEqual( + announcement.employee_ids, + self.employee_a, + ) + + def test_department_announcement_user_count(self): + self.env["announcement"].create( + { + "name": "Department Count Announcement", + "announcement_type": "department", + "department_ids": [(6, 0, [self.hr_department.id])], + } + ) + + result = self.user_a.with_user(self.user_a).announcement_user_count() + + self.assertIsInstance(result, list) + + def test_job_position_announcement_user_count(self): + self.env["announcement"].create( + { + "name": "Job Count Announcement", + "announcement_type": "job_position", + "position_ids": [(6, 0, [self.developer_job.id])], + } + ) + + result = self.user_b.with_user(self.user_b).announcement_user_count() + + self.assertIsInstance(result, list) + + def test_onchange_specific_users(self): + announcement = self.env["announcement"].new( + { + "announcement_type": "specific_users", + } + ) + + announcement.employee_ids = self.employee_a + announcement.department_ids = self.hr_department + announcement.position_ids = self.developer_job + + announcement._onchange_announcement_type() + + self.assertFalse(announcement.employee_ids) + self.assertFalse(announcement.department_ids) + self.assertFalse(announcement.position_ids) + + def test_onchange_user_group(self): + announcement = self.env["announcement"].new( + { + "announcement_type": "user_group", + } + ) + + announcement.employee_ids = self.employee_a + announcement.department_ids = self.hr_department + announcement.position_ids = self.developer_job + + announcement._onchange_announcement_type() + + self.assertFalse(announcement.employee_ids) + self.assertFalse(announcement.department_ids) + self.assertFalse(announcement.position_ids) + + def test_onchange_employee(self): + announcement = self.env["announcement"].new( + { + "announcement_type": "employee", + } + ) + + announcement.department_ids = self.hr_department + announcement.position_ids = self.developer_job + + announcement._onchange_announcement_type() + + self.assertFalse(announcement.department_ids) + self.assertFalse(announcement.position_ids) + + def test_onchange_department(self): + announcement = self.env["announcement"].new( + { + "announcement_type": "department", + } + ) + + announcement.employee_ids = self.employee_a + announcement.position_ids = self.developer_job + + announcement._onchange_announcement_type() + + self.assertFalse(announcement.employee_ids) + self.assertFalse(announcement.position_ids) + + def test_onchange_job_position(self): + announcement = self.env["announcement"].new( + { + "announcement_type": "job_position", + } + ) + + announcement.employee_ids = self.employee_a + announcement.department_ids = self.hr_department + + announcement._onchange_announcement_type() + + self.assertFalse(announcement.employee_ids) + self.assertFalse(announcement.department_ids) diff --git a/hr_announcement/views/announcement_views.xml b/hr_announcement/views/announcement_views.xml new file mode 100644 index 00000000000..851c0f8b63a --- /dev/null +++ b/hr_announcement/views/announcement_views.xml @@ -0,0 +1,32 @@ + + + + announcement + + + + + + + + + +