Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][ADD] hr_leave_employee_manager: Add domain #148

Open
wants to merge 1 commit into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions hr_leave_employee_manager/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
.. image:: https://img.shields.io/badge/license-LGPL--3-blue.svg
:target: https://opensource.org/licenses/LGPL-3.0
:alt: License: LGPL-3

=========================
HR Leave Employee Manager
=========================

Overview
========

The **HR Leave Employee Manager** module enhances the leave request process in Odoo by modifying the domain applied to the `employee_id` field. With this module, the field only shows:

- The current employee (if the user is linked to an employee record).
- Employees managed by the current employee (employees for whom the current employee is the `leave_manager_id`).

This ensures that managers can only create leave requests for their own team, improving usability and enforcing better data control.

Features
========

- The `employee_id` field on leave requests (model `hr.leave`) is restricted to:

- The current user’s employee record.

- Employees for whom the current user is the `leave_manager_id`.

- Form view inheritance to ensure the `employee_id` field is always visible and applies the correct domain dynamically.

Usage
=====

1. **Install the Module**:

- Install the **HR Leave Employee Manager** module from the Apps menu.

2. **Go to Leave Requests**:

- Navigate to *Time Off > Managers > Time Off*.

- Create a new leave request.

- In the *Employee* field, you will only see:

- Yourself (if you are an employee).

- Employees who have you set as their *Leave Manager*.

3. **Simplified Selection**:
- Managers will only see their team members, simplifying the creation of requests on behalf of employees.

Configuration
=============

No additional configuration is required to use this module.

Testing
=======

1. Link a user to an employee record.

2. Set that employee as the `leave_manager_id` of some other employees.

3. Log in with that user and try to create a leave request.

4. Verify that the `employee_id` field only shows:

- The current employee.

- The employees managed by that employee.

Bug Tracker
===========

If you encounter any issues, please report them on the GitHub repository at `GitHub Issues <https://github.com/avanzosc/hr-addons/issues>`_.

Credits
=======

Contributors
------------

* Ana Juaristi <[email protected]>
* Unai Beristain <[email protected]>

For specific questions or support, please contact the contributors.

License
=======

This project is licensed under the LGPL-3 License. For more details, refer to the LICENSE file or visit <https://opensource.org/licenses/LGPL-3.0>.
1 change: 1 addition & 0 deletions hr_leave_employee_manager/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
14 changes: 14 additions & 0 deletions hr_leave_employee_manager/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "HR Leave Employee Manager",
"version": "14.0.1.0.0",
"category": "Human Resources",
"author": "Avanzosc",
"license": "LGPL-3",
"depends": ["hr_holidays"],
"data": [
"views/hr_leave_view.xml",
],
"installable": True,
"application": False,
"website": "https://github.com/avanzosc/hr-addons",
}
1 change: 1 addition & 0 deletions hr_leave_employee_manager/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import hr_leave
19 changes: 19 additions & 0 deletions hr_leave_employee_manager/models/hr_leave.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from odoo import api, fields, models


class HrLeave(models.Model):
_inherit = "hr.leave"

@api.model
def _domain_employee_id(self):
employee = self.env.user.employee_id
if not employee:
return [("id", "=", False)]
return ["|", ("id", "=", employee.id), ("leave_manager_id", "=", employee.id)]

employee_id = fields.Many2one(
"hr.employee",
string="Employee",
domain=lambda self: self._domain_employee_id(),
required=True,
)
14 changes: 14 additions & 0 deletions hr_leave_employee_manager/views/hr_leave_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="view_leave_form_inherit_employee_manager" model="ir.ui.view">
<field name="name">hr.leave.form.inherit.employee.manager</field>
<field name="model">hr.leave</field>
<field name="inherit_id" ref="hr_holidays.hr_leave_view_form" />
<field name="arch" type="xml">
<field name="employee_id" position="attributes">
<attribute name="invisible">0</attribute>
<attribute name="options">{'invisible': 0}</attribute>
</field>
</field>
</record>
</odoo>
6 changes: 6 additions & 0 deletions setup/hr_leave_employee_manager/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,
)