diff --git a/hr_contract_update_overtime/README.rst b/hr_contract_update_overtime/README.rst new file mode 100644 index 00000000..d1ae2b09 --- /dev/null +++ b/hr_contract_update_overtime/README.rst @@ -0,0 +1,120 @@ +================================ +Update Overtime from HR Contract +================================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:2329c25c16db2797a064fe7cbfc3513aea464555dc2d747d4ea77f8958d6dd05 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png + :target: https://odoo-community.org/page/development-status + :alt: Alpha +.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fhr--attendance-lightgray.png?logo=github + :target: https://github.com/OCA/hr-attendance/tree/16.0/hr_contract_update_overtime + :alt: OCA/hr-attendance +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/hr-attendance-16-0/hr-attendance-16-0-hr_contract_update_overtime + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/hr-attendance&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends the functionality of Contracts and Attendances to +support recalculating Overtime and to allow you to keep up to date your +Overtime. + +You can Update Overtime in different ways: + +- An action on the Contract History tree view +- Header button on Contract History form view +- Header button on Contract form view + +.. IMPORTANT:: + This is an alpha version, the data model and design can change at any time without warning. + Only for development or testing purpose, do not use in production. + `More details on development status `_ + +**Table of contents** + +.. contents:: + :local: + +Use Cases / Context +=================== + +This module was developed because in certain cases, you want to Update +Overtime of your Employees. + +It will be useful for you if you activate contracts module after +attendance. + +Usage +===== + +To use this module, you need to: + +1. Go to Settings > Attendances +2. Activate "Count Extra Hours" +3. Go to Employees > Contracts +4. Select any Contract History Running or Expired +5. Click on "Update Overtime" button on the Header + +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 +------- + +* Moduon + +Contributors +------------ + +- Eduardo de Miguel (`Moduon `__) + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +.. |maintainer-Shide| image:: https://github.com/Shide.png?size=40px + :target: https://github.com/Shide + :alt: Shide +.. |maintainer-rafaelbn| image:: https://github.com/rafaelbn.png?size=40px + :target: https://github.com/rafaelbn + :alt: rafaelbn + +Current `maintainers `__: + +|maintainer-Shide| |maintainer-rafaelbn| + +This module is part of the `OCA/hr-attendance `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/hr_contract_update_overtime/__init__.py b/hr_contract_update_overtime/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/hr_contract_update_overtime/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/hr_contract_update_overtime/__manifest__.py b/hr_contract_update_overtime/__manifest__.py new file mode 100644 index 00000000..d8f67d03 --- /dev/null +++ b/hr_contract_update_overtime/__manifest__.py @@ -0,0 +1,28 @@ +# Copyright 2024 Moduon Team S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0) + +{ + "name": "Update Overtime from HR Contract", + "summary": "Update Overtime from HR Contract", + "version": "16.0.1.0.0", + "development_status": "Alpha", + "category": "Human Resources/Contracts", + "website": "https://github.com/OCA/hr-attendance", + "author": "Moduon, Odoo Community Association (OCA)", + "maintainers": ["Shide", "rafaelbn"], + "license": "LGPL-3", + "application": False, + "installable": True, + "external_dependencies": { + "python": ["freezegun"], + }, + "depends": [ + "hr_contract", + "hr_attendance", + ], + "data": [ + "data/hr_contract_history_data.xml", + "views/hr_contract_history_view.xml", + "views/hr_contract_view.xml", + ], +} diff --git a/hr_contract_update_overtime/data/hr_contract_history_data.xml b/hr_contract_update_overtime/data/hr_contract_history_data.xml new file mode 100644 index 00000000..9ecc0ee3 --- /dev/null +++ b/hr_contract_update_overtime/data/hr_contract_history_data.xml @@ -0,0 +1,18 @@ + + + + Update Overtime + + + tree + + code + records.action_update_overtime() + + diff --git a/hr_contract_update_overtime/i18n/es.po b/hr_contract_update_overtime/i18n/es.po new file mode 100644 index 00000000..7a22b425 --- /dev/null +++ b/hr_contract_update_overtime/i18n/es.po @@ -0,0 +1,40 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_contract_update_overtime +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-07-11 08:46+0000\n" +"PO-Revision-Date: 2024-07-11 10:47+0200\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: Poedit 3.4.4\n" + +#. module: hr_contract_update_overtime +#: model:ir.model,name:hr_contract_update_overtime.model_hr_contract +msgid "Contract" +msgstr "Contrato" + +#. module: hr_contract_update_overtime +#: model:ir.model,name:hr_contract_update_overtime.model_hr_contract_history +msgid "Contract history" +msgstr "Histórico de contratación" + +#. module: hr_contract_update_overtime +#: model:ir.actions.server,name:hr_contract_update_overtime.hr_contract_history_update_overtime_all_action +#: model_terms:ir.ui.view,arch_db:hr_contract_update_overtime.hr_contract_history_view_form +#: model_terms:ir.ui.view,arch_db:hr_contract_update_overtime.hr_contract_view_form +msgid "Update Overtime" +msgstr "Actualizar Horas Extra" + +#. module: hr_contract_update_overtime +#: model_terms:ir.ui.view,arch_db:hr_contract_update_overtime.hr_contract_history_view_form +msgid "Update Overtime on Running and Expired contracts" +msgstr "Actualiza las Horas Extra en los contratos en Curso o Expirados" diff --git a/hr_contract_update_overtime/i18n/hr_contract_update_overtime.pot b/hr_contract_update_overtime/i18n/hr_contract_update_overtime.pot new file mode 100644 index 00000000..3d144b51 --- /dev/null +++ b/hr_contract_update_overtime/i18n/hr_contract_update_overtime.pot @@ -0,0 +1,38 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_contract_update_overtime +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-07-11 08:46+0000\n" +"PO-Revision-Date: 2024-07-11 08:46+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: hr_contract_update_overtime +#: model:ir.model,name:hr_contract_update_overtime.model_hr_contract +msgid "Contract" +msgstr "" + +#. module: hr_contract_update_overtime +#: model:ir.model,name:hr_contract_update_overtime.model_hr_contract_history +msgid "Contract history" +msgstr "" + +#. module: hr_contract_update_overtime +#: model:ir.actions.server,name:hr_contract_update_overtime.hr_contract_history_update_overtime_all_action +#: model_terms:ir.ui.view,arch_db:hr_contract_update_overtime.hr_contract_history_view_form +#: model_terms:ir.ui.view,arch_db:hr_contract_update_overtime.hr_contract_view_form +msgid "Update Overtime" +msgstr "" + +#. module: hr_contract_update_overtime +#: model_terms:ir.ui.view,arch_db:hr_contract_update_overtime.hr_contract_history_view_form +msgid "Update Overtime on Running and Expired contracts" +msgstr "" diff --git a/hr_contract_update_overtime/models/__init__.py b/hr_contract_update_overtime/models/__init__.py new file mode 100644 index 00000000..f0fc9d11 --- /dev/null +++ b/hr_contract_update_overtime/models/__init__.py @@ -0,0 +1,2 @@ +from . import hr_contract +from . import hr_contract_history diff --git a/hr_contract_update_overtime/models/hr_contract.py b/hr_contract_update_overtime/models/hr_contract.py new file mode 100644 index 00000000..7528302d --- /dev/null +++ b/hr_contract_update_overtime/models/hr_contract.py @@ -0,0 +1,27 @@ +# Copyright 2024 Moduon Team S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0) +from datetime import datetime, timedelta + +from odoo import fields, models + + +class HrContract(models.Model): + _inherit = "hr.contract" + + def _get_attendances(self): + self.ensure_one() + dtt_start = datetime.combine(self.date_start, datetime.min.time()) + dtt_end = datetime.combine( + self.date_end or fields.Date.today(), datetime.min.time() + ) + return self.employee_id.attendance_ids.filtered( + lambda att: att.check_in >= dtt_start + and att.check_in < (dtt_end + timedelta(days=1)) + ) + + def action_update_overtime(self): + for record in self: + if record.state not in {"open", "close"}: + continue + attendances = record._get_attendances() + attendances._update_overtime() diff --git a/hr_contract_update_overtime/models/hr_contract_history.py b/hr_contract_update_overtime/models/hr_contract_history.py new file mode 100644 index 00000000..2a9326b7 --- /dev/null +++ b/hr_contract_update_overtime/models/hr_contract_history.py @@ -0,0 +1,10 @@ +# Copyright 2024 Moduon Team S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0) +from odoo import models + + +class HrContractHistory(models.Model): + _inherit = "hr.contract.history" + + def action_update_overtime(self): + return self.mapped("contract_ids").action_update_overtime() diff --git a/hr_contract_update_overtime/readme/CONTEXT.md b/hr_contract_update_overtime/readme/CONTEXT.md new file mode 100644 index 00000000..6d0a2e61 --- /dev/null +++ b/hr_contract_update_overtime/readme/CONTEXT.md @@ -0,0 +1,4 @@ +This module was developed because in certain cases, you want to +Update Overtime of your Employees. + +It will be useful for you if you activate contracts module after attendance. diff --git a/hr_contract_update_overtime/readme/CONTRIBUTORS.md b/hr_contract_update_overtime/readme/CONTRIBUTORS.md new file mode 100644 index 00000000..290347f4 --- /dev/null +++ b/hr_contract_update_overtime/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Eduardo de Miguel ([Moduon](https://www.moduon.team/)) diff --git a/hr_contract_update_overtime/readme/DESCRIPTION.md b/hr_contract_update_overtime/readme/DESCRIPTION.md new file mode 100644 index 00000000..0141d1f9 --- /dev/null +++ b/hr_contract_update_overtime/readme/DESCRIPTION.md @@ -0,0 +1,7 @@ +This module extends the functionality of Contracts and Attendances to support +recalculating Overtime and to allow you to keep up to date your Overtime. + +You can Update Overtime in different ways: +- An action on the Contract History tree view +- Header button on Contract History form view +- Header button on Contract form view diff --git a/hr_contract_update_overtime/readme/USAGE.md b/hr_contract_update_overtime/readme/USAGE.md new file mode 100644 index 00000000..ca574879 --- /dev/null +++ b/hr_contract_update_overtime/readme/USAGE.md @@ -0,0 +1,7 @@ +To use this module, you need to: + +1. Go to Settings > Attendances +2. Activate "Count Extra Hours" +3. Go to Employees > Contracts +4. Select any Contract History Running or Expired +5. Click on "Update Overtime" button on the Header diff --git a/hr_contract_update_overtime/static/description/icon.png b/hr_contract_update_overtime/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/hr_contract_update_overtime/static/description/icon.png differ diff --git a/hr_contract_update_overtime/static/description/index.html b/hr_contract_update_overtime/static/description/index.html new file mode 100644 index 00000000..f0e34d6d --- /dev/null +++ b/hr_contract_update_overtime/static/description/index.html @@ -0,0 +1,459 @@ + + + + + +Update Overtime from HR Contract + + + +
+

Update Overtime from HR Contract

+ + +

Alpha License: LGPL-3 OCA/hr-attendance Translate me on Weblate Try me on Runboat

+

This module extends the functionality of Contracts and Attendances to +support recalculating Overtime and to allow you to keep up to date your +Overtime.

+

You can Update Overtime in different ways:

+
    +
  • An action on the Contract History tree view
  • +
  • Header button on Contract History form view
  • +
  • Header button on Contract form view
  • +
+
+

Important

+

This is an alpha version, the data model and design can change at any time without warning. +Only for development or testing purpose, do not use in production. +More details on development status

+
+

Table of contents

+ +
+

Use Cases / Context

+

This module was developed because in certain cases, you want to Update +Overtime of your Employees.

+

It will be useful for you if you activate contracts module after +attendance.

+
+
+

Usage

+

To use this module, you need to:

+
    +
  1. Go to Settings > Attendances
  2. +
  3. Activate “Count Extra Hours”
  4. +
  5. Go to Employees > Contracts
  6. +
  7. Select any Contract History Running or Expired
  8. +
  9. Click on “Update Overtime” button on the Header
  10. +
+
+
+

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

+
    +
  • Moduon
  • +
+
+
+

Contributors

+
    +
  • Eduardo de Miguel (Moduon)
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

Current maintainers:

+

Shide rafaelbn

+

This module is part of the OCA/hr-attendance project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/hr_contract_update_overtime/tests/__init__.py b/hr_contract_update_overtime/tests/__init__.py new file mode 100644 index 00000000..4dbc6ab9 --- /dev/null +++ b/hr_contract_update_overtime/tests/__init__.py @@ -0,0 +1 @@ +from . import test_hr_contract_update_overtime diff --git a/hr_contract_update_overtime/tests/test_hr_contract_update_overtime.py b/hr_contract_update_overtime/tests/test_hr_contract_update_overtime.py new file mode 100644 index 00000000..a3b1c743 --- /dev/null +++ b/hr_contract_update_overtime/tests/test_hr_contract_update_overtime.py @@ -0,0 +1,213 @@ +# Copyright 2024 Moduon Team S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0) + +from datetime import datetime, timedelta + +from freezegun import freeze_time + +from odoo import fields +from odoo.tests.common import TransactionCase +from odoo.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT + + +@freeze_time("2024-01-19") +class HRContractUpdateOvertime(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + tz = "UTC" + cls.env.user.tz = tz + cls.employee = cls.env["hr.employee"].create( + { + "name": "Overtime Employee", + "gender": "male", + "country_id": cls.env.ref("base.es").id, + "tz": tz, + } + ) + today = fields.Date.today() + + def make_dtt(days_before, h=0, m=0, to_date=False): + dat = datetime.combine( + today - timedelta(days=days_before), datetime.min.time() + ).replace(hour=h, minute=m) + if to_date: + return dat.date().strftime(DEFAULT_SERVER_DATE_FORMAT) + return dat.strftime(DEFAULT_SERVER_DATETIME_FORMAT) + + # Configure overtime + company = cls.employee.company_id + company.hr_attendance_overtime = True + company.overtime_start_date = make_dtt(7, 0, 0, to_date=True) + company.overtime_company_threshold = 0.0 + company.overtime_employee_threshold = 0.0 + company.resource_calendar_id.tz = tz + # Create attendances + + cls.env["hr.attendance"].create( + [ + { + "employee_id": cls.employee.id, + "check_in": make_dtt(4, h=8, m=30), + "check_out": make_dtt(4, h=9, m=30), + }, + { + "employee_id": cls.employee.id, + "check_in": make_dtt(3, h=8, m=30), + "check_out": make_dtt(3, h=11, m=30), + }, + { + "employee_id": cls.employee.id, + "check_in": make_dtt(2, h=8, m=30), + "check_out": make_dtt(2, h=15, m=30), + }, + ] + ) + # Create Resource Calendars + rc_2h_day = cls.env["resource.calendar"].create( + [ + { + "name": "Test Calendar: 10h week", + "company_id": company.id, + "tz": tz, + "two_weeks_calendar": False, + "attendance_ids": [(5, 0, 0)] + + [ + ( + 0, + 0, + { + "name": "Attendance", + "dayofweek": dayofweek, + "hour_from": hour_from, + "hour_to": hour_to, + "day_period": day_period, + }, + ) + for dayofweek, hour_from, hour_to, day_period in [ + ("0", 8.0, 10.0, "morning"), + ("1", 8.0, 10.0, "morning"), + ("2", 8.0, 10.0, "morning"), + ("3", 8.0, 10.0, "morning"), + ("4", 8.0, 10.0, "morning"), + ] + ], + } + ] + ) + rc_4h_day = cls.env["resource.calendar"].create( + [ + { + "name": "Test Calendar: 20h week", + "company_id": company.id, + "tz": tz, + "two_weeks_calendar": False, + "attendance_ids": [(5, 0, 0)] + + [ + ( + 0, + 0, + { + "name": "Attendance", + "dayofweek": dayofweek, + "hour_from": hour_from, + "hour_to": hour_to, + "day_period": day_period, + }, + ) + for dayofweek, hour_from, hour_to, day_period in [ + ("0", 8.0, 12.0, "morning"), + ("1", 8.0, 12.0, "morning"), + ("2", 8.0, 12.0, "morning"), + ("3", 8.0, 12.0, "morning"), + ("4", 8.0, 12.0, "morning"), + ] + ], + } + ] + ) + rc_8h_day = cls.env["resource.calendar"].create( + [ + { + "name": "Test Calendar: 40h week", + "company_id": company.id, + "tz": tz, + "two_weeks_calendar": False, + "attendance_ids": [(5, 0, 0)] + + [ + ( + 0, + 0, + { + "name": "Attendance", + "dayofweek": dayofweek, + "hour_from": hour_from, + "hour_to": hour_to, + "day_period": day_period, + }, + ) + for dayofweek, hour_from, hour_to, day_period in [ + ("0", 8.0, 16.0, "morning"), + ("1", 8.0, 16.0, "morning"), + ("2", 8.0, 16.0, "morning"), + ("3", 8.0, 16.0, "morning"), + ("4", 8.0, 16.0, "morning"), + ] + ], + } + ] + ) + # Create Contracts + cls.env["hr.contract"].create( + [ + { + "name": "Contract 2h", + "employee_id": cls.employee.id, + "hr_responsible_id": cls.env.user.id, + "resource_calendar_id": rc_2h_day.id, + "state": "close", + "wage": 1, + "date_start": make_dtt(4, to_date=True), + "date_end": make_dtt(4, to_date=True), + }, + { + "name": "Contract 4h", + "employee_id": cls.employee.id, + "hr_responsible_id": cls.env.user.id, + "resource_calendar_id": rc_4h_day.id, + "state": "close", + "wage": 2, + "date_start": make_dtt(3, to_date=True), + "date_end": make_dtt(3, to_date=True), + }, + { + "name": "Contract 8h", + "employee_id": cls.employee.id, + "hr_responsible_id": cls.env.user.id, + "resource_calendar_id": rc_8h_day.id, + "state": "open", + "wage": 4, + "date_start": make_dtt(2, to_date=True), + }, + ] + ) + cls.contract_history = cls.env["hr.contract.history"].search( + [ + ("employee_id", "=", cls.employee.id), + ] + ) + cls.overtime_model = cls.env["hr.attendance.overtime"] + + def test_overtime(self): + self.assertEqual(self.contract_history.contract_count, 3) + self.contract_history.action_update_overtime() + total_overtime = ( + self.env["hr.attendance.overtime"] + .search( + [ + ("employee_id", "=", self.employee.id), + ] + ) + .mapped("duration") + ) + self.assertEqual(sum(total_overtime), -3.0) diff --git a/hr_contract_update_overtime/views/hr_contract_history_view.xml b/hr_contract_update_overtime/views/hr_contract_history_view.xml new file mode 100644 index 00000000..cff60987 --- /dev/null +++ b/hr_contract_update_overtime/views/hr_contract_history_view.xml @@ -0,0 +1,20 @@ + + + + + hr.contract.history + + + +