From bef21de75011747cc39186ba548d538d6a2ea58f Mon Sep 17 00:00:00 2001 From: Carmen Bianca BAKKER Date: Fri, 21 Jun 2024 18:23:17 +0200 Subject: [PATCH 1/2] [ADD] hr_timesheet_overtime_rate_holidays I really dislike writing Odoo tests. They take so so so so long to write, building a global state like a house of cards. Signed-off-by: Carmen Bianca BAKKER --- .../README.rst | 71 +++ .../__init__.py | 5 + .../__manifest__.py | 19 + .../models/__init__.py | 5 + .../models/account_analytic_line.py | 15 + .../readme/CONTRIBUTORS.rst | 3 + .../readme/DESCRIPTION.rst | 2 + .../static/description/index.html | 421 ++++++++++++++++++ .../tests/__init__.py | 5 + .../tests/test_timesheet_holidays.py | 73 +++ .../hr_timesheet_overtime_rate_holidays | 1 + .../setup.py | 6 + 12 files changed, 626 insertions(+) create mode 100644 hr_timesheet_overtime_rate_holidays/README.rst create mode 100644 hr_timesheet_overtime_rate_holidays/__init__.py create mode 100644 hr_timesheet_overtime_rate_holidays/__manifest__.py create mode 100644 hr_timesheet_overtime_rate_holidays/models/__init__.py create mode 100644 hr_timesheet_overtime_rate_holidays/models/account_analytic_line.py create mode 100644 hr_timesheet_overtime_rate_holidays/readme/CONTRIBUTORS.rst create mode 100644 hr_timesheet_overtime_rate_holidays/readme/DESCRIPTION.rst create mode 100644 hr_timesheet_overtime_rate_holidays/static/description/index.html create mode 100644 hr_timesheet_overtime_rate_holidays/tests/__init__.py create mode 100644 hr_timesheet_overtime_rate_holidays/tests/test_timesheet_holidays.py create mode 120000 setup/hr_timesheet_overtime_rate_holidays/odoo/addons/hr_timesheet_overtime_rate_holidays create mode 100644 setup/hr_timesheet_overtime_rate_holidays/setup.py diff --git a/hr_timesheet_overtime_rate_holidays/README.rst b/hr_timesheet_overtime_rate_holidays/README.rst new file mode 100644 index 0000000..14236aa --- /dev/null +++ b/hr_timesheet_overtime_rate_holidays/README.rst @@ -0,0 +1,71 @@ +=============================================== +Timesheet - Overtime and holidays compatibility +=============================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:c66f9b84bace8273e5d1ae17aee636c58bb8bc63a2bc85c58efc080a59033467 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-coopiteasy%2Fcie--timesheet-lightgray.png?logo=github + :target: https://github.com/coopiteasy/cie-timesheet/tree/16.0/hr_timesheet_overtime_rate_holidays + :alt: coopiteasy/cie-timesheet + +|badge1| |badge2| |badge3| + +Ensures that no overtime rate is applied to timesheet lines that are created +when taking leave. + +**Table of contents** + +.. contents:: + :local: + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Coop IT Easy SC + +Contributors +~~~~~~~~~~~~ + +* `Coop IT Easy SC `_: + + * Carmen Bianca BAKKER + +Maintainers +~~~~~~~~~~~ + +.. |maintainer-carmenbianca| image:: https://github.com/carmenbianca.png?size=40px + :target: https://github.com/carmenbianca + :alt: carmenbianca + +Current maintainer: + +|maintainer-carmenbianca| + +This module is part of the `coopiteasy/cie-timesheet `_ project on GitHub. + +You are welcome to contribute. diff --git a/hr_timesheet_overtime_rate_holidays/__init__.py b/hr_timesheet_overtime_rate_holidays/__init__.py new file mode 100644 index 0000000..3eb7887 --- /dev/null +++ b/hr_timesheet_overtime_rate_holidays/__init__.py @@ -0,0 +1,5 @@ +# SPDX-FileCopyrightText: 2024 Coop IT Easy SC +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +from . import models diff --git a/hr_timesheet_overtime_rate_holidays/__manifest__.py b/hr_timesheet_overtime_rate_holidays/__manifest__.py new file mode 100644 index 0000000..2674bb7 --- /dev/null +++ b/hr_timesheet_overtime_rate_holidays/__manifest__.py @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: 2024 Coop IT Easy SC +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +{ + "name": "Timesheet - Overtime and holidays compatibility", + "summary": "Don't apply overtime rates on timesheet lines created from a holiday", + "version": "16.0.1.0.0", + "category": "Human Resources", + "website": "https://github.com/coopiteasy/cie-timesheet", + "author": "Coop IT Easy SC", + "maintainers": ["carmenbianca"], + "license": "AGPL-3", + "depends": [ + "project_timesheet_holidays", + "hr_timesheet_overtime_rate", + ], + "auto_install": True, +} diff --git a/hr_timesheet_overtime_rate_holidays/models/__init__.py b/hr_timesheet_overtime_rate_holidays/models/__init__.py new file mode 100644 index 0000000..84f4adc --- /dev/null +++ b/hr_timesheet_overtime_rate_holidays/models/__init__.py @@ -0,0 +1,5 @@ +# SPDX-FileCopyrightText: 2024 Coop IT Easy SC +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +from . import account_analytic_line diff --git a/hr_timesheet_overtime_rate_holidays/models/account_analytic_line.py b/hr_timesheet_overtime_rate_holidays/models/account_analytic_line.py new file mode 100644 index 0000000..6cdffdc --- /dev/null +++ b/hr_timesheet_overtime_rate_holidays/models/account_analytic_line.py @@ -0,0 +1,15 @@ +# SPDX-FileCopyrightText: 2024 Coop IT Easy SC +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +from odoo import models + + +class AnalyticLine(models.Model): + _inherit = "account.analytic.line" + + def get_overtime_rate(self): + self.ensure_one() + if self.holiday_id: + return 1 + return super().get_overtime_rate() diff --git a/hr_timesheet_overtime_rate_holidays/readme/CONTRIBUTORS.rst b/hr_timesheet_overtime_rate_holidays/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000..f1ac675 --- /dev/null +++ b/hr_timesheet_overtime_rate_holidays/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Coop IT Easy SC `_: + + * Carmen Bianca BAKKER diff --git a/hr_timesheet_overtime_rate_holidays/readme/DESCRIPTION.rst b/hr_timesheet_overtime_rate_holidays/readme/DESCRIPTION.rst new file mode 100644 index 0000000..82e1685 --- /dev/null +++ b/hr_timesheet_overtime_rate_holidays/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +Ensures that no overtime rate is applied to timesheet lines that are created +when taking leave. diff --git a/hr_timesheet_overtime_rate_holidays/static/description/index.html b/hr_timesheet_overtime_rate_holidays/static/description/index.html new file mode 100644 index 0000000..b5b2522 --- /dev/null +++ b/hr_timesheet_overtime_rate_holidays/static/description/index.html @@ -0,0 +1,421 @@ + + + + + +Timesheet - Overtime and holidays compatibility + + + +
+

Timesheet - Overtime and holidays compatibility

+ + +

Beta License: AGPL-3 coopiteasy/cie-timesheet

+

Ensures that no overtime rate is applied to timesheet lines that are created +when taking leave.

+

Table of contents

+ +
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Coop IT Easy SC
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

Current maintainer:

+

carmenbianca

+

This module is part of the coopiteasy/cie-timesheet project on GitHub.

+

You are welcome to contribute.

+
+
+
+ + diff --git a/hr_timesheet_overtime_rate_holidays/tests/__init__.py b/hr_timesheet_overtime_rate_holidays/tests/__init__.py new file mode 100644 index 0000000..e66310f --- /dev/null +++ b/hr_timesheet_overtime_rate_holidays/tests/__init__.py @@ -0,0 +1,5 @@ +# SPDX-FileCopyrightText: 2024 Coop IT Easy SC +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +from . import test_timesheet_holidays diff --git a/hr_timesheet_overtime_rate_holidays/tests/test_timesheet_holidays.py b/hr_timesheet_overtime_rate_holidays/tests/test_timesheet_holidays.py new file mode 100644 index 0000000..e7eaa2b --- /dev/null +++ b/hr_timesheet_overtime_rate_holidays/tests/test_timesheet_holidays.py @@ -0,0 +1,73 @@ +# SPDX-FileCopyrightText: 2024 Coop IT Easy SC +# +# SPDX-License-Identifier: AGPL-3.0-or-later + + +from datetime import datetime + +from dateutil.relativedelta import relativedelta + +from odoo.addons.hr_timesheet.tests.test_timesheet import TestCommonTimesheet + + +class TestTimesheetHolidays(TestCommonTimesheet): + def setUp(self): + super().setUp() + + self.leave_start_datetime = datetime(2018, 2, 5, 7, 0, 0, 0) # this is monday + self.leave_end_datetime = self.leave_start_datetime + relativedelta(days=3) + + self.internal_project = self.env.company.internal_project_id + self.internal_task_leaves = self.env.company.leave_timesheet_task_id + + self.hr_leave_type = self.env["hr.leave.type"].create( + { + "name": "Leave Type", + "requires_allocation": "no", + "timesheet_generate": True, + "timesheet_project_id": self.internal_project.id, + "timesheet_task_id": self.internal_task_leaves.id, + } + ) + + # I'm not sure what this record does in this context. + self.overtime = self.env["resource.overtime"].create({"name": "test"}) + self.rate = self.env["resource.overtime.rate"].create( + { + "name": "test", + "dayofweek": "0", # Monday + "rate": 2.0, + "overtime_id": self.overtime.id, + } + ) + + def test_unit_amount(self): + number_of_days = (self.leave_end_datetime - self.leave_start_datetime).days + holiday = ( + self.env["hr.leave"] + .with_user(self.user_employee) + .create( + { + "name": "Leave 1", + "employee_id": self.empl_employee.id, + "holiday_type": "employee", + "holiday_status_id": self.hr_leave_type.id, + "date_from": self.leave_start_datetime, + "date_to": self.leave_end_datetime, + "number_of_days": number_of_days, + } + ) + ) + holiday.sudo().action_validate() + + # This is the important bit. All the above is really annoying Odoo + # testing scaffolding. + analytic_lines = self.env["account.analytic.line"].search( + [ + ("date", ">=", self.leave_start_datetime.date()), + ("date", "<=", self.leave_end_datetime.date()), + ] + ) + self.assertEqual(len(analytic_lines), 3) + for line in analytic_lines: + self.assertAlmostEqual(line.unit_amount, 8.0) diff --git a/setup/hr_timesheet_overtime_rate_holidays/odoo/addons/hr_timesheet_overtime_rate_holidays b/setup/hr_timesheet_overtime_rate_holidays/odoo/addons/hr_timesheet_overtime_rate_holidays new file mode 120000 index 0000000..bc2b632 --- /dev/null +++ b/setup/hr_timesheet_overtime_rate_holidays/odoo/addons/hr_timesheet_overtime_rate_holidays @@ -0,0 +1 @@ +../../../../hr_timesheet_overtime_rate_holidays \ No newline at end of file diff --git a/setup/hr_timesheet_overtime_rate_holidays/setup.py b/setup/hr_timesheet_overtime_rate_holidays/setup.py new file mode 100644 index 0000000..28c57bb --- /dev/null +++ b/setup/hr_timesheet_overtime_rate_holidays/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) From 94fd511c7c313c7818c63af2c9cdbff1e5f69b50 Mon Sep 17 00:00:00 2001 From: Carmen Bianca BAKKER Date: Thu, 18 Jul 2024 14:33:04 +0200 Subject: [PATCH 2/2] [MIG] hr_timesheet_overtime_rate_holidays: Migrate to 12.0 Signed-off-by: Carmen Bianca BAKKER --- .../__manifest__.py | 6 +++--- .../models/account_analytic_line.py | 9 ++++---- .../tests/test_timesheet_holidays.py | 21 +++++++++++++++---- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/hr_timesheet_overtime_rate_holidays/__manifest__.py b/hr_timesheet_overtime_rate_holidays/__manifest__.py index 2674bb7..8f66ee6 100644 --- a/hr_timesheet_overtime_rate_holidays/__manifest__.py +++ b/hr_timesheet_overtime_rate_holidays/__manifest__.py @@ -5,15 +5,15 @@ { "name": "Timesheet - Overtime and holidays compatibility", "summary": "Don't apply overtime rates on timesheet lines created from a holiday", - "version": "16.0.1.0.0", + "version": "12.0.1.0.0", "category": "Human Resources", - "website": "https://github.com/coopiteasy/cie-timesheet", + "website": "https://coopiteasy.be", "author": "Coop IT Easy SC", "maintainers": ["carmenbianca"], "license": "AGPL-3", "depends": [ "project_timesheet_holidays", - "hr_timesheet_overtime_rate", + "hr_timesheet_overtime", ], "auto_install": True, } diff --git a/hr_timesheet_overtime_rate_holidays/models/account_analytic_line.py b/hr_timesheet_overtime_rate_holidays/models/account_analytic_line.py index 6cdffdc..f2825e3 100644 --- a/hr_timesheet_overtime_rate_holidays/models/account_analytic_line.py +++ b/hr_timesheet_overtime_rate_holidays/models/account_analytic_line.py @@ -8,8 +8,7 @@ class AnalyticLine(models.Model): _inherit = "account.analytic.line" - def get_overtime_rate(self): - self.ensure_one() - if self.holiday_id: - return 1 - return super().get_overtime_rate() + def _update_values(self, values): + if not values.get("holiday_id", self.holiday_id): + return super()._update_values(values) + return diff --git a/hr_timesheet_overtime_rate_holidays/tests/test_timesheet_holidays.py b/hr_timesheet_overtime_rate_holidays/tests/test_timesheet_holidays.py index e7eaa2b..cc9740f 100644 --- a/hr_timesheet_overtime_rate_holidays/tests/test_timesheet_holidays.py +++ b/hr_timesheet_overtime_rate_holidays/tests/test_timesheet_holidays.py @@ -17,13 +17,14 @@ def setUp(self): self.leave_start_datetime = datetime(2018, 2, 5, 7, 0, 0, 0) # this is monday self.leave_end_datetime = self.leave_start_datetime + relativedelta(days=3) - self.internal_project = self.env.company.internal_project_id - self.internal_task_leaves = self.env.company.leave_timesheet_task_id + self.internal_project = self.env.user.company_id.leave_timesheet_project_id + self.internal_task_leaves = self.env.user.company_id.leave_timesheet_task_id self.hr_leave_type = self.env["hr.leave.type"].create( { "name": "Leave Type", - "requires_allocation": "no", + "allocation_type": "no", + "validity_start": self.leave_start_datetime, "timesheet_generate": True, "timesheet_project_id": self.internal_project.id, "timesheet_task_id": self.internal_task_leaves.id, @@ -41,11 +42,23 @@ def setUp(self): } ) + # This is necessary because hr_timesheet_overtime depends on + # resource_work_time_from_contracts. + self.env["hr.contract"].create( + { + "name": "test", + "employee_id": self.empl_employee.id, + "wage": 0.0, + "resource_calendar_id": self.empl_employee.resource_calendar_id.id, + "date_start": "2017-01-01", + } + ) + def test_unit_amount(self): number_of_days = (self.leave_end_datetime - self.leave_start_datetime).days holiday = ( self.env["hr.leave"] - .with_user(self.user_employee) + .sudo(self.user_employee.id) .create( { "name": "Leave 1",