diff --git a/hr_holidays_validator_list/README.rst b/hr_holidays_validator_list/README.rst new file mode 100644 index 00000000..0277475d --- /dev/null +++ b/hr_holidays_validator_list/README.rst @@ -0,0 +1,90 @@ +========================== +HR Holidays validator list +========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:d3681d99c40d44ab5566861f6d2f9988670c370100d09af8923fea8d3251791b + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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--holidays-lightgray.png?logo=github + :target: https://github.com/OCA/hr-holidays/tree/14.0/hr_holidays_validator_list + :alt: OCA/hr-holidays +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/hr-holidays-14-0/hr-holidays-14-0-hr_holidays_validator_list + :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-holidays&target_branch=14.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows for an employee to have several leave validators. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +For adding multiple : + +#. Go to the menu *Employee > Field leave_manager_ids*. +#. Add managers in the new many2many field. +#. The validation type of the hr.leave should be "manager". + +Other changes: + +#. The "People I manage" filter in hr.leave and hr.leave.allocation have been + updated accordingly + +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 +~~~~~~~ + +* Victor Vermot + +Contributors +~~~~~~~~~~~~ + +* Victor Vermot-Petit-Outhenin + +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-holidays `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/hr_holidays_validator_list/__init__.py b/hr_holidays_validator_list/__init__.py new file mode 100644 index 00000000..0ee8b507 --- /dev/null +++ b/hr_holidays_validator_list/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import tests diff --git a/hr_holidays_validator_list/__manifest__.py b/hr_holidays_validator_list/__manifest__.py new file mode 100644 index 00000000..213ba4a2 --- /dev/null +++ b/hr_holidays_validator_list/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2023 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +{ + "name": "HR Holidays validator list", + "summary": "Allow to add several leave validators", + "author": "Victor Vermot, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/hr-holidays", + "category": "Human Resources", + "version": "14.0.1.0.0", + "license": "AGPL-3", + "depends": ["hr_holidays"], + "data": [ + "views/hr_views.xml", + "views/hr_leave_allocation_views.xml", + "views/hr_leave_views.xml", + ], + "installable": True, +} diff --git a/hr_holidays_validator_list/i18n/fr.po b/hr_holidays_validator_list/i18n/fr.po new file mode 100644 index 00000000..f8d5e053 --- /dev/null +++ b/hr_holidays_validator_list/i18n/fr.po @@ -0,0 +1,62 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_holidays_validator_list +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-11-07 10:12+0000\n" +"PO-Revision-Date: 2023-11-07 10:12+0000\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_holidays_validator_list +#: model:ir.model,name:hr_holidays_validator_list.model_hr_employee_base +msgid "Basic Employee" +msgstr "Employé basique" + +#. module: hr_holidays_validator_list +#: model:ir.model.fields,field_description:hr_holidays_validator_list.field_hr_employee_base__display_name +#: model:ir.model.fields,field_description:hr_holidays_validator_list.field_hr_leave_allocation__display_name +msgid "Display Name" +msgstr "Nom affiché" + +#. module: hr_holidays_validator_list +#: model:ir.model.fields,field_description:hr_holidays_validator_list.field_hr_employee_base__id +#: model:ir.model.fields,field_description:hr_holidays_validator_list.field_hr_leave_allocation__id +msgid "ID" +msgstr "ID" + +#. module: hr_holidays_validator_list +#: model:ir.model.fields,field_description:hr_holidays_validator_list.field_hr_employee_base____last_update +#: model:ir.model.fields,field_description:hr_holidays_validator_list.field_hr_leave_allocation____last_update +msgid "Last Modified on" +msgstr "Dernière modification le" + +#. module: hr_holidays_validator_list +#: model:ir.model.fields,help:hr_holidays_validator_list.field_hr_employee__leave_manager_ids +#: model:ir.model.fields,help:hr_holidays_validator_list.field_hr_employee_base__leave_manager_ids +#: model:ir.model.fields,help:hr_holidays_validator_list.field_hr_employee_public__leave_manager_ids +msgid "" +"Select the users responsible for approving \"Time Off\" of this employee.\n" +"If empty, the approval is done by an Administrator or Approver (determined in settings/users)." +msgstr "" +"Sélectionne le user responsable for approuvé les congés de l'employé.\n" +"Si vide, la validation est faite par un adiministrateur ou approuveur (comme configuré dans paramètres/utilisateurs)" + +#. module: hr_holidays_validator_list +#: model:ir.model,name:hr_holidays_validator_list.model_hr_leave_allocation +msgid "Time Off Allocation" +msgstr "Allocation de congés" + +#. module: hr_holidays_validator_list +#: model:ir.model.fields,field_description:hr_holidays_validator_list.field_hr_employee__leave_manager_ids +#: model:ir.model.fields,field_description:hr_holidays_validator_list.field_hr_employee_base__leave_manager_ids +#: model:ir.model.fields,field_description:hr_holidays_validator_list.field_hr_employee_public__leave_manager_ids +msgid "Time Off Managers" +msgstr "Managers de congés" diff --git a/hr_holidays_validator_list/i18n/hr_holidays_validator_list.pot b/hr_holidays_validator_list/i18n/hr_holidays_validator_list.pot new file mode 100644 index 00000000..a8a6c2b2 --- /dev/null +++ b/hr_holidays_validator_list/i18n/hr_holidays_validator_list.pot @@ -0,0 +1,60 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_holidays_validator_list +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-11-07 10:12+0000\n" +"PO-Revision-Date: 2023-11-07 10:12+0000\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_holidays_validator_list +#: model:ir.model,name:hr_holidays_validator_list.model_hr_employee_base +msgid "Basic Employee" +msgstr "" + +#. module: hr_holidays_validator_list +#: model:ir.model.fields,field_description:hr_holidays_validator_list.field_hr_employee_base__display_name +#: model:ir.model.fields,field_description:hr_holidays_validator_list.field_hr_leave_allocation__display_name +msgid "Display Name" +msgstr "" + +#. module: hr_holidays_validator_list +#: model:ir.model.fields,field_description:hr_holidays_validator_list.field_hr_employee_base__id +#: model:ir.model.fields,field_description:hr_holidays_validator_list.field_hr_leave_allocation__id +msgid "ID" +msgstr "" + +#. module: hr_holidays_validator_list +#: model:ir.model.fields,field_description:hr_holidays_validator_list.field_hr_employee_base____last_update +#: model:ir.model.fields,field_description:hr_holidays_validator_list.field_hr_leave_allocation____last_update +msgid "Last Modified on" +msgstr "" + +#. module: hr_holidays_validator_list +#: model:ir.model.fields,help:hr_holidays_validator_list.field_hr_employee__leave_manager_ids +#: model:ir.model.fields,help:hr_holidays_validator_list.field_hr_employee_base__leave_manager_ids +#: model:ir.model.fields,help:hr_holidays_validator_list.field_hr_employee_public__leave_manager_ids +msgid "" +"Select the users responsible for approving \"Time Off\" of this employee.\n" +"If empty, the approval is done by an Administrator or Approver (determined in settings/users)." +msgstr "" + +#. module: hr_holidays_validator_list +#: model:ir.model,name:hr_holidays_validator_list.model_hr_leave_allocation +msgid "Time Off Allocation" +msgstr "" + +#. module: hr_holidays_validator_list +#: model:ir.model.fields,field_description:hr_holidays_validator_list.field_hr_employee__leave_manager_ids +#: model:ir.model.fields,field_description:hr_holidays_validator_list.field_hr_employee_base__leave_manager_ids +#: model:ir.model.fields,field_description:hr_holidays_validator_list.field_hr_employee_public__leave_manager_ids +msgid "Time Off Managers" +msgstr "" diff --git a/hr_holidays_validator_list/models/__init__.py b/hr_holidays_validator_list/models/__init__.py new file mode 100644 index 00000000..c4ac7c36 --- /dev/null +++ b/hr_holidays_validator_list/models/__init__.py @@ -0,0 +1,2 @@ +from . import hr_employee +from . import hr_leave diff --git a/hr_holidays_validator_list/models/hr_employee.py b/hr_holidays_validator_list/models/hr_employee.py new file mode 100644 index 00000000..09a06da3 --- /dev/null +++ b/hr_holidays_validator_list/models/hr_employee.py @@ -0,0 +1,46 @@ +# Copyright 2023 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +from odoo import api, fields, models + + +class HrEmployeeBase(models.AbstractModel): + _inherit = "hr.employee.base" + + leave_manager_ids = fields.Many2many( + "res.users", + string="Time Off Managers", + store=True, + readonly=False, + help="""Select the users responsible for approving 'Time Off' of this employee. + If empty, the approval is done by an Administrator + or Approver (determined in settings/users).""", + ) + + @api.depends("parent_id", "leave_manager_ids") + def _compute_leave_manager(self): + + for employee in self: + if employee.leave_manager_ids: + employee.leave_manager_id = employee.leave_manager_ids[0] + else: + super()._compute_leave_manager() + + def _add_leave_manager_ids_in_group(self, values): + if "leave_manager_ids" in values: + approver_group = self.env.ref( + "hr_holidays.group_hr_holidays_responsible", raise_if_not_found=False + ) + for manager_id in values["leave_manager_ids"][0][-1]: + if approver_group: + approver_group.sudo().write({"users": [(4, manager_id)]}) + + def create(self, values): + res = super().create(values) + self._add_leave_manager_ids_in_group(values) + return res + + def write(self, values): + res = super().write(values) + self._add_leave_manager_ids_in_group(values) + return res diff --git a/hr_holidays_validator_list/models/hr_leave.py b/hr_holidays_validator_list/models/hr_leave.py new file mode 100644 index 00000000..7c9aa0a4 --- /dev/null +++ b/hr_holidays_validator_list/models/hr_leave.py @@ -0,0 +1,35 @@ +# Copyright 2023 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +from odoo import models + + +class HolidaysLeave(models.Model): + """Allocation Requests Access specifications: similar to leave requests""" + + _inherit = "hr.leave" + + def activity_update(self): + """Updates activity for all leave_manager_ids""" + if not self.employee_id.leave_manager_ids or self.env.context.get( + "no_leave_manager_ids_trigger" + ): + super().activity_update() + else: + for manager in self.employee_id.leave_manager_ids: + self.employee_id.sudo().leave_manager_id = manager + super().activity_update() + self.employee_id.sudo().leave_manager_id = False + + def _check_approval_update(self, state): + """Checks that the leave manager is in leave_manager_ids""" + if not self.employee_id.leave_manager_ids or self.env.context.get( + "no_leave_manager_ids_trigger" + ): + super()._check_approval_update(state) + else: + for manager in self.employee_id.leave_manager_ids: + if manager == self.env.user: + self.employee_id.sudo().leave_manager_id = manager.id + super()._check_approval_update(state) + self.employee_id.sudo().leave_manager_id = False diff --git a/hr_holidays_validator_list/readme/CONTRIBUTORS.rst b/hr_holidays_validator_list/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..5deff8bc --- /dev/null +++ b/hr_holidays_validator_list/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Victor Vermot-Petit-Outhenin diff --git a/hr_holidays_validator_list/readme/DESCRIPTION.rst b/hr_holidays_validator_list/readme/DESCRIPTION.rst new file mode 100644 index 00000000..eb26ae96 --- /dev/null +++ b/hr_holidays_validator_list/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module allows for an employee to have several leave validators. diff --git a/hr_holidays_validator_list/readme/USAGE.rst b/hr_holidays_validator_list/readme/USAGE.rst new file mode 100644 index 00000000..42f77afd --- /dev/null +++ b/hr_holidays_validator_list/readme/USAGE.rst @@ -0,0 +1,10 @@ +For adding multiple : + +#. Go to the menu *Employee > Field leave_manager_ids*. +#. Add managers in the new many2many field. +#. The validation type of the hr.leave should be "manager". + +Other changes: + +#. The "People I manage" filter in hr.leave and hr.leave.allocation have been + updated accordingly diff --git a/hr_holidays_validator_list/tests/__init__.py b/hr_holidays_validator_list/tests/__init__.py new file mode 100644 index 00000000..4752aaf0 --- /dev/null +++ b/hr_holidays_validator_list/tests/__init__.py @@ -0,0 +1 @@ +from . import test_hr_leave diff --git a/hr_holidays_validator_list/tests/test_hr_leave.py b/hr_holidays_validator_list/tests/test_hr_leave.py new file mode 100644 index 00000000..587e2dc7 --- /dev/null +++ b/hr_holidays_validator_list/tests/test_hr_leave.py @@ -0,0 +1,66 @@ +# Copyright 2023 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) + +from datetime import datetime + +import odoo.tests.common as common +from odoo.exceptions import UserError + + +class TestHrLeave(common.TransactionCase): + def setUp(self): + super().setUp() + employee = self.env["hr.employee"].search([])[0] + employee.write({"leave_manager_ids": [(6, 0, [6, 2])]}) + hr_leave_type = self.env["hr.leave.type"].create( + { + "name": "Leave Test", + "color_name": "red", + "request_unit": "hour", + } + ) + self.hr_leave = self.env["hr.leave"].create( + { + "employee_id": employee.id, + "holiday_status_id": hr_leave_type.id, + "holiday_type": "employee", + "date_from": datetime(year=2023, month=10, day=1, hour=8, minute=0), + "date_to": datetime(year=2023, month=10, day=3, hour=8, minute=0), + } + ) + + self.user1 = self.env["res.users"].create( + { + "name": "User 1", + "login": "user1", + "password": "password1", + "groups_id": [], + } + ) + + def test_hr_leave_managers_can_validate_leaves(self): + """Test that checks if all leave managers in field leave_manager_ids can + confirm a hr_leave and hr_leave_allocations""" + self.env.user = self.env["res.users"].browse(6) + self.hr_leave.with_user(self.env.user).action_validate() + self.assertEqual(self.hr_leave.state, "validate") + self.hr_leave.state = "confirm" + self.env.user = self.env["res.users"].browse(2) + self.hr_leave.with_user(self.env.user).action_validate() + self.assertEqual(self.hr_leave.state, "validate") + self.hr_leave.state = "confirm" + + # remove user with id 2 from manager groups + approver_group = self.env.ref( + "hr_holidays.group_hr_holidays_manager", raise_if_not_found=False + ) + other_group = self.env.ref( + "hr_holidays.group_hr_holidays_user", raise_if_not_found=False + ) + if approver_group: + approver_group.sudo().write({"users": [(3, 2)]}) + other_group.sudo().write({"users": [(3, 2)]}) + + # checks that trying to validate leaves with no rights raises an error + with self.assertRaises(UserError): + self.hr_leave.with_user(self.user1)._check_approval_update("validate") diff --git a/hr_holidays_validator_list/views/hr_leave_allocation_views.xml b/hr_holidays_validator_list/views/hr_leave_allocation_views.xml new file mode 100644 index 00000000..f9c0dd2a --- /dev/null +++ b/hr_holidays_validator_list/views/hr_leave_allocation_views.xml @@ -0,0 +1,17 @@ + + + + hr.holidays.filter_allocations.inherited + hr.leave.allocation + + + + + [('employee_id.leave_manager_ids', 'in', [uid])] + + + + + diff --git a/hr_holidays_validator_list/views/hr_leave_views.xml b/hr_holidays_validator_list/views/hr_leave_views.xml new file mode 100644 index 00000000..0533bac6 --- /dev/null +++ b/hr_holidays_validator_list/views/hr_leave_views.xml @@ -0,0 +1,17 @@ + + + + hr.holidays.hr_leave.inherited + hr.leave + + + + + [('employee_id.leave_manager_ids', 'in', [uid])] + + + + + diff --git a/hr_holidays_validator_list/views/hr_views.xml b/hr_holidays_validator_list/views/hr_views.xml new file mode 100644 index 00000000..16da68a8 --- /dev/null +++ b/hr_holidays_validator_list/views/hr_views.xml @@ -0,0 +1,33 @@ + + + + hr.employee.leave.form.inherit + hr.employee + + + + 1 + + + + + + + + + + hr.employee.tree.leave + hr.employee + + + + 1 + + + + + + + + + diff --git a/setup/hr_holidays_validator_list/odoo/addons/hr_holidays_validator_list b/setup/hr_holidays_validator_list/odoo/addons/hr_holidays_validator_list new file mode 120000 index 00000000..c73ec829 --- /dev/null +++ b/setup/hr_holidays_validator_list/odoo/addons/hr_holidays_validator_list @@ -0,0 +1 @@ +../../../../hr_holidays_validator_list \ No newline at end of file diff --git a/setup/hr_holidays_validator_list/setup.py b/setup/hr_holidays_validator_list/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/hr_holidays_validator_list/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)