Files
odoo_source/addons
Sarah Bellefroid e15c7e5442 [FIX] hr_holidays: correct name search in leave type
Currently, when requesting time off for multiple employees, the search for the leave type correspond to the search of the current user.

Steps to reproduce:
-------------------
* Go to the **Time Off** app
* Select **Configuration** > **Time Off Type**
* Create a new time off type
  * Approval: By Employee's Approver and Time Off Oficcer
  * Requires allocation: Yes
  * Employee Requests: Extra Days Requests Allowed
  * Approval: Approved by Time Off Officer
  * Notified Time off officer: Mitchell Admin
* Select **Management** > **Allocations**
* Create a new allocation
  * Employees: Mitchell Admin
  * Time off time: The one created previously
* Validate the allocation
* Select **Management** > **Time Off**
* create a new time off
  * Employees: Any Employee A & Employee B
  * Time off type:
  > Observation: The new time off time is present in the name search while both employees don't have any allocation for it.

Why the fix:
------------
The name search searches for time off type with
```
['|', ['requires_allocation', '=', 'no'], '&', ['has_valid_allocation', '=', True], '&', ['max_leaves', '>', '0'], '|', ['allows_negative', '=', True], '&', ['virtual_remaining_leaves', '>', 0], ['allows_negative', '=', False]]
```
By configuration, the time off has `requires_allocation = yes` therefore it shouldn't appear here and it does not -> ok

`has_valid_allocation` has a search method `_search_valid`
https://github.com/odoo/odoo/blob/bb0cb2896236ead6b474cd1b3a685ff447716b95/addons/hr_holidays/models/hr_leave_type.py#L109-L138

`max_leaves` has a search method `_search_max_leaves`
https://github.com/odoo/odoo/blob/bb0cb2896236ead6b474cd1b3a685ff447716b95/addons/hr_holidays/models/hr_leave_type.py#L165-L192

Both use the function `_get_contextual_employee` to make their search.
https://github.com/odoo/odoo/blob/bb0cb2896236ead6b474cd1b3a685ff447716b95/addons/hr_holidays/models/hr_employee.py#L386-L388

When there are more than one employee selected on the hr leave form, the context contains `employee_id: False`. Thus here we are making the search using the current user, which is Mitchell Admin.

The search shouldn't be made using the current user in this case since he doesn't correspond to any of the employees we added of the form.

opw-3816442

closes odoo/odoo#161713

Signed-off-by: Bertrand Dossogne (bedo) <bedo@odoo.com>
2024-04-26 17:17:53 +00:00
..
2024-04-09 19:35:41 +00:00
2024-03-08 11:17:48 +00:00
2024-02-22 09:06:12 +00:00
2024-01-26 09:13:03 +00:00
2024-03-15 17:30:00 +00:00
2024-04-26 08:22:49 +00:00
2023-10-27 08:36:16 +00:00
2023-10-27 08:36:16 +00:00
2023-10-27 08:36:16 +00:00