Skip to content

Commit

Permalink
fix: pre-commit corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
victorvermot committed Nov 7, 2023
1 parent 1937ed0 commit e4662ed
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 49 deletions.
29 changes: 16 additions & 13 deletions hr_holidays_validator_list/models/hr_employee.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 6 additions & 8 deletions hr_holidays_validator_list/models/hr_leave_allocation.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion hr_holidays_validator_list/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -1 +1 @@
This module allows for an employee to have several leave validators.
This module allows for an employee to have several leave validators.
2 changes: 1 addition & 1 deletion hr_holidays_validator_list/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -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".

Expand Down
29 changes: 16 additions & 13 deletions hr_holidays_validator_list/tests/test_hr_leave.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from datetime import datetime

import odoo.tests.common as common

from odoo.exceptions import UserError


Expand Down Expand Up @@ -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")
10 changes: 6 additions & 4 deletions hr_holidays_validator_list/views/hr_leave_allocation_views.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<?xml version='1.0' encoding='UTF-8'?>
<odoo>
<?xml version='1.0' encoding='UTF-8' ?>
<odoo>
<record id="view_hr_leave_allocation_filter_inherited" model="ir.ui.view">
<field name="name">hr.holidays.filter_allocations.inherited</field>
<field name="model">hr.leave.allocation</field>
<field name="inherit_id" ref="hr_holidays.view_hr_leave_allocation_filter"/>
<field name="inherit_id" ref="hr_holidays.view_hr_leave_allocation_filter" />
<field name="arch" type="xml">
<data>
<xpath expr="//filter[@name='managed_people']" position="attributes">
<attribute name="domain">[('employee_id.leave_manager_ids', 'in', [uid])]</attribute>
<attribute
name="domain"
>[('employee_id.leave_manager_ids', 'in', [uid])]</attribute>
</xpath>
</data>
</field>
Expand Down
10 changes: 6 additions & 4 deletions hr_holidays_validator_list/views/hr_leave_views.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<?xml version='1.0' encoding='UTF-8'?>
<odoo>
<?xml version='1.0' encoding='UTF-8' ?>
<odoo>
<record id="view_hr_leave_filter_inherited" model="ir.ui.view">
<field name="name">hr.holidays.hr_leave.inherited</field>
<field name="model">hr.leave</field>
<field name="inherit_id" ref="hr_holidays.view_hr_holidays_filter"/>
<field name="inherit_id" ref="hr_holidays.view_hr_holidays_filter" />
<field name="arch" type="xml">
<data>
<xpath expr="//filter[@name='managed_people']" position="attributes">
<attribute name="domain">[('employee_id.leave_manager_ids', 'in', [uid])]</attribute>
<attribute
name="domain"
>[('employee_id.leave_manager_ids', 'in', [uid])]</attribute>
</xpath>
</data>
</field>
Expand Down
9 changes: 4 additions & 5 deletions hr_holidays_validator_list/views/hr_views.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
<?xml version='1.0' encoding='UTF-8'?>
<odoo>
<!-- Hr employee inherit Legal Leaves -->
<?xml version='1.0' encoding='UTF-8' ?>
<odoo>
<record id="view_employee_form_leave_inherit" model="ir.ui.view">
<field name="name">hr.employee.leave.form.inherit</field>
<field name="model">hr.employee</field>
<field name="inherit_id" ref="hr_holidays.view_employee_form_leave_inherit"/>
<field name="inherit_id" ref="hr_holidays.view_employee_form_leave_inherit" />
<field name="arch" type="xml">
<xpath expr="//field[@name='leave_manager_id']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
<xpath expr="//group[@name='managers']" position="inside">
<field name="leave_manager_ids" widget="many2many_tags"/>
<field name="leave_manager_ids" widget="many2many_tags" />
</xpath>
</field>
</record>
Expand Down
6 changes: 6 additions & 0 deletions setup/hr_holidays_validator_list/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit e4662ed

Please sign in to comment.