From e4662ed53ada37b3080826925087914425591e9f Mon Sep 17 00:00:00 2001 From: victorvermot Date: Tue, 7 Nov 2023 11:36:41 +0100 Subject: [PATCH] fix: pre-commit corrections --- .../models/hr_employee.py | 29 ++++++++++--------- .../models/hr_leave_allocation.py | 14 ++++----- .../readme/DESCRIPTION.rst | 2 +- hr_holidays_validator_list/readme/USAGE.rst | 2 +- .../tests/test_hr_leave.py | 29 ++++++++++--------- .../views/hr_leave_allocation_views.xml | 10 ++++--- .../views/hr_leave_views.xml | 10 ++++--- hr_holidays_validator_list/views/hr_views.xml | 9 +++--- .../odoo/addons/hr_holidays_validator_list | 1 + setup/hr_holidays_validator_list/setup.py | 6 ++++ 10 files changed, 63 insertions(+), 49 deletions(-) create mode 120000 setup/hr_holidays_validator_list/odoo/addons/hr_holidays_validator_list create mode 100644 setup/hr_holidays_validator_list/setup.py diff --git a/hr_holidays_validator_list/models/hr_employee.py b/hr_holidays_validator_list/models/hr_employee.py index 95ef4baf..3e175b99 100644 --- a/hr_holidays_validator_list/models/hr_employee.py +++ b/hr_holidays_validator_list/models/hr_employee.py @@ -8,27 +8,30 @@ class HrEmployeeBase(models.AbstractModel): _inherit = "hr.employee.base" leave_manager_ids = fields.Many2many( - 'res.users', - string='Time Off Managers', + "res.users", + string="Time Off Managers", store=True, readonly=False, - help='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).', + help="""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).""", ) def _set_leave_manager_id_from_leave_manager_ids(self, values): - if 'leave_manager_ids' in values: - if not len(values['leave_manager_ids'][0][-1]): - values['leave_manager_id'] = None - elif ('leave_manager_ids' in values.keys()): - values['leave_manager_id'] = values['leave_manager_ids'][0][-1][-1] + if "leave_manager_ids" in values: + if not len(values["leave_manager_ids"][0][-1]): + values["leave_manager_id"] = None + elif "leave_manager_ids" in values.keys(): + values["leave_manager_ids"] = values["leave_manager_ids"][0][-1][-1] 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 "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)]}) + approver_group.sudo().write({"users": [(4, manager_id)]}) def create(self, values): self._set_leave_manager_id_from_leave_manager_ids(values) diff --git a/hr_holidays_validator_list/models/hr_leave_allocation.py b/hr_holidays_validator_list/models/hr_leave_allocation.py index 6d10c340..74bfa12b 100644 --- a/hr_holidays_validator_list/models/hr_leave_allocation.py +++ b/hr_holidays_validator_list/models/hr_leave_allocation.py @@ -1,18 +1,16 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -# Copyright (c) 2005-2006 Axelor SARL. (http://www.axelor.com) - +# Copyright 2023 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) from odoo import models class HolidaysAllocation(models.Model): - """ Allocation Requests Access specifications: similar to leave requests """ + """Allocation Requests Access specifications: similar to leave requests""" + _inherit = "hr.leave.allocation" def activity_update(self): - """updates activity for all leave_manager_ids""" + """uUpdates activity for all leave_manager_ids""" res = super().activity_update() for manager in self.employee_id.leave_manager_ids: old_manager = self.employee_id.leave_manager_id @@ -22,7 +20,7 @@ def activity_update(self): return res def _check_approval_update(self, state): - """checks that the leave manager is in leave_manager_ids""" + """Checks that the leave manager is in leave_manager_ids""" res = super()._check_approval_update(state) for manager in self.employee_id.leave_manager_ids: if manager == self.env.user: diff --git a/hr_holidays_validator_list/readme/DESCRIPTION.rst b/hr_holidays_validator_list/readme/DESCRIPTION.rst index faeafe3d..eb26ae96 100644 --- a/hr_holidays_validator_list/readme/DESCRIPTION.rst +++ b/hr_holidays_validator_list/readme/DESCRIPTION.rst @@ -1 +1 @@ -This module allows for an employee to have several leave validators. +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 index 02c81531..42f77afd 100644 --- a/hr_holidays_validator_list/readme/USAGE.rst +++ b/hr_holidays_validator_list/readme/USAGE.rst @@ -1,6 +1,6 @@ For adding multiple : -#. Go to the menu *Employee > Field leave_manager_ids +#. 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". diff --git a/hr_holidays_validator_list/tests/test_hr_leave.py b/hr_holidays_validator_list/tests/test_hr_leave.py index 60021403..0fc955d8 100644 --- a/hr_holidays_validator_list/tests/test_hr_leave.py +++ b/hr_holidays_validator_list/tests/test_hr_leave.py @@ -4,7 +4,6 @@ from datetime import datetime import odoo.tests.common as common - from odoo.exceptions import UserError @@ -33,23 +32,27 @@ def setUp(self): 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.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.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' + 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) + 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)]}) + 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 - self.env.user = self.env['res.users'].browse(2) + self.env.user = self.env["res.users"].browse(2) with self.assertRaises(UserError): - self.hr_leave.with_user(self.env.user)._check_approval_update('validate') + self.hr_leave.with_user(self.env.user)._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 index 2c6e654e..f9c0dd2a 100644 --- a/hr_holidays_validator_list/views/hr_leave_allocation_views.xml +++ b/hr_holidays_validator_list/views/hr_leave_allocation_views.xml @@ -1,13 +1,15 @@ - - + + hr.holidays.filter_allocations.inherited hr.leave.allocation - + - [('employee_id.leave_manager_ids', 'in', [uid])] + [('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 index b68a9436..0533bac6 100644 --- a/hr_holidays_validator_list/views/hr_leave_views.xml +++ b/hr_holidays_validator_list/views/hr_leave_views.xml @@ -1,13 +1,15 @@ - - + + hr.holidays.hr_leave.inherited hr.leave - + - [('employee_id.leave_manager_ids', 'in', [uid])] + [('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 index f84bfd69..79e89152 100644 --- a/hr_holidays_validator_list/views/hr_views.xml +++ b/hr_holidays_validator_list/views/hr_views.xml @@ -1,16 +1,15 @@ - - - + + hr.employee.leave.form.inherit 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, +)