From 047e222373918c7b7ff1630c62bca6ec6a425132 Mon Sep 17 00:00:00 2001 From: fw-bot Date: Mon, 17 Feb 2020 11:18:36 +0000 Subject: [PATCH] [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 --- addons/hr_contract/models/hr_contract.py | 4 ++-- addons/hr_holidays/models/hr_leave.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/hr_contract/models/hr_contract.py b/addons/hr_contract/models/hr_contract.py index 345fb5fe016..5f5509ccfc5 100644 --- a/addons/hr_contract/models/hr_contract.py +++ b/addons/hr_contract/models/hr_contract.py @@ -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 diff --git a/addons/hr_holidays/models/hr_leave.py b/addons/hr_holidays/models/hr_leave.py index 637aababa62..fd8e337621d 100644 --- a/addons/hr_holidays/models/hr_leave.py +++ b/addons/hr_holidays/models/hr_leave.py @@ -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),