diff options
| author | Lucas Lefèvre <lul@odoo.com> | 2019-03-29 12:03:11 +0100 |
|---|---|---|
| committer | Yannick Tivisse <yti@odoo.com> | 2019-06-13 10:02:10 +0200 |
| commit | 22437e331a60c81a80d619c075a9d516e980c078 (patch) | |
| tree | 9178688c381961b55be5329fbc443b42fb3a0c13 /addons/hr_contract/tests | |
| parent | 55e7b702bb7f01c5f3bd3efbccf82c2d2c661f49 (diff) | |
[IMP] hr_contract: Sync employee and contract calendars mismatch
Purpose
=======
An employee and its current contract should have the same
calendar. Currently, if the contract's calendar is changed,
the employee's calendar is not changed.
In the same way, if a contract is created directly in `open`
state, the employee's calendar is not changed.
Finally, the calendar synchronization when the employee
contract is changed is only done in payroll, for no reason.
Specification
=============
Fix the three issues described above.
If the employee's calendar is nonetheless manually changed, a warning
should be displayed if there is a mismatch between both calendars.
Diffstat (limited to 'addons/hr_contract/tests')
| -rw-r--r-- | addons/hr_contract/tests/__init__.py | 1 | ||||
| -rw-r--r-- | addons/hr_contract/tests/common.py | 16 | ||||
| -rw-r--r-- | addons/hr_contract/tests/test_auto_status.py | 10 | ||||
| -rw-r--r-- | addons/hr_contract/tests/test_calendar_sync.py | 68 | ||||
| -rw-r--r-- | addons/hr_contract/tests/test_contract.py | 21 |
5 files changed, 99 insertions, 17 deletions
diff --git a/addons/hr_contract/tests/__init__.py b/addons/hr_contract/tests/__init__.py index ad627a612a4..d798e53356b 100644 --- a/addons/hr_contract/tests/__init__.py +++ b/addons/hr_contract/tests/__init__.py @@ -3,3 +3,4 @@ from . import test_auto_status from . import test_contract +from . import test_calendar_sync diff --git a/addons/hr_contract/tests/common.py b/addons/hr_contract/tests/common.py new file mode 100644 index 00000000000..3c7dc0b80e9 --- /dev/null +++ b/addons/hr_contract/tests/common.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. +from odoo.tests.common import TransactionCase +from dateutil.relativedelta import relativedelta + + +class TestContractBase(TransactionCase): + + def setUp(self): + super(TestContractBase, self).setUp() + + self.employee = self.env['hr.employee'].create({ + 'name': 'Richard', + 'gender': 'male', + 'country_id': self.ref('base.be'), + }) diff --git a/addons/hr_contract/tests/test_auto_status.py b/addons/hr_contract/tests/test_auto_status.py index 20b8e4007fc..c342d05dd0f 100644 --- a/addons/hr_contract/tests/test_auto_status.py +++ b/addons/hr_contract/tests/test_auto_status.py @@ -1,21 +1,15 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. from datetime import date, datetime -from odoo.tests.common import TransactionCase from dateutil.relativedelta import relativedelta +from odoo.addons.hr_contract.tests.common import TestContractBase -class TestHrContracts(TransactionCase): +class TestHrContracts(TestContractBase): def setUp(self): super(TestHrContracts, self).setUp() self.contracts = self.env['hr.contract'].with_context(tracking_disable=True) - self.employee = self.env['hr.employee'].create({ - 'name': 'Richard', - 'gender': 'male', - 'birthday': '1984-05-01', - 'country_id': self.ref('base.be'), - }) self.test_contract = dict(name='Test', wage=1, employee_id=self.employee.id, state='open') def apply_cron(self): diff --git a/addons/hr_contract/tests/test_calendar_sync.py b/addons/hr_contract/tests/test_calendar_sync.py new file mode 100644 index 00000000000..b025def4c7e --- /dev/null +++ b/addons/hr_contract/tests/test_calendar_sync.py @@ -0,0 +1,68 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo.fields import Datetime, Date +from odoo.addons.hr_contract.tests.common import TestContractBase + + +class TestContractCalendars(TestContractBase): + + def setUp(self): + super(TestContractCalendars, self).setUp() + self.calendar_richard = self.env['resource.calendar'].create({'name': 'Calendar of Richard'}) + self.employee.resource_calendar_id = self.calendar_richard + + self.calendar_35h = self.env['resource.calendar'].create({'name': '35h calendar'}) + self.calendar_35h._onchange_hours_per_day() # update hours/day + + self.contract_cdd = self.env['hr.contract'].create({ + 'date_end': Date.to_date('2015-11-15'), + 'date_start': Date.to_date('2015-01-01'), + 'name': 'First CDD Contract for Richard', + 'resource_calendar_id': self.calendar_35h.id, + 'wage': 5000.0, + 'employee_id': self.employee.id, + 'state': 'close', + }) + + def test_contract_state_incoming_to_open(self): + # Employee's calendar should change + self.assertEqual(self.employee.resource_calendar_id, self.calendar_richard) + self.contract_cdd.state = 'open' + self.assertEqual(self.employee.resource_calendar_id, self.contract_cdd.resource_calendar_id, "The employee should have the calendar of its contract.") + + def test_contract_transfer_leaves(self): + + def create_calendar_leave(start, end, resource=None): + return self.env['resource.calendar.leaves'].create({ + 'name': 'leave name', + 'date_from': start, + 'date_to': end, + 'resource_id': resource.id if resource else None, + 'calendar_id': self.employee.resource_calendar_id.id, + 'time_type': 'leave', + }) + + start = Datetime.to_datetime('2015-11-17 07:00:00') + end = Datetime.to_datetime('2015-11-20 18:00:00') + leave1 = create_calendar_leave(start, end, resource=self.employee.resource_id) + + start = Datetime.to_datetime('2015-11-25 07:00:00') + end = Datetime.to_datetime('2015-11-28 18:00:00') + leave2 = create_calendar_leave(start, end, resource=self.employee.resource_id) + + # global leave + start = Datetime.to_datetime('2015-11-25 07:00:00') + end = Datetime.to_datetime('2015-11-28 18:00:00') + leave3 = create_calendar_leave(start, end) + + self.calendar_richard.transfer_leaves_to(self.calendar_35h, resources=self.employee.resource_id, from_date=Date.to_date('2015-11-21')) + + self.assertEqual(leave1.calendar_id, self.calendar_richard, "It should stay in Richard's calendar") + self.assertEqual(leave3.calendar_id, self.calendar_richard, "Global leave should stay in original calendar") + self.assertEqual(leave2.calendar_id, self.calendar_35h, "It should be transfered to the other calendar") + + # Transfer global leaves + self.calendar_richard.transfer_leaves_to(self.calendar_35h, resources=None, from_date=Date.to_date('2015-11-21')) + + self.assertEqual(leave3.calendar_id, self.calendar_35h, "Global leave should be transfered")
\ No newline at end of file diff --git a/addons/hr_contract/tests/test_contract.py b/addons/hr_contract/tests/test_contract.py index 39d6743d275..ca05600929c 100644 --- a/addons/hr_contract/tests/test_contract.py +++ b/addons/hr_contract/tests/test_contract.py @@ -1,22 +1,16 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from datetime import datetime -from odoo.tests.common import TransactionCase +from datetime import datetime, date from odoo.exceptions import ValidationError from dateutil.relativedelta import relativedelta +from odoo.addons.hr_contract.tests.common import TestContractBase -class TestHrContracts(TransactionCase): +class TestHrContracts(TestContractBase): def setUp(self): super(TestHrContracts, self).setUp() self.contracts = self.env['hr.contract'].with_context(tracking_disable=True) - self.employee = self.env['hr.employee'].create({ - 'name': 'Richard', - 'gender': 'male', - 'birthday': '1984-05-01', - 'country_id': self.ref('base.be'), - }) def create_contract(self, state, start, end=None): return self.env['hr.contract'].create({ @@ -84,3 +78,12 @@ class TestHrContracts(TransactionCase): with self.assertRaises(ValidationError): # No end self.create_contract('incoming', datetime.strptime('2015-01-01', '%Y-%m-%d').date()) + + def test_set_employee_contract_create(self): + contract = self.create_contract('open', date(2018, 1, 1), date(2018, 1, 2)) + self.assertEqual(self.employee.contract_id, contract) + + def test_set_employee_contract_write(self): + contract = self.create_contract('draft', date(2018, 1, 1), date(2018, 1, 2)) + contract.state = 'open' + self.assertEqual(self.employee.contract_id, contract) |
