From ac96a360fd5a86481bf7926d4712c8d73c71e0b1 Mon Sep 17 00:00:00 2001 From: Harsh Vadodaria Date: Fri, 6 Jul 2018 14:05:44 +0530 Subject: [PATCH] [IMP]: Added Upstream Patch for hr_holidays --- addons/hr_holidays/models/hr.py | 12 ++++++++++++ addons/hr_holidays/models/hr_holidays.py | 11 ++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/addons/hr_holidays/models/hr.py b/addons/hr_holidays/models/hr.py index 80393e6a..b4387d5f 100644 --- a/addons/hr_holidays/models/hr.py +++ b/addons/hr_holidays/models/hr.py @@ -215,3 +215,15 @@ class Employee(models.Model): ('type', '=', 'remove') ]) return [('id', 'in', holidays.mapped('employee_id').ids)] + + def write(self, values): + res = super(Employee, self).write(values) + if 'parent_id' in values or 'department_id' in values: + holidays = self.env['hr.holidays'].search([('state', 'in', ['draft', 'confirm']), ('employee_id', 'in', self.ids)]) + hr_vals = {} + if values.get('parent_id') is not None: + hr_vals['manager_id'] = values['parent_id'] + if values.get('department_id') is not None: + hr_vals['department_id'] = values['department_id'] + holidays.write(hr_vals) + return res diff --git a/addons/hr_holidays/models/hr_holidays.py b/addons/hr_holidays/models/hr_holidays.py index 9e79c561..4d8cf770 100644 --- a/addons/hr_holidays/models/hr_holidays.py +++ b/addons/hr_holidays/models/hr_holidays.py @@ -195,7 +195,7 @@ class Holidays(models.Model): states={'draft': [('readonly', False)], 'confirm': [('readonly', False)]}, help="Choose 'Leave Request' if someone wants to take an off-day. " "\nChoose 'Allocation Request' if you want to increase the number of leaves available for someone") - parent_id = fields.Many2one('hr.holidays', string='Parent') + parent_id = fields.Many2one('hr.holidays', string='Parent', copy=False) linked_request_ids = fields.One2many('hr.holidays', 'parent_id', string='Linked Requests') department_id = fields.Many2one('hr.department', related='employee_id.department_id', string='Department', readonly=True, store=True) category_id = fields.Many2one('hr.employee.category', string='Employee Tag', readonly=True, @@ -248,7 +248,7 @@ class Holidays(models.Model): if nholidays: raise ValidationError(_('You can not have 2 leaves that overlaps on same day!')) - @api.constrains('state', 'number_of_days_temp') + @api.constrains('state', 'number_of_days_temp', 'holiday_status_id') def _check_holidays(self): for holiday in self: if holiday.holiday_type != 'employee' or holiday.type != 'remove' or not holiday.employee_id or holiday.holiday_status_id.limit: @@ -274,7 +274,8 @@ class Holidays(models.Model): self.employee_id = None @api.onchange('employee_id') - def _onchange_employee(self): + def _onchange_employee_id(self): + self.manager_id = self.employee_id and self.employee_id.parent_id self.department_id = self.employee_id.department_id def _get_number_of_days(self, date_from, date_to, employee_id): @@ -358,6 +359,8 @@ class Holidays(models.Model): values.update({'department_id': self.env['hr.employee'].browse(employee_id).department_id.id}) holiday = super(Holidays, self.with_context(mail_create_nolog=True, mail_create_nosubscribe=True)).create(values) holiday.add_follower(employee_id) + if 'employee_id' in values: + holiday._onchange_employee_id() return holiday @api.multi @@ -367,6 +370,8 @@ class Holidays(models.Model): raise AccessError(_('You cannot set a leave request as \'%s\'. Contact a human resource manager.') % values.get('state')) result = super(Holidays, self).write(values) self.add_follower(employee_id) + if 'employee_id' in values: + self._onchange_employee_id() return result @api.multi