allow closed contracts to overlap

This commit is contained in:
Florian du Garage Num 2025-08-31 08:24:47 +02:00
parent 95ad2b2855
commit c7cfbe8631
6 changed files with 66 additions and 1 deletions

View File

@ -6,4 +6,5 @@ Addons for Odoo 18
| Name | Version | Description |
|------------------------|-----------------|---------------------------------------------|
| gn_l10n_fr_pcg_asso | 18.0.0.0.1 | PCG pour les associations françaises |
| gn_l10n_fr_pcg_asso | 18.0.0.0.1 | PCG pour les associations françaises |
| gn_hr | 18.0.0.0.1 | Module RH custom |

5
gn_hr/README.md Normal file
View File

@ -0,0 +1,5 @@
# GN HR
This module allow to have overlapping contracts if they're expired.
The current behavior forbids it unless contracts are in state "Draft" or "Cancel".
We just modify method `_check_current_contract` on `hr.contract`.

2
gn_hr/__init__.py Normal file
View File

@ -0,0 +1,2 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from . import models

13
gn_hr/__manifest__.py Normal file
View File

@ -0,0 +1,13 @@
{
"name": "GN HR",
"version": "18.0.0.0.1",
"category": "HR",
"summary": "Custom HR module",
"author": "Le Garage Numérique",
"maintainers": ["makayabou"],
"website": "https://git.legaragenumerique.fr",
"depends": [
"hr_contract",
],
"license": "LGPL-3",
}

1
gn_hr/models/__init__.py Normal file
View File

@ -0,0 +1 @@
from . import hr_contract

View File

@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
from odoo import api, fields, models, _
from odoo.exceptions import ValidationError
from odoo.osv import expression
import logging
_logger = logging.getLogger(__name__)
class Contract(models.Model):
_inherit = ['hr.contract']
@api.constrains('employee_id', 'state', 'kanban_state', 'date_start', 'date_end')
def _check_current_contract(self):
""" Two contracts in state [incoming | open | close] cannot overlap """
for contract in self.filtered(lambda c: (c.state not in ['draft', 'cancel', 'close'] or c.state == 'draft' and c.kanban_state == 'done') and c.employee_id):
domain = [
('id', '!=', contract.id),
('employee_id', '=', contract.employee_id.id),
('company_id', '=', contract.company_id.id),
'|',
('state', 'in', ['open', 'close']),
'&',
('state', '=', 'draft'),
('kanban_state', '=', 'done') # replaces incoming
]
if not contract.date_end:
start_domain = []
end_domain = ['|', ('date_end', '>=', contract.date_start), ('date_end', '=', False)]
else:
start_domain = [('date_start', '<=', contract.date_end)]
end_domain = ['|', ('date_end', '>', contract.date_start), ('date_end', '=', False)]
domain = expression.AND([domain, start_domain, end_domain])
if self.search_count(domain):
raise ValidationError(
_(
'An employee can only have one contract at the same time. (Excluding Draft and Cancelled contracts).\n\nEmployee: %(employee_name)s',
employee_name=contract.employee_id.name
)
)