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

[FW][FIX] hr_holidays: correctly calculate leave duration #166139

Conversation

fw-bot
Copy link
Contributor

@fw-bot fw-bot commented May 21, 2024

Steps

  • Time off installed
  • Put an employee on a different schedule than the company's
    default one and make him for example start earlier.
  • Create a new Time Off type, set "Requires allocation" to
    No Limit.
  • Approvals > Time off > New and create a time off (mode "by
    company") on the day where the employee is starting earlier.
  • Approve it.
  • Approvals > Time off : the leave's duration for the employee
    on a different schedule is incorrect (slightly less than 1 day).

Issue

When creating a leave on a company level, a leave will first be
created with start and end hours based on the company's default
schedule.
When approving the leave, a leave is then created for each
affected employee. The date_from and date_to received by
create are based on the company's default schedule. This is not
generally problematic as it is taken into account. For example,
the date_from and date_to of the employee's leave are correct
even if he is on a different schedule.

However, when we compute the number of days, it is not accounted for.

employee_leave_date_duration[(date_from, date_to)] = self._get_number_of_days_batch(date_from, date_to, employee_ids)

result = employee._get_work_days_data_batch(date_from, date_to, domain=domain)

As a result, the hours worked by an employee on a different schedule
which are "outside" of the company's default schedule don't count
towards the calculation.
https://github.com/odoo/odoo/blob/3eec4d6a69ff76cbf750b960dc8db2eb5e0a45f9/addons/resource/models/resource_mixin.py#L94-101

Note: the issue is the same for leaves given to a department or an
employee tag since they are created the same way.

Fix

When creating a leave for employees, if the leave is not for half
days or hours, give the whole day as a leave to account for different
schedules. Note that the actual date_from and date_to of each employee's
leave are still based on their actual attendance, but if an employee
has hours outside of the company's schedule, they will count towards
the leave's duration.

opw-3703793

Forward-Port-Of: #165947
Forward-Port-Of: #161856

Steps
-----
- Time off installed
- Put an employee on a different schedule than the company's
default one and make him for example start earlier.
- Create a new Time Off type, set "Requires allocation" to
No Limit.
- Approvals > Time off > New and create a time off (mode "by
company") on the day where the employee is starting earlier.
- Approve it.
- Approvals > Time off : the leave's duration for the employee
on a different schedule is incorrect (slightly less than 1 day).

Issue
-----
When creating a leave on a company level, a leave will first be
created with start and end hours based on the company's default
schedule.
When approving the leave, a leave is then created for each
affected employee. The date_from and date_to received by
create are based on the company's default schedule. This is not
generally problematic as it is taken into account. For example,
the date_from and date_to of the employee's leave are correct
even if he is on a different schedule.

However, when we compute the number of days, it is not accounted for.
https://github.com/odoo/odoo/blob/64cbe389e698398eee93ebde9c61b2ee79756380/addons/hr_holidays/models/hr_leave.py#L918
https://github.com/odoo/odoo/blob/64cbe389e698398eee93ebde9c61b2ee79756380/addons/hr_holidays/models/hr_leave.py#L744
As a result, the hours worked by an employee on a different schedule
which are "outside" of the company's default schedule don't count
towards the calculation.
https://github.com/odoo/odoo/blob/3eec4d6a69ff76cbf750b960dc8db2eb5e0a45f9/addons/resource/models/resource_mixin.py#L94-101

Note: the issue is the same for leaves given to a department or an
employee tag since they are created the same way.

Fix
-----
Use the whole day as a basis for leave duration calculation if there
is more than one schedule for the employees. Also add more logic to
handle half days and hours leaves which had incorrect start and end
hours.

opw-3703793

X-original-commit: aaf27b4
@robodoo robodoo added the forwardport This PR was created by @fw-bot label May 21, 2024
@robodoo
Copy link
Contributor

robodoo commented May 21, 2024

Pull request status dashboard.

@fw-bot
Copy link
Contributor Author

fw-bot commented May 21, 2024

@taqu-odoo @Bertrand2 this PR targets saas-16.4 and is the last of the forward-port chain.

To merge the full chain, use

@fw-bot r+

More info at https://github.com/odoo/odoo/wiki/Mergebot#forward-port

@C3POdoo C3POdoo added the OE the report is linked to a support ticket (opw-...) label May 21, 2024
@Bertrand2
Copy link
Contributor

@fw-bot r+

robodoo pushed a commit that referenced this pull request May 21, 2024
Steps
-----
- Time off installed
- Put an employee on a different schedule than the company's
default one and make him for example start earlier.
- Create a new Time Off type, set "Requires allocation" to
No Limit.
- Approvals > Time off > New and create a time off (mode "by
company") on the day where the employee is starting earlier.
- Approve it.
- Approvals > Time off : the leave's duration for the employee
on a different schedule is incorrect (slightly less than 1 day).

Issue
-----
When creating a leave on a company level, a leave will first be
created with start and end hours based on the company's default
schedule.
When approving the leave, a leave is then created for each
affected employee. The date_from and date_to received by
create are based on the company's default schedule. This is not
generally problematic as it is taken into account. For example,
the date_from and date_to of the employee's leave are correct
even if he is on a different schedule.

However, when we compute the number of days, it is not accounted for.
https://github.com/odoo/odoo/blob/64cbe389e698398eee93ebde9c61b2ee79756380/addons/hr_holidays/models/hr_leave.py#L918
https://github.com/odoo/odoo/blob/64cbe389e698398eee93ebde9c61b2ee79756380/addons/hr_holidays/models/hr_leave.py#L744
As a result, the hours worked by an employee on a different schedule
which are "outside" of the company's default schedule don't count
towards the calculation.
https://github.com/odoo/odoo/blob/3eec4d6a69ff76cbf750b960dc8db2eb5e0a45f9/addons/resource/models/resource_mixin.py#L94-101

Note: the issue is the same for leaves given to a department or an
employee tag since they are created the same way.

Fix
-----
Use the whole day as a basis for leave duration calculation if there
is more than one schedule for the employees. Also add more logic to
handle half days and hours leaves which had incorrect start and end
hours.

opw-3703793

closes #166139

X-original-commit: aaf27b4
Signed-off-by: Bertrand Dossogne (bedo) <bedo@odoo.com>
@robodoo robodoo closed this May 21, 2024
@fw-bot fw-bot deleted the saas-16.4-16.0-opw-3703793-company_time_off_duration-taqu-1R2N-fw branch June 4, 2024 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
forwardport This PR was created by @fw-bot OE the report is linked to a support ticket (opw-...)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants