[FIX] hr_contract: allow to close employee's contracts

- There's a constraint limiting the number of contracts an employee can
have.

This constraint take in account closed contract which cause issues.
For example if you have to sign a new contract for an employee with a
running contract, you'll have to close the current running contract.
But if this employee already has closed contracts, you won't be able
to close it since they are detected as ""running"" contracts.

closes odoo/odoo#33294

Signed-off-by: Toufik Benjaa (tbe) <tbe@odoo.com>
This commit is contained in:
Toufik Ben Jaa
2019-05-10 13:38:36 +00:00
parent 625eaeecaf
commit f39a974cc2
+3 -3
View File
@@ -108,12 +108,12 @@ class Contract(models.Model):
@api.constrains('employee_id', 'state', 'date_start', 'date_end')
def _check_current_contract(self):
""" Two contracts in state [incoming | pending | open | close] cannot overlap """
for contract in self.filtered(lambda c: c.state not in ['draft', 'cancel']):
""" Two contracts in state [incoming | pending | open] cannot overlap """
for contract in self.filtered(lambda c: c.state not in ['draft', 'cancel', 'close']):
domain = [
('id', '!=', contract.id),
('employee_id', '=', contract.employee_id.id),
('state', 'in', ['incoming', 'pending', 'open', 'close']),
('state', 'in', ['incoming', 'pending', 'open']),
]
if not contract.date_end: