[IMP]: Added Upstream Patch for hr_holidays

This commit is contained in:
Harsh Vadodaria 2018-07-06 14:05:44 +05:30
parent cb0640a320
commit ac96a360fd
2 changed files with 20 additions and 3 deletions

View File

@ -215,3 +215,15 @@ class Employee(models.Model):
('type', '=', 'remove') ('type', '=', 'remove')
]) ])
return [('id', 'in', holidays.mapped('employee_id').ids)] 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

View File

@ -195,7 +195,7 @@ class Holidays(models.Model):
states={'draft': [('readonly', False)], 'confirm': [('readonly', False)]}, states={'draft': [('readonly', False)], 'confirm': [('readonly', False)]},
help="Choose 'Leave Request' if someone wants to take an off-day. " 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") "\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') 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) 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, category_id = fields.Many2one('hr.employee.category', string='Employee Tag', readonly=True,
@ -248,7 +248,7 @@ class Holidays(models.Model):
if nholidays: if nholidays:
raise ValidationError(_('You can not have 2 leaves that overlaps on same day!')) 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): def _check_holidays(self):
for holiday in 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: 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 self.employee_id = None
@api.onchange('employee_id') @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 self.department_id = self.employee_id.department_id
def _get_number_of_days(self, date_from, date_to, employee_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}) 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 = super(Holidays, self.with_context(mail_create_nolog=True, mail_create_nosubscribe=True)).create(values)
holiday.add_follower(employee_id) holiday.add_follower(employee_id)
if 'employee_id' in values:
holiday._onchange_employee_id()
return holiday return holiday
@api.multi @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')) raise AccessError(_('You cannot set a leave request as \'%s\'. Contact a human resource manager.') % values.get('state'))
result = super(Holidays, self).write(values) result = super(Holidays, self).write(values)
self.add_follower(employee_id) self.add_follower(employee_id)
if 'employee_id' in values:
self._onchange_employee_id()
return result return result
@api.multi @api.multi