[FIX] hr_holidays : fix duplicate allocation for batch allocation
STEP TO REPRODUCE : 1. create a time off type with alloation_validation_type == 'no' 2. create a batch allocation (with company, department, employee tag or employee mode but with some employees) 3. records will be duplicated Expected behaviour : no duplication task : 3615657 Part-of: odoo/odoo#144394
This commit is contained in:
@@ -708,12 +708,14 @@ class HolidaysAllocation(models.Model):
|
||||
} for employee in employees]
|
||||
|
||||
def action_validate(self):
|
||||
self.write({
|
||||
'state': 'validate',
|
||||
'approver_id': self.env.user.employee_id.id
|
||||
})
|
||||
self._action_validate_create_childs()
|
||||
self.activity_update()
|
||||
to_validate = self.filtered(lambda alloc: alloc.state != 'validate')
|
||||
if to_validate:
|
||||
to_validate.write({
|
||||
'state': 'validate',
|
||||
'approver_id': self.env.user.employee_id.id
|
||||
})
|
||||
to_validate._action_validate_create_childs()
|
||||
to_validate.activity_update()
|
||||
return True
|
||||
|
||||
def _action_validate_create_childs(self):
|
||||
|
||||
@@ -20,3 +20,4 @@ from . import test_uninstall
|
||||
from . import test_holidays_calendar
|
||||
from . import test_negative
|
||||
from . import test_past_accruals
|
||||
from . import test_allocations
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
from odoo.tests import tagged
|
||||
|
||||
from odoo.addons.hr_holidays.tests.common import TestHrHolidaysCommon
|
||||
|
||||
|
||||
@tagged('allocation')
|
||||
class TestAllocations(TestHrHolidaysCommon):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestAllocations, cls).setUpClass()
|
||||
cls.leave_type = cls.env['hr.leave.type'].create({
|
||||
'name': 'Time Off with no validation for approval',
|
||||
'time_type': 'leave',
|
||||
'requires_allocation': 'yes',
|
||||
'allocation_validation_type': 'no',
|
||||
})
|
||||
cls.department = cls.env['hr.department'].create({
|
||||
'name': 'Test Department',
|
||||
})
|
||||
cls.category_tag = cls.env['hr.employee.category'].create({
|
||||
'name': 'Test category'
|
||||
})
|
||||
cls.employee = cls.env['hr.employee'].create({
|
||||
'name': 'My Employee',
|
||||
'company_id': cls.company.id,
|
||||
'department_id': cls.department.id,
|
||||
'category_ids': [(4, cls.category_tag.id)],
|
||||
})
|
||||
|
||||
def test_allocation_whole_company(self):
|
||||
company_allocation = self.env['hr.leave.allocation'].create({
|
||||
'name': 'Bank Holiday',
|
||||
'holiday_type': 'company',
|
||||
'mode_company_id': self.company.id,
|
||||
'holiday_status_id': self.leave_type.id,
|
||||
'number_of_days': 2,
|
||||
'allocation_type': 'regular',
|
||||
})
|
||||
|
||||
company_allocation.action_validate()
|
||||
|
||||
num_of_allocations = self.env['hr.leave.allocation'].search_count([('employee_id', '=', self.employee.id), ('multi_employee', '=', False)])
|
||||
self.assertEqual(num_of_allocations, 1)
|
||||
|
||||
def test_allocation_multi_employee(self):
|
||||
employee_allocation = self.env['hr.leave.allocation'].create({
|
||||
'name': 'Bank Holiday',
|
||||
'holiday_type': 'employee',
|
||||
'employee_ids': [(4, self.employee.id), (4, self.employee_emp.id)],
|
||||
'employee_id': self.employee.id,
|
||||
'holiday_status_id': self.leave_type.id,
|
||||
'number_of_days': 2,
|
||||
'allocation_type': 'regular',
|
||||
})
|
||||
|
||||
employee_allocation.action_validate()
|
||||
|
||||
num_of_allocations = self.env['hr.leave.allocation'].search_count([('employee_id', '=', self.employee.id), ('multi_employee', '=', False), ('parent_id', '!=', False)])
|
||||
self.assertEqual(num_of_allocations, 1)
|
||||
|
||||
def test_allocation_department(self):
|
||||
department_allocation = self.env['hr.leave.allocation'].create({
|
||||
'name': 'Bank Holiday',
|
||||
'holiday_type': 'department',
|
||||
'department_id': self.department.id,
|
||||
'holiday_status_id': self.leave_type.id,
|
||||
'number_of_days': 2,
|
||||
'allocation_type': 'regular',
|
||||
})
|
||||
|
||||
department_allocation.action_validate()
|
||||
|
||||
num_of_allocations = self.env['hr.leave.allocation'].search_count([('employee_id', '=', self.employee.id), ('multi_employee', '=', False)])
|
||||
self.assertEqual(num_of_allocations, 1)
|
||||
|
||||
def test_allocation_category(self):
|
||||
category_allocation = self.env['hr.leave.allocation'].create({
|
||||
'name': 'Bank Holiday',
|
||||
'holiday_type': 'category',
|
||||
'category_id': self.category_tag.id,
|
||||
'holiday_status_id': self.leave_type.id,
|
||||
'number_of_days': 2,
|
||||
'allocation_type': 'regular',
|
||||
})
|
||||
|
||||
category_allocation.action_validate()
|
||||
|
||||
num_of_allocations = self.env['hr.leave.allocation'].search_count([('employee_id', '=', self.employee.id), ('multi_employee', '=', False)])
|
||||
self.assertEqual(num_of_allocations, 1)
|
||||
Reference in New Issue
Block a user