From f160bba4d1dca8616de6b0f0246444dfe0d4dbdf Mon Sep 17 00:00:00 2001 From: "Adrien Peiffer (ACSONE)" Date: Wed, 12 Apr 2017 18:17:27 +0200 Subject: [PATCH] [IMP] hr_holidays: improve inheritance Improve inheritance on allocation creation by employee's tag. opw-728620 Closes #16402 --- addons/hr_holidays/models/hr_holidays.py | 30 ++++++++++++++---------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/addons/hr_holidays/models/hr_holidays.py b/addons/hr_holidays/models/hr_holidays.py index 9b4daa0f5bf..469a60f0231 100644 --- a/addons/hr_holidays/models/hr_holidays.py +++ b/addons/hr_holidays/models/hr_holidays.py @@ -439,6 +439,23 @@ class Holidays(models.Model): else: holiday.action_validate() + @api.multi + def _prepare_create_by_category(self, employee): + self.ensure_one() + values = { + 'name': self.name, + 'type': self.type, + 'holiday_type': 'employee', + 'holiday_status_id': self.holiday_status_id.id, + 'date_from': self.date_from, + 'date_to': self.date_to, + 'notes': self.notes, + 'number_of_days_temp': self.number_of_days_temp, + 'parent_id': self.id, + 'employee_id': employee.id + } + return values + @api.multi def action_validate(self): if not self.env.user.has_group('hr_holidays.group_hr_holidays_user'): @@ -479,18 +496,7 @@ class Holidays(models.Model): elif holiday.holiday_type == 'category': leaves = self.env['hr.holidays'] for employee in holiday.category_id.employee_ids: - values = { - 'name': holiday.name, - 'type': holiday.type, - 'holiday_type': 'employee', - 'holiday_status_id': holiday.holiday_status_id.id, - 'date_from': holiday.date_from, - 'date_to': holiday.date_to, - 'notes': holiday.notes, - 'number_of_days_temp': holiday.number_of_days_temp, - 'parent_id': holiday.id, - 'employee_id': employee.id - } + values = holiday._prepare_create_by_category(employee) leaves += self.with_context(mail_notify_force_send=False).create(values) # TODO is it necessary to interleave the calls? leaves.action_approve()