diff --git a/addons/hr_holidays/__openerp__.py b/addons/hr_holidays/__openerp__.py index 1c35c9173ca..50c64491ee4 100644 --- a/addons/hr_holidays/__openerp__.py +++ b/addons/hr_holidays/__openerp__.py @@ -51,10 +51,6 @@ A synchronization with an internal agenda (Meetings of the CRM module) is also p 'qweb': [ 'static/src/xml/*.xml', ], - 'test': [ - 'test/test_hr_holiday.yml', - 'test/hr_holidays_report.yml', - ], 'installable': True, 'application': True, 'auto_install': False, diff --git a/addons/hr_holidays/test/hr_holidays_report.yml b/addons/hr_holidays/test/hr_holidays_report.yml deleted file mode 100644 index 19189e34461..00000000000 --- a/addons/hr_holidays/test/hr_holidays_report.yml +++ /dev/null @@ -1,22 +0,0 @@ -- - Print the HR Holidays(Summary Department) Report through the wizard -- - !python {model: hr.holidays}: | - import time - ctx={} - ctx.update({'model': 'hr.department','active_ids': [ref('hr.employee_fp'),ref('hr.employee_qdp'),ref('hr.employee_al')]}) - data_dict = {'date_from': time.strftime('%Y-%m-01'), 'depts' : [(6,0,[ref('hr.dep_sales')])],'holiday_type' : 'Approved'} - from openerp.tools import test_reports - test_reports.try_report_action(cr, uid, 'action_hr_holidays_summary_dept',wiz_data=data_dict, context=ctx, our_module='hr_holidays') - -- - Print the HR Holidays(Summary Employee) Report through the wizard -- - !python {model: hr.holidays}: | - import time - ctx={} - ctx.update({'model': 'hr.employee','active_ids': [ref('hr.employee_fp'),ref('hr.employee_qdp'),ref('hr.employee_al')]}) - data_dict = {'date_from': time.strftime('%Y-%m-01'), 'emp' : [(6,0,[ref('hr.employee_fp'),ref('hr.employee_qdp'),ref('hr.employee_al')])],'holiday_type' : 'Approved'} - from openerp.tools import test_reports - test_reports.try_report_action(cr, uid, 'action_hr_holidays_summary_employee',wiz_data=data_dict, context=ctx, our_module='hr_holidays') - diff --git a/addons/hr_holidays/test/test_hr_holiday.yml b/addons/hr_holidays/test/test_hr_holiday.yml deleted file mode 100644 index 1c00692c1f7..00000000000 --- a/addons/hr_holidays/test/test_hr_holiday.yml +++ /dev/null @@ -1,28 +0,0 @@ -- - In order to test the hr_holiday module in OpenERP, I will Allocate leaves for Employee and manage leaves and leaves requests. -- - I assign the dates in the holiday request. -- - !record {model: hr.holidays, id: hr_holiday1}: - name: Sick Leave - holiday_status_id: holiday_status_cl - date_from: !eval time.strftime('%Y-%m-10 10:00:00') - date_to: !eval time.strftime('%Y-%m-11 19:00:00') - employee_id: hr.employee_fp - type: remove -- - I find a small mistake on my leave request to I click on "Refuse" button to correct a mistake. -- - !workflow {model: hr.holidays, action: refuse, ref: hr_holidays_employee1_cl} -- - I again set to draft and then confirm. -- - !python {model: hr.holidays}: | - self.holidays_reset(cr, uid, [ref('hr_holidays_employee1_cl')]) - self.signal_workflow(cr, uid, [ref('hr_holidays_employee1_cl')], 'confirm') -- - I validate the holiday request by clicking on "To Approve" button. -- - !workflow {model: hr.holidays, action: validate, ref: hr_holidays_employee1_cl} -- - I can also see Summary of Employee's holiday by using "Employee's Holidays" Report. This report will allows to choose to print holidays with state Confirmed, Validated or both. diff --git a/addons/hr_holidays/tests/common.py b/addons/hr_holidays/tests/common.py index 117bb9fbaf6..f6ea354ff6b 100644 --- a/addons/hr_holidays/tests/common.py +++ b/addons/hr_holidays/tests/common.py @@ -1,80 +1,62 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from openerp.tests import common +from odoo.tests import common class TestHrHolidaysBase(common.TransactionCase): def setUp(self): super(TestHrHolidaysBase, self).setUp() - cr, uid = self.cr, self.uid # Usefull models - self.hr_employee = self.registry('hr.employee') - self.hr_holidays = self.registry('hr.holidays') - self.hr_holidays_status = self.registry('hr.holidays.status') - self.res_users = self.registry('res.users') - self.res_partner = self.registry('res.partner') + self.Employee = self.env['hr.employee'] + self.Holidays = self.env['hr.holidays'] + self.HolidaysStatus = self.env['hr.holidays.status'] + self.Partner = self.env['res.partner'] + self.Users = self.env['res.users'].with_context(no_reset_password=True) # Find Employee group - group_employee_ref = self.registry('ir.model.data').get_object_reference(cr, uid, 'base', 'group_user') - self.group_employee_id = group_employee_ref and group_employee_ref[1] or False + group_employee = self.env.ref('base.group_user', False) + self.group_employee_id = group_employee and group_employee.id or False # Find Hr User group - group_hr_user_ref = self.registry('ir.model.data').get_object_reference(cr, uid, 'base', 'group_hr_user') - self.group_hr_user_ref_id = group_hr_user_ref and group_hr_user_ref[1] or False + group_hr_user = self.env.ref('base.group_hr_user', False) + self.group_hr_user_id = group_hr_user and group_hr_user.id or False # Find Hr Manager group - group_hr_manager_ref = self.registry('ir.model.data').get_object_reference(cr, uid, 'base', 'group_hr_manager') - self.group_hr_manager_ref_id = group_hr_manager_ref and group_hr_manager_ref[1] or False - - # Test partners to use through the various tests - self.hr_partner_id = self.res_partner.create(cr, uid, { - 'name': 'Gertrude AgrolaitPartner', - 'email': 'gertrude.partner@agrolait.com', - }) - self.email_partner_id = self.res_partner.create(cr, uid, { - 'name': 'Patrick Ratatouille', - 'email': 'patrick.ratatouille@agrolait.com', - }) + group_hr_manager = self.env.ref('base.group_hr_manager', False) + self.group_hr_manager_id = group_hr_manager and group_hr_manager.id or False # Test users to use through the various tests - self.user_hruser_id = self.res_users.create(cr, uid, { + self.user_hruser_id = self.Users.create({ 'name': 'Armande HrUser', 'login': 'Armande', 'alias_name': 'armande', 'email': 'armande.hruser@example.com', - 'groups_id': [(6, 0, [self.group_employee_id, self.group_hr_user_ref_id])] - }, {'no_reset_password': True}) - self.user_hrmanager_id = self.res_users.create(cr, uid, { + 'groups_id': [(6, 0, [self.group_employee_id, self.group_hr_user_id])] + }).id + self.user_hrmanager_id = self.Users.create({ 'name': 'Bastien HrManager', 'login': 'bastien', 'alias_name': 'bastien', 'email': 'bastien.hrmanager@example.com', - 'groups_id': [(6, 0, [self.group_employee_id, self.group_hr_manager_ref_id])] - }, {'no_reset_password': True}) - self.user_none_id = self.res_users.create(cr, uid, { - 'name': 'Charlie Avotbonkeur', - 'login': 'charlie', - 'alias_name': 'charlie', - 'email': 'charlie.noone@example.com', - 'groups_id': [(6, 0, [])] - }, {'no_reset_password': True}) - self.user_employee_id = self.res_users.create(cr, uid, { + 'groups_id': [(6, 0, [self.group_employee_id, self.group_hr_manager_id])] + }).id + self.user_employee_id = self.Users.create({ 'name': 'David Employee', 'login': 'david', 'alias_name': 'david', 'email': 'david.employee@example.com', 'groups_id': [(6, 0, [self.group_employee_id])] - }, {'no_reset_password': True}) + }).id # Hr Data - self.employee_emp_id = self.hr_employee.create(cr, uid, { + self.employee_emp_id = self.Employee.create({ 'name': 'David Employee', 'user_id': self.user_employee_id, - }) - self.employee_hruser_id = self.hr_employee.create(cr, uid, { + }).id + self.employee_hruser_id = self.Employee.create({ 'name': 'Armande HrUser', 'user_id': self.user_hruser_id, - }) + }).id diff --git a/addons/hr_holidays/tests/test_holidays_flow.py b/addons/hr_holidays/tests/test_holidays_flow.py index ba8037758bf..7bd160d908f 100644 --- a/addons/hr_holidays/tests/test_holidays_flow.py +++ b/addons/hr_holidays/tests/test_holidays_flow.py @@ -1,20 +1,19 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. - from datetime import datetime from dateutil.relativedelta import relativedelta -from openerp.addons.hr_holidays.tests.common import TestHrHolidaysBase -from openerp.exceptions import AccessError -from openerp.exceptions import ValidationError -from openerp.tools import mute_logger +from odoo.exceptions import AccessError, ValidationError +from odoo.tools import mute_logger, test_reports + +from odoo.addons.hr_holidays.tests.common import TestHrHolidaysBase + class TestHolidaysFlow(TestHrHolidaysBase): @mute_logger('openerp.addons.base.ir.ir_model', 'openerp.models') def test_00_leave_request_flow(self): """ Testing leave request flow """ - cr, uid = self.cr, self.uid def _check_holidays_status(holiday_status, ml, lt, rl, vrl): self.assertEqual(holiday_status.max_leaves, ml, @@ -28,22 +27,23 @@ class TestHolidaysFlow(TestHrHolidaysBase): # HrUser creates some holiday statuses -> crash because only HrManagers should do this with self.assertRaises(AccessError): - self.holidays_status_dummy = self.hr_holidays_status.create(cr, self.user_hruser_id, { + self.HolidaysStatus.sudo(self.user_hruser_id).create({ 'name': 'UserCheats', 'limit': True, }) # HrManager creates some holiday statuses - self.holidays_status_0 = self.hr_holidays_status.create(cr, self.user_hrmanager_id, { + HolidayStatusManagerGroup = self.HolidaysStatus.sudo(self.user_hrmanager_id) + HolidayStatusManagerGroup.create({ 'name': 'WithMeetingType', 'limit': True, - 'categ_id': self.registry('calendar.event.type').create(cr, self.user_hrmanager_id, {'name': 'NotLimitedMeetingType'}), + 'categ_id': self.env['calendar.event.type'].sudo(self.user_hrmanager_id).create({'name': 'NotLimitedMeetingType'}).id }) - self.holidays_status_1 = self.hr_holidays_status.create(cr, self.user_hrmanager_id, { + self.holidays_status_1 = HolidayStatusManagerGroup.create({ 'name': 'NotLimited', 'limit': True, }) - self.holidays_status_2 = self.hr_holidays_status.create(cr, self.user_hrmanager_id, { + self.holidays_status_2 = HolidayStatusManagerGroup.create({ 'name': 'Limited', 'limit': False, 'double_validation': True, @@ -54,39 +54,37 @@ class TestHolidaysFlow(TestHrHolidaysBase): # -------------------------------------------------- # Employee creates a leave request for another employee -> should crash + HolidaysEmployeeGroup = self.Holidays.sudo(self.user_employee_id) with self.assertRaises(ValidationError): - self.hr_holidays.create(cr, self.user_employee_id, { + HolidaysEmployeeGroup.create({ 'name': 'Hol10', 'employee_id': self.employee_hruser_id, - 'holiday_status_id': self.holidays_status_1, + 'holiday_status_id': self.holidays_status_1.id, 'date_from': (datetime.today() - relativedelta(days=1)), 'date_to': datetime.today(), 'number_of_days_temp': 1, }) - ids = self.hr_holidays.search(cr, uid, [('name', '=', 'Hol10')]) - self.hr_holidays.unlink(cr, uid, ids) + self.Holidays.search([('name', '=', 'Hol10')]).unlink() # Employee creates a leave request in a no-limit category - hol1_id = self.hr_holidays.create(cr, self.user_employee_id, { + hol1_employee_group = HolidaysEmployeeGroup.create({ 'name': 'Hol11', 'employee_id': self.employee_emp_id, - 'holiday_status_id': self.holidays_status_1, + 'holiday_status_id': self.holidays_status_1.id, 'date_from': (datetime.today() - relativedelta(days=1)), 'date_to': datetime.today(), 'number_of_days_temp': 1, }) - hol1 = self.hr_holidays.browse(cr, self.user_hruser_id, hol1_id) - self.assertEqual(hol1.state, 'confirm', 'hr_holidays: newly created leave request should be in confirm state') + hol1_user_group = hol1_employee_group.sudo(self.user_hruser_id) + self.assertEqual(hol1_user_group.state, 'confirm', 'hr_holidays: newly created leave request should be in confirm state') # Employee validates its leave request -> should not work - self.hr_holidays.signal_workflow(cr, self.user_employee_id, [hol1_id], 'validate') - hol1.refresh() - self.assertEqual(hol1.state, 'confirm', 'hr_holidays: employee should not be able to validate its own leave request') + hol1_employee_group.signal_workflow('validate') + self.assertEqual(hol1_user_group.state, 'confirm', 'hr_holidays: employee should not be able to validate its own leave request') # HrUser validates the employee leave request - self.hr_holidays.signal_workflow(cr, self.user_hrmanager_id, [hol1_id], 'validate') - hol1.refresh() - self.assertEqual(hol1.state, 'validate', 'hr_holidays: validates leave request should be in validate state') + hol1_user_group.signal_workflow('validate') + self.assertEqual(hol1_user_group.state, 'validate', 'hr_holidays: validates leave request should be in validate state') # -------------------------------------------------- # Case2: limited type of leave request @@ -94,10 +92,10 @@ class TestHolidaysFlow(TestHrHolidaysBase): # Employee creates a new leave request at the same time -> crash, avoid interlapping with self.assertRaises(ValidationError): - self.hr_holidays.create(cr, self.user_employee_id, { + HolidaysEmployeeGroup.create({ 'name': 'Hol21', 'employee_id': self.employee_emp_id, - 'holiday_status_id': self.holidays_status_1, + 'holiday_status_id': self.holidays_status_1.id, 'date_from': (datetime.today() - relativedelta(days=1)).strftime('%Y-%m-%d %H:%M'), 'date_to': datetime.today(), 'number_of_days_temp': 1, @@ -105,87 +103,132 @@ class TestHolidaysFlow(TestHrHolidaysBase): # Employee creates a leave request in a limited category -> crash, not enough days left with self.assertRaises(ValidationError): - self.hr_holidays.create(cr, self.user_employee_id, { + HolidaysEmployeeGroup.create({ 'name': 'Hol22', 'employee_id': self.employee_emp_id, - 'holiday_status_id': self.holidays_status_2, + 'holiday_status_id': self.holidays_status_2.id, 'date_from': (datetime.today() + relativedelta(days=0)).strftime('%Y-%m-%d %H:%M'), 'date_to': (datetime.today() + relativedelta(days=1)), 'number_of_days_temp': 1, }) # Clean transaction - self.hr_holidays.unlink(cr, uid, self.hr_holidays.search(cr, uid, [('name', 'in', ['Hol21', 'Hol22'])])) + self.Holidays.search([('name', 'in', ['Hol21', 'Hol22'])]).unlink() # HrUser allocates some leaves to the employee - aloc1_id = self.hr_holidays.create(cr, self.user_hruser_id, { + aloc1_user_group = self.Holidays.sudo(self.user_hruser_id).create({ 'name': 'Days for limited category', 'employee_id': self.employee_emp_id, - 'holiday_status_id': self.holidays_status_2, + 'holiday_status_id': self.holidays_status_2.id, 'type': 'add', 'number_of_days_temp': 2, }) # HrUser validates the allocation request - self.hr_holidays.signal_workflow(cr, self.user_hruser_id, [aloc1_id], 'validate') - self.hr_holidays.signal_workflow(cr, self.user_hruser_id, [aloc1_id], 'second_validate') + aloc1_user_group.signal_workflow('validate') + aloc1_user_group.signal_workflow('second_validate') # Checks Employee has effectively some days left - hol_status_2 = self.hr_holidays_status.browse(cr, self.user_employee_id, self.holidays_status_2) - _check_holidays_status(hol_status_2, 2.0, 0.0, 2.0, 2.0) + hol_status_2_employee_group = self.holidays_status_2.sudo(self.user_employee_id) + _check_holidays_status(hol_status_2_employee_group, 2.0, 0.0, 2.0, 2.0) # Employee creates a leave request in the limited category, now that he has some days left - hol2_id = self.hr_holidays.create(cr, self.user_employee_id, { + hol2 = HolidaysEmployeeGroup.create({ 'name': 'Hol22', 'employee_id': self.employee_emp_id, - 'holiday_status_id': self.holidays_status_2, + 'holiday_status_id': self.holidays_status_2.id, 'date_from': (datetime.today() + relativedelta(days=2)).strftime('%Y-%m-%d %H:%M'), 'date_to': (datetime.today() + relativedelta(days=3)), 'number_of_days_temp': 1, }) - hol2 = self.hr_holidays.browse(cr, self.user_hruser_id, hol2_id) + hol2_user_group = hol2.sudo(self.user_hruser_id) # Check left days: - 1 virtual remaining day - hol_status_2.refresh() - _check_holidays_status(hol_status_2, 2.0, 0.0, 2.0, 1.0) + _check_holidays_status(hol_status_2_employee_group, 2.0, 0.0, 2.0, 1.0) # HrUser validates the first step - self.hr_holidays.signal_workflow(cr, self.user_hruser_id, [hol2_id], 'validate') - hol2.refresh() + hol2_user_group.signal_workflow('validate') self.assertEqual(hol2.state, 'validate1', 'hr_holidays: first validation should lead to validate1 state') # HrUser validates the second step - self.hr_holidays.signal_workflow(cr, self.user_hruser_id, [hol2_id], 'second_validate') - hol2.refresh() + hol2_user_group.signal_workflow('second_validate') self.assertEqual(hol2.state, 'validate', 'hr_holidays: second validation should lead to validate state') # Check left days: - 1 day taken - hol_status_2.refresh() - _check_holidays_status(hol_status_2, 2.0, 1.0, 1.0, 1.0) + _check_holidays_status(hol_status_2_employee_group, 2.0, 1.0, 1.0, 1.0) # HrManager finds an error: he refuses the leave request - self.hr_holidays.signal_workflow(cr, self.user_hrmanager_id, [hol2_id], 'refuse') - hol2.refresh() + hol2.sudo(self.user_hrmanager_id).signal_workflow('refuse') self.assertEqual(hol2.state, 'refuse', 'hr_holidays: refuse should lead to refuse state') # Check left days: 2 days left again - hol_status_2.refresh() - _check_holidays_status(hol_status_2, 2.0, 0.0, 2.0, 2.0) + _check_holidays_status(hol_status_2_employee_group, 2.0, 0.0, 2.0, 2.0) # Annoyed, HrUser tries to fix its error and tries to reset the leave request -> does not work, only HrManager - self.hr_holidays.signal_workflow(cr, self.user_hruser_id, [hol2_id], 'reset') + hol2_user_group.signal_workflow('reset') self.assertEqual(hol2.state, 'refuse', 'hr_holidays: hr_user should not be able to reset a refused leave request') # HrManager resets the request - self.hr_holidays.signal_workflow(cr, self.user_hrmanager_id, [hol2_id], 'reset') - hol2.refresh() + hol2_manager_group = hol2.sudo(self.user_hrmanager_id) + hol2_manager_group.signal_workflow('reset') self.assertEqual(hol2.state, 'draft', 'hr_holidays: resetting should lead to draft state') # HrManager changes the date and put too much days -> crash when confirming - self.hr_holidays.write(cr, self.user_hrmanager_id, [hol2_id], { + hol2_manager_group.write({ 'date_from': (datetime.today() + relativedelta(days=4)).strftime('%Y-%m-%d %H:%M'), 'date_to': (datetime.today() + relativedelta(days=7)), 'number_of_days_temp': 4, }) with self.assertRaises(ValidationError): - self.hr_holidays.signal_workflow(cr, self.user_hrmanager_id, [hol2_id], 'confirm') + hol2_manager_group.signal_workflow('confirm') + + # cl can be of maximum 20 days for employee_fp + hol3_status = self.env.ref('hr_holidays.holiday_status_cl') + # I assign the dates in the holiday request for 1 day + hol3 = self.Holidays.create({ + 'name': 'Sick Leave', + 'holiday_status_id': hol3_status.id, + 'date_from': datetime.today().strftime('%Y-%m-10 10:00:00'), + 'date_to': datetime.today().strftime('%Y-%m-11 19:00:00'), + 'employee_id': self.ref('hr.employee_fp'), + 'type': 'remove', + 'number_of_days_temp': 1 + }) + # I find a small mistake on my leave request to I click on "Refuse" button to correct a mistake. + hol3.signal_workflow('refuse') + self.assertEqual(hol3.state, 'refuse', 'hr_holidays: refuse should lead to refuse state') + # I again set to draft and then confirm. + hol3.signal_workflow('reset') + self.assertEqual(hol3.state, 'draft', 'hr_holidays: resetting should lead to draft state') + hol3.signal_workflow('confirm') + self.assertEqual(hol3.state, 'confirm', 'hr_holidays: confirming should lead to confirm state') + # I validate the holiday request by clicking on "To Approve" button. + hol3.signal_workflow('validate') + self.assertEqual(hol3.state, 'validate', 'hr_holidays: validation should lead to validate state') + # Check left days for casual leave: 19 days left + _check_holidays_status(hol3_status, 20.0, 1.0, 19.0, 19.0) + + def test_10_leave_summary_reports(self): + # Print the HR Holidays(Summary Department) Report through the wizard + ctx = { + 'model': 'hr.department', + 'active_ids': [self.ref('hr.employee_fp'), self.ref('hr.employee_qdp'), self.ref('hr.employee_al')] + } + data_dict = { + 'date_from': datetime.today().strftime('%Y-%m-01'), + 'depts': [(6, 0, [self.ref('hr.dep_sales')])], + 'holiday_type': 'Approved' + } + test_reports.try_report_action(self.env.cr, self.env.uid, 'action_hr_holidays_summary_dept', wiz_data=data_dict, context=ctx, our_module='hr_holidays') + + # Print the HR Holidays(Summary Employee) Report through the wizard + ctx = { + 'model': 'hr.employee', + 'active_ids': [self.ref('hr.employee_fp'), self.ref('hr.employee_qdp'), self.ref('hr.employee_al')] + } + data_dict = { + 'date_from': datetime.today().strftime('%Y-%m-01'), + 'emp': [(6, 0, [self.ref('hr.employee_fp'), self.ref('hr.employee_qdp'), self.ref('hr.employee_al')])], + 'holiday_type': 'Approved' + } + test_reports.try_report_action(self.env.cr, self.env.uid, 'action_hr_holidays_summary_employee', wiz_data=data_dict, context=ctx, our_module='hr_holidays')