[FIX] hr_contract: Avoid error when changing template contract stage

Before this commit:
When we change a contract to stage 'open', we write this contract
on employee. But it causes error when it's a template contract
(without employee).

After this commit:
When we change a contract to stage 'open', we write this contract
on employee only if contract has an employee.

[FIX] hr_contract: Allow overlapping in template contract

Before this commit:
We check for all contract that there are no overlapping for a
same employee.

After this commit:
We check that there are no overlapping for contract with
employee.

[FIX] hr_payroll, hr_holidays: Avoid some constrains with company time off

Before this commit:
We can't create company (or team) time off if you have 2 or more
template contract in your database.
We can't create mutliple company or team time off that overlaps.

After this commit:
We can create company (or team) time off if you have 2 or more
template contract in your database.
If a time off is set across multiple contract, print those contracts
in error message.
We can create multiple company or team time off that overlaps.

closes odoo/odoo#45696

Taskid: 2196185
X-original-commit: 3fdada6f8f19ae7123d9b35b3e7c557d072c1bc0
Related: odoo/enterprise#8553
Signed-off-by: jbm-odoo <jbm-odoo@users.noreply.github.com>
This commit is contained in:
fw-bot
2020-02-19 11:04:40 +00:00
committed by jbm-odoo
parent 3184a911e7
commit 047e222373
2 changed files with 3 additions and 3 deletions
+2 -2
View File
@@ -80,7 +80,7 @@ class Contract(models.Model):
@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'] or c.state == 'draft' and c.kanban_state == 'done'):
for contract in self.filtered(lambda c: (c.state not in ['draft', 'cancel'] or c.state == 'draft' and c.kanban_state == 'done') and c.employee_id):
domain = [
('id', '!=', contract.id),
('employee_id', '=', contract.employee_id.id),
@@ -190,7 +190,7 @@ class Contract(models.Model):
contracts._assign_open_contract()
open_contracts = contracts.filtered(lambda c: c.state == 'open' or c.state == 'draft' and c.kanban_state == 'done')
# sync contract calendar -> calendar employee
for contract in open_contracts.filtered(lambda c: c.resource_calendar_id):
for contract in open_contracts.filtered(lambda c: c.employee_id and c.resource_calendar_id):
contract.employee_id.resource_calendar_id = contract.resource_calendar_id
return contracts
+1 -1
View File
@@ -528,7 +528,7 @@ class HolidaysRequest(models.Model):
@api.constrains('date_from', 'date_to', 'state', 'employee_id')
def _check_date(self):
for holiday in self:
for holiday in self.filtered('employee_id'):
domain = [
('date_from', '<', holiday.date_to),
('date_to', '>', holiday.date_from),