Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
503f0d5
[ADD] hr_contract_employee_calendar_planning
jonasbuchholz Oct 24, 2022
7a6b179
[MIG] hr_contract_employee_calendar_planning: Migration to 15.0
jonasbuchholz Jan 23, 2023
40fa309
[UPD] Update hr_contract_employee_calendar_planning.pot
Dec 17, 2022
46ac0a9
[UPD] README.rst
OCA-git-bot Dec 17, 2022
7935df1
[ADD] icon.png
OCA-git-bot Dec 17, 2022
be72195
[UPD] Update hr_contract_employee_calendar_planning.pot
Apr 21, 2023
df6998b
[UPD] README.rst
OCA-git-bot Apr 21, 2023
69bce01
Added translation using Weblate (Italian)
mymage May 17, 2023
52bcdab
Translated using Weblate (Italian)
mymage May 18, 2023
3368ee4
[IMP] hr_contract_employee_calendar_planning: test performance improv…
josep-tecnativa Oct 19, 2023
2a2e02a
[IMP] hr_employee_calendar_planning: prevent employee calendar overwr…
jonasbuchholz May 15, 2023
392fc00
[IMP] hr_contract_employee_calendar_planning: sort contracts and cale…
jonasbuchholz Jul 25, 2023
128de13
[IMP] hr_contract_employee_calendar_planning: test post_init_hook by …
jonasbuchholz Jul 27, 2023
bc38989
[ADD] hr_contract_employee_calendar_planning
jonasbuchholz Dec 14, 2023
edd2820
[UPD] Update hr_contract_employee_calendar_planning.pot
Dec 3, 2024
0e99771
Update translation files
weblate Dec 3, 2024
51e412b
Translated using Weblate (Italian)
mymage Dec 4, 2024
966ca82
[IMP] hr_contract_employee_calendar_planning: multicreate warning
kluna1998 Feb 27, 2025
e96a09b
[BOT] post-merge updates
OCA-git-bot Mar 24, 2025
e563ebc
Fix pre-commit issues
Alexgars73 Jun 10, 2025
47aeb98
[MIG] hr_contract_employee_calendar_planning: Migration to 18.0
Alexgars73 Jun 11, 2025
28773bd
[UPD] Update hr_contract_employee_calendar_planning.pot
Nov 8, 2025
fff992a
[BOT] post-merge updates
OCA-git-bot Nov 8, 2025
2f764d2
[18.0][FIX] hr_contract_employee_calendar_planning: avoid errors with…
FernandoRomera Jan 25, 2026
788712d
[MIG] hr_contract_employee_calendar_planning: Migration to 19.0
Feb 24, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 116 additions & 0 deletions hr_contract_employee_calendar_planning/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

======================================
Hr Contract Employee Calendar Planning
======================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:18ed8fc47869734b2baa5068f1346d1bbc662d2b834e9a2efa4ce502117ea7fa
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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/license-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-OCA%2Fhr-lightgray.png?logo=github
:target: https://github.com/OCA/hr/tree/19.0/hr_contract_employee_calendar_planning
:alt: OCA/hr
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/hr-19-0/hr-19-0-hr_contract_employee_calendar_planning
: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&target_branch=19.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module ensures a consistent working times history when using the
**hr_contract** and **hr_employee_calendar_planning** modules together.

There are 3 different data models which can relate to working time
(resource.calendar) records:

- Employees (hr.employee)
- Contracts (hr.contract)
- Resources (resource.resource) -> related to hr.employee through
resource.mixin

The **hr_employee_calendar_planning** module adds the calendar_ids field
to employees, which allows a more flexible working times configuration:
Instead of selecting a single resource.calendar, multiple calendars can
be combined into one auto-generated calendar.

However, contracts are not considered when creating auto-generated
calendars. This can lead to unexpected behaviour, because the active
contract calendar and the employee calendar can diverge (calendar
mismatch). Additionally, when configuring a new contract, or changing
the existing contract calendar, the employee calendar will be
overwritten by the contract calendar.

To resolve this issue, this module migrates current and previous
contract calendars into the calendar_ids and thus the auto-generated
calendar. Additionally, changes to the employee calendar by contracts
are prevented. The resource_calendar_id field is hidden in contract
views, since all working times should be managed in the calendar_ids
field for each employee. However, it is still possible to keep a
meaningful contract history, e.g. for salary information.

**Table of contents**

.. contents::
:local:

Usage
=====



Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/hr/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 <https://github.com/OCA/hr/issues/new?body=module:%20hr_contract_employee_calendar_planning%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
-------

* cibex

Contributors
------------

- Jonas Buchholz <J.Buchholz@cibex.net>
- `Studio73 <https://www.studio73.es/>`__:
- Vicent Castells <vicent@studio73.es>

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.

This module is part of the `OCA/hr <https://github.com/OCA/hr/tree/19.0/hr_contract_employee_calendar_planning>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions hr_contract_employee_calendar_planning/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import models
from .hooks import post_init_hook
14 changes: 14 additions & 0 deletions hr_contract_employee_calendar_planning/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Hr Contract Employee Calendar Planning",
"version": "19.0.1.0.0",
"category": "Human Resources",
"website": "https://github.com/OCA/hr",
"author": "cibex,Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"auto_install": True,
"depends": ["hr", "hr_employee_calendar_planning", "resource"],
"data": ["views/contract.xml"],
"post_init_hook": "post_init_hook",
}
77 changes: 77 additions & 0 deletions hr_contract_employee_calendar_planning/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import logging

from odoo.fields import Command

_logger = logging.getLogger(__name__)


def post_init_hook(env, employees=None):
"""Migrate calendars from versions to calendar_ids
to have consistent work schedule history"""
if not employees:
employees = env["hr.employee"].with_context(active_test=False).search([])

for employee in employees.filtered(
lambda e: e.version_ids.filtered("contract_date_start")
):
version_calendar_lines = []
versions = employee.version_ids.filtered("contract_date_start").sorted(
"date_start"
)
for version in versions:
date_start = version.date_start
date_end = version.date_end
# filter calendar_ids to check for overlaps with versions
# with the same work schedule
cal_ids = employee.calendar_ids.filtered(
lambda x, version=version: x.calendar_id == version.resource_calendar_id
and (
not x.date_start
or not version.date_end
or x.date_start < version.date_end
)
and (
not x.date_end
or not version.date_start
or x.date_end > version.date_start
)
)
if cal_ids:
_logger.info(f"{version} is overlapping with {cal_ids}")
for calendar in cal_ids.sorted("date_start"):
if date_start and calendar.date_start != date_start:
_logger.info(
f"changing date_start of {calendar} "
f"from {calendar.date_start} to {date_start}"
)
calendar.date_start = date_start
if date_end and calendar.date_end != date_end:
_logger.info(
f"changing date_end of {calendar} "
f"from {calendar.date_end} to {date_end}"
)
calendar.date_end = date_end
break
else:
_logger.info(
f"adding new calendar_id for {version.employee_id.name}: "
f"{version.resource_calendar_id.name} "
f"from {date_start} to {date_end}"
)
version_calendar_lines.append(
Command.create(
{
"date_start": date_start,
"date_end": date_end,
"calendar_id": version.resource_calendar_id.id,
}
)
)

employee.calendar_ids = version_calendar_lines

# set correct calendar in current version
# Prevent the resource calendar of leaves to be updated by a write
employee.version_id.with_context(no_leave_resource_calendar_update=True).update(
{"resource_calendar_id": employee.resource_calendar_id.id}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * hr_contract_employee_calendar_planning
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 18.0\n"
"Report-Msgid-Bugs-To: \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_employee_calendar_planning
#: model:ir.model,name:hr_contract_employee_calendar_planning.model_hr_contract
msgid "Contract"
msgstr ""
25 changes: 25 additions & 0 deletions hr_contract_employee_calendar_planning/i18n/it.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * hr_contract_employee_calendar_planning
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2024-12-04 12:06+0000\n"
"Last-Translator: mymage <stefano.consolaro@mymage.it>\n"
"Language-Team: none\n"
"Language: it\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 5.6.2\n"

#. module: hr_contract_employee_calendar_planning
#: model:ir.model,name:hr_contract_employee_calendar_planning.model_hr_contract
msgid "Contract"
msgstr "Contratto"

#~ msgid "Employee Contract"
#~ msgstr "Contratto dipendente"
1 change: 1 addition & 0 deletions hr_contract_employee_calendar_planning/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import hr_version
40 changes: 40 additions & 0 deletions hr_contract_employee_calendar_planning/models/hr_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from odoo import api, models


class HrVersion(models.Model):
_inherit = "hr.version"

def write(self, vals):
if vals.get("resource_calendar_id") and self.filtered(
lambda version: version.employee_id
and vals.get("resource_calendar_id")
!= version.employee_id.resource_calendar_id.id
):
# in the write method of versions, when writing the resource_calendar_id
# the employee resource_calendar_id is set to the same id
# this interferes with the logic of hr_employee_calendar_planning,
# which assumes that calendar times are managed by
# resource.calendar.attendances in auto-generated calendars
# based on the employee's calendar_ids.
# since the default calendar for new versions is the employee calendar,
# and we set the correct calendar for the existing version
# in the post_init_hook, we resolve this conflict by not allowing
# calendar changes in versions.
vals.pop("resource_calendar_id")
return super().write(vals)

@api.model_create_multi
def create(self, vals_list):
# the create method of versions syncs version
# calendars with employee calendars
# in order to not overwrite the employee calendar
# we set the version calendar to match the employee calendar
for vals in vals_list:
employee_calendar = (
self.env["hr.employee"]
.browse([vals.get("employee_id")])
.resource_calendar_id
)
if employee_calendar:
vals.update({"resource_calendar_id": employee_calendar.id})
return super().create(vals_list)
3 changes: 3 additions & 0 deletions hr_contract_employee_calendar_planning/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
3 changes: 3 additions & 0 deletions hr_contract_employee_calendar_planning/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Jonas Buchholz \<J.Buchholz@cibex.net\>
- [Studio73](https://www.studio73.es/):
- Vicent Castells \<<vicent@studio73.es>\>
30 changes: 30 additions & 0 deletions hr_contract_employee_calendar_planning/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
This module ensures a consistent working times history when using the
**hr_contract** and **hr_employee_calendar_planning** modules together.

There are 3 different data models which can relate to working time
(resource.calendar) records:

- Employees (hr.employee)
- Contracts (hr.contract)
- Resources (resource.resource) -\> related to hr.employee through
resource.mixin

The **hr_employee_calendar_planning** module adds the calendar_ids field
to employees, which allows a more flexible working times configuration:
Instead of selecting a single resource.calendar, multiple calendars can
be combined into one auto-generated calendar.

However, contracts are not considered when creating auto-generated
calendars. This can lead to unexpected behaviour, because the active
contract calendar and the employee calendar can diverge (calendar
mismatch). Additionally, when configuring a new contract, or changing
the existing contract calendar, the employee calendar will be
overwritten by the contract calendar.

To resolve this issue, this module migrates current and previous
contract calendars into the calendar_ids and thus the auto-generated
calendar. Additionally, changes to the employee calendar by contracts
are prevented. The resource_calendar_id field is hidden in contract
views, since all working times should be managed in the calendar_ids
field for each employee. However, it is still possible to keep a
meaningful contract history, e.g. for salary information.
1 change: 1 addition & 0 deletions hr_contract_employee_calendar_planning/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading