diff --git a/README.md b/README.md index 13a0575..da7d659 100644 --- a/README.md +++ b/README.md @@ -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 | \ No newline at end of file +| 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 | diff --git a/gn_hr/README.md b/gn_hr/README.md new file mode 100644 index 0000000..012cfce --- /dev/null +++ b/gn_hr/README.md @@ -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`. diff --git a/gn_hr/__init__.py b/gn_hr/__init__.py new file mode 100644 index 0000000..ca62191 --- /dev/null +++ b/gn_hr/__init__.py @@ -0,0 +1,2 @@ +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). +from . import models \ No newline at end of file diff --git a/gn_hr/__manifest__.py b/gn_hr/__manifest__.py new file mode 100644 index 0000000..3553255 --- /dev/null +++ b/gn_hr/__manifest__.py @@ -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", +} diff --git a/gn_hr/models/__init__.py b/gn_hr/models/__init__.py new file mode 100644 index 0000000..b07b789 --- /dev/null +++ b/gn_hr/models/__init__.py @@ -0,0 +1 @@ +from . import hr_contract diff --git a/gn_hr/models/hr_contract.py b/gn_hr/models/hr_contract.py new file mode 100644 index 0000000..603e1a5 --- /dev/null +++ b/gn_hr/models/hr_contract.py @@ -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 + ) + )