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

TA#72215 [16.0] [MIG] timesheet_holidays_time_control_compatible #54

Merged
merged 10 commits into from
Feb 4, 2025
1 change: 1 addition & 0 deletions .docker_files/main/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"depends": [
"hr_timesheet_project_parent_enhanced",
"project_timesheet_time_control_sheet",
"timesheet_holidays_time_control_compatible",
"timesheet_task_project_no_change",
],
"installable": True,
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ USER odoo

COPY hr_timesheet_project_parent_enhanced /mnt/extra-addons/hr_timesheet_project_parent_enhanced
COPY project_timesheet_time_control_sheet /mnt/extra-addons/project_timesheet_time_control_sheet
COPY timesheet_holidays_time_control_compatible /mnt/extra-addons/timesheet_holidays_time_control_compatible
COPY timesheet_task_project_no_change /mnt/extra-addons/timesheet_task_project_no_change

COPY .docker_files/main /mnt/extra-addons/main
Expand Down
1 change: 0 additions & 1 deletion gitoo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@
includes:
- web_ir_actions_act_multi
- web_widget_x2many_2d_matrix

21 changes: 21 additions & 0 deletions timesheet_holidays_time_control_compatible/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Timesheet Holidays Time Control Compatible
==========================================
This module makes the module `project_timesheet_time_control <https://github.com/OCA/project/tree/16.0/project_timesheet_time_control>`_ compatible with `project_timesheet_holidays`.

This module allows to approve leave requests in advance while associating them with the date selected by the employee, rather than saving them on the validation date.

Usage
-----
As Leave Manager,
- I validate leave for an employee requested for a later date,
- Imputation on timesheets is made for the leave date and not the validation date

.. image:: https://raw.githubusercontent.com/Numigi/odoo-timesheet-addons/16.0/timesheet_holidays_time_control_compatible/static/description/leave_validated.png

The leave is charged to timesheets whose date is equivalent to the leave date and not the validation date.

.. image:: https://raw.githubusercontent.com/Numigi/odoo-timesheet-addons/16.0/timesheet_holidays_time_control_compatible/static/description/timesheets_from_leave.png

Contributors
------------
* Numigi (tm) and all its contributors (https://bit.ly/numigiens)
4 changes: 4 additions & 0 deletions timesheet_holidays_time_control_compatible/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2023-today Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import models

Check notice on line 4 in timesheet_holidays_time_control_compatible/__init__.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

timesheet_holidays_time_control_compatible/__init__.py#L4

'.models' imported but unused (F401)
16 changes: 16 additions & 0 deletions timesheet_holidays_time_control_compatible/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2023-today Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{

Check warning on line 4 in timesheet_holidays_time_control_compatible/__manifest__.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

timesheet_holidays_time_control_compatible/__manifest__.py#L4

Statement seems to have no effect
"name": "Timesheet Holidays Time Control Compatible",
"version": "16.0.1.0.0",
"author": "Numigi",
"maintainer": "Numigi",
"website": "https://bit.ly/numigi-com",
"license": "AGPL-3",
"category": "Project",
"depends": ["project_timesheet_holidays", "project_timesheet_time_control"],
"summary": "Confirm holiday with the holiday date not the validation date.",
"data": [],
"installable": True,
}
4 changes: 4 additions & 0 deletions timesheet_holidays_time_control_compatible/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2023-today Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import hr_leave

Check notice on line 4 in timesheet_holidays_time_control_compatible/models/__init__.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

timesheet_holidays_time_control_compatible/models/__init__.py#L4

'.hr_leave' imported but unused (F401)
22 changes: 22 additions & 0 deletions timesheet_holidays_time_control_compatible/models/hr_leave.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2023-today Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import datetime

from odoo import models


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

def _timesheet_prepare_line_values(
self, index, work_hours_data, day_date, work_hours_count
):
self.ensure_one()
timesheet_line = super()._timesheet_prepare_line_values(
index, work_hours_data, day_date, work_hours_count
)
timesheet_line["date_time"] = datetime.datetime.combine(
day_date, datetime.time(8, 00)
)
return timesheet_line
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions timesheet_holidays_time_control_compatible/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2023-today Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import test_validate_holiday_date
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Copyright 2023-today Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields
from odoo.addons.hr_holidays.tests.common import TestHrHolidaysCommon


class TestValidateHolidayDate(TestHrHolidaysCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()

def test_account_analytic_line_date(self):
leave_type = self.env["hr.leave.type"].create(
{
"name": "Paid Time Off",
"leave_validation_type": "hr",
}
)
allocation = (
self.env["hr.leave.allocation"]
.with_user(self.user_hruser_id)
.create(
{
"name": "30 days allocation",
"holiday_status_id": self.env.ref(
"hr_holidays.holiday_status_training"
).id,
"number_of_days": 30,
"employee_id": self.employee_emp_id,
}
)
)
allocation.action_validate()

# Leave 1 only for 1 day or half
leave1 = (
self.env["hr.leave"]
.with_user(self.user_employee_id)
.create(
{
"name": "Holiday 1 Day",
"employee_id": self.employee_emp_id,
"holiday_status_id": leave_type.id,
"date_from": fields.Datetime.from_string("2023-09-20 08:00:00"),
"date_to": fields.Datetime.from_string("2023-09-20 17:00:00"),
"number_of_days": 1,
}
)
)
leave1.sudo().action_validate()

self.assertEqual(
leave1.sudo().timesheet_ids[0].date, leave1.sudo().date_from.date()
)
# Leave 2 more than 1 day
date_start = fields.Datetime.from_string("2023-09-21 08:00:00")
date_end = fields.Datetime.from_string("2023-09-22 17:00:00")
leave2 = self.env["hr.leave"].create(
{
"name": "Holiday 2 Days",
"employee_id": self.employee_emp_id,
"holiday_status_id": leave_type.id,
"date_from": date_start,
"date_to": date_end,
}
)

leave2.sudo().action_validate()

# Ensure that each timesheet is having
# the correct date (start and end date in leave)

self.assertEqual(len(leave2.timesheet_ids), 2)
self.assertEqual(
leave2.sudo().timesheet_ids[1].date, leave2.sudo().date_from.date()
)
self.assertEqual(
leave2.sudo().timesheet_ids[0].date, leave2.sudo().date_to.date()
)
Loading