[FIX] hr_holidays: Make tests demo data independent
Part-of: odoo/odoo#146649
This commit is contained in:
@@ -47,11 +47,7 @@ class TestAutomation(TransactionCaseWithUserDemo):
|
||||
bilbo.name = "Bilbo"
|
||||
self.assertFalse(bilbo.active)
|
||||
|
||||
<<<<<<< HEAD
|
||||
def test_02_on_create_or_write_restricted(self):
|
||||
=======
|
||||
def test_02_on_create_restricted(self):
|
||||
>>>>>>> 31f52b97943c ([FIX] base_automation: Make tests demo data independent)
|
||||
""" on_create action with low portal user """
|
||||
model = self.env.ref("base.model_ir_filters")
|
||||
automation = self.env["base.automation"].create({
|
||||
|
||||
@@ -85,7 +85,7 @@ registry.category("web_tour.tours").add('hr_holidays_tour', {
|
||||
position: 'bottom',
|
||||
},
|
||||
{
|
||||
trigger: `tr.o_data_row:first:not(:has(button[name="action_approve"]))`,
|
||||
trigger: `tr.o_data_row:first:not(:has(button[name="action_approve"])),table tbody:not(tr.o_data_row)`,
|
||||
content: "Verify leave is approved",
|
||||
auto: true,
|
||||
isCheck: true,
|
||||
|
||||
@@ -11,6 +11,7 @@ class TestHrHolidaysCommon(common.TransactionCase):
|
||||
def setUpClass(cls):
|
||||
super(TestHrHolidaysCommon, cls).setUpClass()
|
||||
cls.env.user.tz = 'Europe/Brussels'
|
||||
cls.env.user.company_id.resource_calendar_id.tz = "Europe/Brussels"
|
||||
|
||||
cls.company = cls.env['res.company'].create({'name': 'Test company'})
|
||||
cls.env.user.company_id = cls.company
|
||||
|
||||
@@ -11,7 +11,6 @@ class TestAutomaticLeaveDates(TestHrHolidaysCommon):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestAutomaticLeaveDates, cls).setUpClass()
|
||||
|
||||
cls.leave_type = cls.env['hr.leave.type'].create({
|
||||
'name': 'Automatic Test',
|
||||
'time_type': 'leave',
|
||||
|
||||
@@ -5,7 +5,7 @@ from datetime import date, datetime
|
||||
|
||||
from odoo import Command
|
||||
from odoo.tests import tagged
|
||||
from odoo.tests.common import TransactionCase
|
||||
from odoo.tests.common import TransactionCase, warmup
|
||||
|
||||
|
||||
@tagged('company_leave')
|
||||
@@ -16,6 +16,8 @@ class TestCompanyLeave(TransactionCase):
|
||||
def setUpClass(cls):
|
||||
super(TestCompanyLeave, cls).setUpClass()
|
||||
cls.company = cls.env['res.company'].create({'name': 'A company'})
|
||||
cls.company.resource_calendar_id.tz = "Europe/Brussels"
|
||||
|
||||
|
||||
cls.bank_holiday = cls.env['hr.leave.type'].create({
|
||||
'name': 'Bank Holiday',
|
||||
@@ -35,6 +37,7 @@ class TestCompanyLeave(TransactionCase):
|
||||
cls.employee = cls.env['hr.employee'].create({
|
||||
'name': 'My Employee',
|
||||
'company_id': cls.company.id,
|
||||
'tz': "Europe/Brussels",
|
||||
})
|
||||
|
||||
def test_leave_whole_company_01(self):
|
||||
@@ -260,6 +263,7 @@ class TestCompanyLeave(TransactionCase):
|
||||
self.assertEqual(all_leaves[2].number_of_days, 1)
|
||||
self.assertEqual(all_leaves[2].state, 'validate')
|
||||
|
||||
@warmup
|
||||
def test_leave_whole_company_07(self):
|
||||
# Test Case 7: Try to create a bank holidays for a lot of
|
||||
# employees, and check the performances
|
||||
@@ -289,7 +293,7 @@ class TestCompanyLeave(TransactionCase):
|
||||
})
|
||||
company_leave._compute_date_from_to()
|
||||
|
||||
with self.assertQueryCount(__system__=958, admin=867): # 770 community
|
||||
with self.assertQueryCount(__system__=830): # 770 community
|
||||
# Original query count: 1987
|
||||
# Without tracking/activity context keys: 5154
|
||||
company_leave.action_validate()
|
||||
|
||||
@@ -82,6 +82,8 @@ class TestHolidaysFlow(TestHrHolidaysCommon):
|
||||
Allocations = self.env['hr.leave.allocation']
|
||||
HolidaysStatus = self.env['hr.leave.type']
|
||||
|
||||
self.env.ref('hr.employee_admin').tz = "Europe/Brussels"
|
||||
|
||||
holiday_status_paid_time_off = self.env['hr.leave.type'].create({
|
||||
'name': 'Paid Time Off',
|
||||
'requires_allocation': 'yes',
|
||||
@@ -100,7 +102,7 @@ class TestHolidaysFlow(TestHrHolidaysCommon):
|
||||
'state': 'confirm',
|
||||
'date_from': time.strftime('%Y-%m-01'),
|
||||
}, {
|
||||
'name': 'Paid Time off for David',
|
||||
'name': 'Paid Time off for Admin',
|
||||
'holiday_status_id': holiday_status_paid_time_off.id,
|
||||
'number_of_days': 20,
|
||||
'employee_id': self.ref('hr.employee_admin'),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from datetime import date
|
||||
from odoo.addons.base.models.ir_model import MODULE_UNINSTALL_FLAG
|
||||
from odoo.tests import tagged, TransactionCase
|
||||
|
||||
@@ -8,6 +9,23 @@ from odoo.tests import tagged, TransactionCase
|
||||
@tagged('-at_install', 'post_install')
|
||||
class TestHrLeaveUninstall(TransactionCase):
|
||||
def test_unlink_model(self):
|
||||
employee = self.env['hr.employee'].create({
|
||||
'name': 'Test Employee'
|
||||
})
|
||||
holiday = self.env['hr.leave'].create({
|
||||
'name': 'Time Off',
|
||||
'employee_id': employee.id,
|
||||
'holiday_status_id': self.env.ref('hr_holidays.holiday_status_sl').id,
|
||||
'request_date_from': date(2020, 1, 7),
|
||||
'date_from': date(2020, 1, 7),
|
||||
'request_date_to': date(2020, 1, 9),
|
||||
'date_to': date(2020, 1, 9),
|
||||
'number_of_days': 3,
|
||||
})
|
||||
holiday.activity_schedule(
|
||||
'hr_holidays.mail_act_leave_approval',
|
||||
note='Test Note',
|
||||
user_id=self.env.user.id)
|
||||
model = self.env['ir.model'].search([('model', '=', 'hr.leave')])
|
||||
activity_type = self.env['mail.activity'].search([
|
||||
('res_model', '=', 'hr.leave')
|
||||
|
||||
@@ -46,6 +46,7 @@ class TestResourceCommon(TransactionCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestResourceCommon, cls).setUpClass()
|
||||
cls.env.company.resource_calendar_id.tz = "Europe/Brussels"
|
||||
|
||||
# UTC+1 winter, UTC+2 summer
|
||||
cls.calendar_jean = cls._define_calendar('40 Hours', [(8, 16, i, 1) for i in range(5)], 'Europe/Brussels')
|
||||
|
||||
@@ -369,8 +369,28 @@ class TestCalendar(TestResourceCommon):
|
||||
self.assertEqual(hours, 8)
|
||||
|
||||
def test_calendar_working_hours_count(self):
|
||||
calendar = self.env.ref('resource.resource_calendar_std_35h')
|
||||
calendar.tz = 'UTC'
|
||||
calendar = self.env['resource.calendar'].create({
|
||||
'name': 'Standard 35 hours/week',
|
||||
'company_id': self.env.company.id,
|
||||
'tz': 'UTC',
|
||||
'attendance_ids': [(5, 0, 0),
|
||||
(0, 0, {'name': 'Monday Morning', 'dayofweek': '0', 'hour_from': 8, 'hour_to': 12, 'day_period': 'morning'}),
|
||||
(0, 0, {'name': 'Monday Lunch', 'dayofweek': '0', 'hour_from': 12, 'hour_to': 13, 'day_period': 'lunch'}),
|
||||
(0, 0, {'name': 'Monday Afternoon', 'dayofweek': '0', 'hour_from': 13, 'hour_to': 16, 'day_period': 'afternoon'}),
|
||||
(0, 0, {'name': 'Tuesday Morning', 'dayofweek': '1', 'hour_from': 8, 'hour_to': 12, 'day_period': 'morning'}),
|
||||
(0, 0, {'name': 'Tuesday Lunch', 'dayofweek': '1', 'hour_from': 12, 'hour_to': 13, 'day_period': 'lunch'}),
|
||||
(0, 0, {'name': 'Tuesday Afternoon', 'dayofweek': '1', 'hour_from': 13, 'hour_to': 16, 'day_period': 'afternoon'}),
|
||||
(0, 0, {'name': 'Wednesday Morning', 'dayofweek': '2', 'hour_from': 8, 'hour_to': 12, 'day_period': 'morning'}),
|
||||
(0, 0, {'name': 'Wednesday Lunch', 'dayofweek': '2', 'hour_from': 12, 'hour_to': 13, 'day_period': 'lunch'}),
|
||||
(0, 0, {'name': 'Wednesday Afternoon', 'dayofweek': '2', 'hour_from': 13, 'hour_to': 16, 'day_period': 'afternoon'}),
|
||||
(0, 0, {'name': 'Thursday Morning', 'dayofweek': '3', 'hour_from': 8, 'hour_to': 12, 'day_period': 'morning'}),
|
||||
(0, 0, {'name': 'Thursday Lunch', 'dayofweek': '3', 'hour_from': 12, 'hour_to': 13, 'day_period': 'lunch'}),
|
||||
(0, 0, {'name': 'Thursday Afternoon', 'dayofweek': '3', 'hour_from': 13, 'hour_to': 16, 'day_period': 'afternoon'}),
|
||||
(0, 0, {'name': 'Friday Morning', 'dayofweek': '4', 'hour_from': 8, 'hour_to': 12, 'day_period': 'morning'}),
|
||||
(0, 0, {'name': 'Friday Lunch', 'dayofweek': '4', 'hour_from': 12, 'hour_to': 13, 'day_period': 'lunch'}),
|
||||
(0, 0, {'name': 'Friday Afternoon', 'dayofweek': '4', 'hour_from': 13, 'hour_to': 16, 'day_period': 'afternoon'})
|
||||
],
|
||||
})
|
||||
res = calendar.get_work_hours_count(
|
||||
fields.Datetime.from_string('2017-05-03 14:03:00'), # Wednesday (8:00-12:00, 13:00-16:00)
|
||||
fields.Datetime.from_string('2017-05-04 11:03:00'), # Thursday (8:00-12:00, 13:00-16:00)
|
||||
|
||||
Reference in New Issue
Block a user