[REF] pms: reorder and rename tests

This commit is contained in:
miguelpadin
2024-02-22 13:54:41 +00:00
committed by Darío Lodeiros
parent e26bf69813
commit 8bac4ea6d0
3 changed files with 370 additions and 467 deletions

View File

@@ -11,435 +11,8 @@ class TestPmsHousekeepingTask(TestPms):
def setUp(self):
super().setUp()
@freeze_time("2000-01-04")
def test_no_create_overnight_task_when_it_shouldnt_when_no_overnight(self):
def test_task_max_inheritance(self):
# ARRANGE
# create task type
self.env["pms.housekeeping.task.type"].create(
{
"name": "Task Type 1",
"is_overnight": True,
"days_after_clean_overnight": 2,
}
)
# ACT
# call method to create task
self.env["pms.housekeeping.task"].generate_tasks(self.pms_property1)
# ASSERT
# search for the task
housekeeping_task = self.env["pms.housekeeping.task"].search(
[("room_id", "=", self.room1.id)]
)
# Verify that the housekeeping task is not created
self.assertFalse(housekeeping_task, "Housekeeping task shouldn't be created")
@freeze_time("2000-01-10")
def test_create_overnight_task_when_it_should_be_created_with_different_dates(self):
# ARRANGE
# create reservation with checkin today
self.env["pms.reservation"].create(
{
"checkin": datetime.today(),
"checkout": datetime.today() + timedelta(days=7),
"room_type_id": self.room_type1.id,
"partner_id": self.partner1.id,
"pms_property_id": self.pms_property1.id,
"pricelist_id": self.pricelist1.id,
"sale_channel_origin_id": self.sale_channel1.id,
}
)
# create task type
self.env["pms.housekeeping.task.type"].create(
{
"name": "Task Type 1",
"is_overnight": True,
"days_after_clean_overnight": 2,
}
)
# Define a list of dates to iterate over
test_dates = [
"2000-01-12",
"2000-01-14",
"2000-01-16",
]
for test_date in test_dates:
with self.subTest(test_date=test_date):
# Freeze time to the current test date
with freeze_time(test_date):
# ACT
# call method to create task
self.env["pms.housekeeping.task"].generate_tasks(self.pms_property1)
# ASSERT
# search for the task
housekeeping_task = self.env["pms.housekeeping.task"].search(
[("room_id", "=", self.room1.id), ("task_date", "=", test_date)]
)
# Verify that the housekeeping task is created
self.assertTrue(
housekeeping_task, "Housekeeping task should be created"
)
@freeze_time("2000-01-10")
def test_create_overnight_task_when_it_shouldnt_be_created_with_different_dates(
self,
):
# ARRANGE
# create reservation with checkin today
self.env["pms.reservation"].create(
{
"checkin": datetime.today(),
"checkout": datetime.today() + timedelta(days=7),
"room_type_id": self.room_type1.id,
"partner_id": self.partner1.id,
"pms_property_id": self.pms_property1.id,
"pricelist_id": self.pricelist1.id,
"sale_channel_origin_id": self.sale_channel1.id,
}
)
# create task type
self.env["pms.housekeeping.task.type"].create(
{
"name": "Task Type 1",
"is_overnight": True,
"days_after_clean_overnight": 2,
}
)
# Define a list of dates to iterate over
test_dates = [
"2000-01-11",
"2000-01-13",
"2000-01-15",
]
for test_date in test_dates:
with self.subTest(test_date=test_date):
# Freeze time to the current test date
with freeze_time(test_date):
# ACT
# call method to create task
self.env["pms.housekeeping.task"].generate_tasks(self.pms_property1)
# ASSERT
# search for the task
housekeeping_task = self.env["pms.housekeeping.task"].search(
[("room_id", "=", self.room1.id), ("task_date", "=", test_date)]
)
# Verify that the housekeeping task is created
self.assertFalse(
housekeeping_task, "Housekeeping task shouldn't be created"
)
###################
@freeze_time("2000-01-04")
def test_no_create_empty_task_when_it_shouldnt_when_no_empty(self):
# ARRANGE
# create task type
self.env["pms.housekeeping.task.type"].create(
{
"name": "Task Type 1",
"is_empty": True,
"days_after_clean_empty": 2,
}
)
# ACT
# call method to create task
self.env["pms.housekeeping.task"].generate_tasks(self.pms_property1)
# ASSERT
# search for the task
housekeeping_task = self.env["pms.housekeeping.task"].search(
[("room_id", "=", self.room1.id)]
)
# Verify that the housekeeping task is not created
self.assertFalse(housekeeping_task, "Housekeeping task shouldn't be created")
@freeze_time("2000-02-11")
def test_create_empty_task_when_it_should_be_created_with_different_dates(self):
# ARRANGE
# create reservation with checkout today - 10 days
self.env["pms.reservation"].create(
{
"checkin": datetime.today() + timedelta(days=-20),
"checkout": datetime.today() + timedelta(days=-10),
"room_type_id": self.room_type1.id,
"partner_id": self.partner1.id,
"pms_property_id": self.pms_property1.id,
"pricelist_id": self.pricelist1.id,
"sale_channel_origin_id": self.sale_channel1.id,
}
)
# create task type
self.env["pms.housekeeping.task.type"].create(
{"name": "Task Type 1", "is_empty": True, "days_after_clean_empty": 2}
)
# Define a list of dates to iterate over
test_dates = [
"2000-02-03",
"2000-02-05",
"2000-02-07",
]
for test_date in test_dates:
with self.subTest(test_date=test_date):
# Freeze time to the current test date
with freeze_time(test_date):
# ACT
# call method to create task
self.env["pms.housekeeping.task"].generate_tasks(self.pms_property1)
# ASSERT
# search for the task
housekeeping_task = self.env["pms.housekeeping.task"].search(
[("room_id", "=", self.room1.id), ("task_date", "=", test_date)]
)
# Verify that the housekeeping task is created
self.assertTrue(
housekeeping_task, "Housekeeping task should be created"
)
@freeze_time("2000-02-11")
def test_create_empty_task_when_it_shouldnt_be_created_with_different_dates(self):
# ARRANGE
# create reservation with checkout today - 10 days
self.env["pms.reservation"].create(
{
"checkin": datetime.today() + timedelta(days=-20),
"checkout": datetime.today() + timedelta(days=-10),
"room_type_id": self.room_type1.id,
"partner_id": self.partner1.id,
"pms_property_id": self.pms_property1.id,
"pricelist_id": self.pricelist1.id,
"sale_channel_origin_id": self.sale_channel1.id,
}
)
# create task type
self.env["pms.housekeeping.task.type"].create(
{"name": "Task Type 1", "is_empty": True, "days_after_clean_empty": 2}
)
# Define a list of dates to iterate over
test_dates = [
"2000-02-02",
"2000-02-04",
"2000-02-06",
]
for test_date in test_dates:
with self.subTest(test_date=test_date):
# Freeze time to the current test date
with freeze_time(test_date):
# ACT
# call method to create task
self.env["pms.housekeeping.task"].generate_tasks(self.pms_property1)
# ASSERT
# search for the task
housekeeping_task = self.env["pms.housekeeping.task"].search(
[("room_id", "=", self.room1.id), ("task_date", "=", test_date)]
)
# Verify that the housekeeping task is created
self.assertFalse(
housekeeping_task, "Housekeeping task should be created"
)
@freeze_time("2000-01-04")
def test_create_checkin_task_when_it_should_when_checkin(self):
# ARRANGE
# create task type
self.env["pms.housekeeping.task.type"].create(
{
"name": "Task Type 1",
"is_checkin": True,
}
)
# create reservation with checkin today
self.env["pms.reservation"].create(
{
"checkin": datetime.today(),
"checkout": datetime.today() + timedelta(days=3),
"room_type_id": self.room_type1.id,
"partner_id": self.partner1.id,
"pms_property_id": self.pms_property1.id,
"pricelist_id": self.pricelist1.id,
"sale_channel_origin_id": self.sale_channel1.id,
}
)
# ACT
# call method to create task
self.env["pms.housekeeping.task"].generate_tasks(self.pms_property1)
# ASSERT
# search for the task
housekeeping_task = self.env["pms.housekeeping.task"].search(
[("room_id", "=", self.room1.id)]
)
# Verify that the housekeeping task is not created
self.assertTrue(housekeeping_task, "Housekeeping task should be created")
@freeze_time("2000-01-04")
def test_no_create_checkin_task_when_it_shouldnt_when_no_checkin(self):
# ARRANGE
# create task type
self.env["pms.housekeeping.task.type"].create(
{
"name": "Task Type 1",
"is_checkin": True,
}
)
# ACT
# call method to create task
self.env["pms.housekeeping.task"].generate_tasks(self.pms_property1)
# ASSERT
# search for the task
housekeeping_task = self.env["pms.housekeeping.task"].search(
[("room_id", "=", self.room1.id)]
)
# Verify that the housekeeping task is not created
self.assertFalse(housekeeping_task, "Housekeeping task shouldn't be created")
@freeze_time("2000-01-04")
def test_create_checkout_task_when_it_should_when_checkout(self):
# ARRANGE
# create task type
self.env["pms.housekeeping.task.type"].create(
{
"name": "Task Type 1",
"is_checkout": True,
}
)
# create reservation with checkout today
self.env["pms.reservation"].create(
{
"checkin": datetime.today() + timedelta(days=-3),
"checkout": datetime.today(),
"room_type_id": self.room_type1.id,
"partner_id": self.partner1.id,
"pms_property_id": self.pms_property1.id,
"pricelist_id": self.pricelist1.id,
"sale_channel_origin_id": self.sale_channel1.id,
}
)
# ACT
# call method to create task
self.env["pms.housekeeping.task"].generate_tasks(self.pms_property1)
# ASSERT
# search for the task
housekeeping_task = self.env["pms.housekeeping.task"].search(
[("room_id", "=", self.room1.id)]
)
# Verify that the housekeeping task is not created
self.assertTrue(housekeeping_task, "Housekeeping task should be created")
@freeze_time("2000-01-04")
def test_no_create_checkout_task_when_it_shouldnt_when_no_checkout(self):
# ARRANGE
# create task type
self.env["pms.housekeeping.task.type"].create(
{
"name": "Task Type 1",
"is_checkout": True,
}
)
# ACT
# call method to create task
self.env["pms.housekeeping.task"].generate_tasks(self.pms_property1)
# ASSERT
# search for the task
housekeeping_task = self.env["pms.housekeeping.task"].search(
[("room_id", "=", self.room1.id)]
)
# Verify that the housekeeping task is not created
self.assertFalse(housekeeping_task, "Housekeeping task shouldn't be created")
@freeze_time("2000-01-04")
def test_create_task_childs(self):
# ARRANGE
# create task type
parent_task_type = self.env["pms.housekeeping.task.type"].create(
{
"name": "Task Type Parent",
"is_checkout": True,
}
)
child_task_type = self.env["pms.housekeeping.task.type"].create(
{
"name": "Task Type Child",
"is_checkout": True,
"parent_id": parent_task_type.id,
}
)
# create reservation with checkout today
self.env["pms.reservation"].create(
{
"checkin": datetime.today() + timedelta(days=-3),
"checkout": datetime.today(),
"room_type_id": self.room_type1.id,
"partner_id": self.partner1.id,
"pms_property_id": self.pms_property1.id,
"pricelist_id": self.pricelist1.id,
"sale_channel_origin_id": self.sale_channel1.id,
}
)
# ACT
# call method to create task
self.env["pms.housekeeping.task"].generate_tasks(self.pms_property1)
# ASSERT
# search for the task
housekeeping_task = self.env["pms.housekeeping.task"].search(
[("room_id", "=", self.room1.id), ("task_type_id", "=", child_task_type.id)]
)
# Verify that the housekeeping task is not created
self.assertTrue(housekeeping_task, "Child housekeeping task should be created")
def test_no_create_task_childs(self):
# ARRANGE
# create task type
self.env["pms.housekeeping.task.type"].create(
{
"name": "Task Type Parent",
"is_checkout": True,
}
)
# create reservation with checkout today
self.env["pms.reservation"].create(
{
"checkin": datetime.today() + timedelta(days=-3),
"checkout": datetime.today(),
"room_type_id": self.room_type1.id,
"partner_id": self.partner1.id,
"pms_property_id": self.pms_property1.id,
"pricelist_id": self.pricelist1.id,
"sale_channel_origin_id": self.sale_channel1.id,
}
)
# ACT
# call method to create task
self.env["pms.housekeeping.task"].generate_tasks(self.pms_property1)
# ASSERT
# search for the task
housekeeping_task = self.env["pms.housekeeping.task"].search(
[("room_id", "=", self.room1.id)]
)
# Verify that the housekeeping task childs is not created
self.assertFalse(
housekeeping_task.child_ids, "Child housekeeping task shouldn´t be created"
)
def test_no_create_grandchild_task(self):
# ARRANGE
# create task type
task_type = self.env["pms.housekeeping.task.type"].create(
{
"name": "Task Type Parent",
@@ -448,7 +21,7 @@ class TestPmsHousekeepingTask(TestPms):
)
parent_task = self.env["pms.housekeeping.task"].create(
{
"name": "Task",
"name": "Parent task",
"room_id": self.room1.id,
"task_type_id": task_type.id,
"task_date": datetime.today(),
@@ -456,7 +29,7 @@ class TestPmsHousekeepingTask(TestPms):
)
child_task = self.env["pms.housekeeping.task"].create(
{
"name": "Child Task",
"name": "Child task",
"room_id": self.room1.id,
"task_type_id": task_type.id,
"parent_id": parent_task.id,
@@ -464,10 +37,13 @@ class TestPmsHousekeepingTask(TestPms):
}
)
# ACT & ASSERT
with self.assertRaises(ValidationError, msg="Grandchild task shouldn´t exist."):
with self.assertRaises(
ValidationError,
msg="The maximum level of inheritance between tasks should be 2",
):
self.env["pms.housekeeping.task"].create(
{
"name": "Grandchild Task",
"name": "Grandchild task",
"room_id": self.room1.id,
"task_type_id": task_type.id,
"parent_id": child_task.id,
@@ -475,12 +51,11 @@ class TestPmsHousekeepingTask(TestPms):
}
)
def test_create_task_with_no_housekeeper(self):
def test_task_with_non_housekeeper_employee(self):
# ARRANGE
self.job_id = self.env["hr.job"].create(
{
"name": "Test Job",
"name": "Non housekeeper job",
}
)
self.employee = self.env["hr.employee"].create(
@@ -490,17 +65,14 @@ class TestPmsHousekeepingTask(TestPms):
"job_id": self.job_id.id,
}
)
# create task type
self.task_type = self.env["pms.housekeeping.task.type"].create(
{
"name": "Task Type 1",
"is_checkout": True,
}
)
# ACT & ASSERT
with self.assertRaises(
ValidationError, msg="Employee should have a housekeeper job"
ValidationError, msg="Task should be assigned to a housekeeper role"
):
self.env["pms.housekeeping.task"].create(
{
@@ -512,8 +84,7 @@ class TestPmsHousekeepingTask(TestPms):
}
)
def test_create_task_with_housekeeper(self):
def test_task_with_housekeeper_employee(self):
# ARRANGE
self.employee = self.env["hr.employee"].create(
{
@@ -522,14 +93,11 @@ class TestPmsHousekeepingTask(TestPms):
"job_id": self.env.ref("pms_housekeeping.housekeeping_job_id").id,
}
)
# create task type
self.task_type = self.env["pms.housekeeping.task.type"].create(
{
"name": "Task Type 1",
"is_checkout": True,
}
)
# ACT
self.task = self.env["pms.housekeeping.task"].create(
{
@@ -540,12 +108,10 @@ class TestPmsHousekeepingTask(TestPms):
"housekeeper_ids": [(6, 0, [self.employee.id])],
}
)
# ASSERT
self.assertTrue(self.task, "Housekeeping task should be created")
def test_task_housekeeper_room_inconsistency(self):
def test_task_inconsistency_between_room_id_and_housekeeper_properties(self):
# ARRANGE
self.pms_property2 = self.env["pms.property"].create(
{
@@ -569,18 +135,16 @@ class TestPmsHousekeepingTask(TestPms):
"property_ids": [(6, 0, [self.pms_property1.id])],
}
)
# create task type
self.task_type = self.env["pms.housekeeping.task.type"].create(
{
"name": "Task Type 1",
"is_checkout": True,
}
)
# ACT & ASSERT
with self.assertRaises(
ValidationError,
msg="The room and housekeeper should belong to the same property.",
msg="Task with inconsistency between room_id and "
"housekeeper properties should not be created",
):
self.env["pms.housekeeping.task"].create(
{
@@ -592,7 +156,7 @@ class TestPmsHousekeepingTask(TestPms):
}
)
def test_task_housekeeper_room_consistency(self):
def test_task_consistency_between_room_id_and_housekeeper_properties(self):
# ARRANGE
self.employee = self.env["hr.employee"].create(
{
@@ -602,14 +166,11 @@ class TestPmsHousekeepingTask(TestPms):
"property_ids": [(6, 0, [self.pms_property1.id])],
}
)
# create task type
self.task_type = self.env["pms.housekeeping.task.type"].create(
{
"name": "Task Type 1",
"is_checkout": True,
}
)
# ACT
task = self.env["pms.housekeeping.task"].create(
{
@@ -620,6 +181,341 @@ class TestPmsHousekeepingTask(TestPms):
"housekeeper_ids": [(6, 0, [self.employee.id])],
}
)
# ASSERT
self.assertTrue(task, "Housekeeping task should be created")
self.assertTrue(
task,
"Task with consistency between room_id and "
"housekeeper properties should be created",
)
# Tests generate_tasks method
@freeze_time("2000-01-10")
def test_task_generate_tasks_create_overnight(self):
# ARRANGE
self.env["pms.reservation"].create(
{
"checkin": datetime.today(),
"checkout": datetime.today() + timedelta(days=7),
"room_type_id": self.room_type1.id,
"partner_id": self.partner1.id,
"pms_property_id": self.pms_property1.id,
"pricelist_id": self.pricelist1.id,
"sale_channel_origin_id": self.sale_channel1.id,
}
)
self.env["pms.housekeeping.task.type"].create(
{
"name": "Task Type 1",
"is_overnight": True,
"days_after_clean_overnight": 2,
}
)
test_dates = ["2000-01-12", "2000-01-14", "2000-01-16"]
for test_date in test_dates:
with self.subTest(test_date=test_date):
with freeze_time(test_date):
# ACT
self.env["pms.housekeeping.task"].generate_tasks(self.pms_property1)
# ASSERT
housekeeping_task = self.env["pms.housekeeping.task"].search(
[("room_id", "=", self.room1.id), ("task_date", "=", test_date)]
)
self.assertTrue(
housekeeping_task, "Overnight tasks should be created"
)
@freeze_time("2000-01-10")
def test_task_generate_tasks_no_create_overnight_tasks(self):
# ARRANGE
self.env["pms.reservation"].create(
{
"checkin": datetime.today(),
"checkout": datetime.today() + timedelta(days=7),
"room_type_id": self.room_type1.id,
"partner_id": self.partner1.id,
"pms_property_id": self.pms_property1.id,
"pricelist_id": self.pricelist1.id,
"sale_channel_origin_id": self.sale_channel1.id,
}
)
self.env["pms.housekeeping.task.type"].create(
{
"name": "Task Type 1",
"is_overnight": True,
"days_after_clean_overnight": 2,
}
)
test_dates = ["2000-01-11", "2000-01-13", "2000-01-15"]
for test_date in test_dates:
with self.subTest(test_date=test_date):
with freeze_time(test_date):
# ACT
self.env["pms.housekeeping.task"].generate_tasks(self.pms_property1)
# ASSERT
housekeeping_task = self.env["pms.housekeeping.task"].search(
[("room_id", "=", self.room1.id), ("task_date", "=", test_date)]
)
self.assertFalse(
housekeeping_task, "Overnight tasks shouldn't be created"
)
@freeze_time("2000-01-04")
def test_task_generate_tasks_no_create_overnight_task_no_overnight_reservations(
self,
):
# ARRANGE
self.env["pms.housekeeping.task.type"].create(
{
"name": "Task Type 1",
"is_overnight": True,
"days_after_clean_overnight": 2,
}
)
# ACT
self.env["pms.housekeeping.task"].generate_tasks(self.pms_property1)
# ASSERT
housekeeping_task = self.env["pms.housekeeping.task"].search(
[("room_id", "=", self.room1.id)]
)
self.assertFalse(housekeeping_task, "Empty tasks shouldn't be created")
@freeze_time("2000-02-11")
def test_task_generate_tasks_create_empty_tasks(self):
# ARRANGE
self.env["pms.reservation"].create(
{
"checkin": datetime.today() + timedelta(days=-20),
"checkout": datetime.today() + timedelta(days=-10),
"room_type_id": self.room_type1.id,
"partner_id": self.partner1.id,
"pms_property_id": self.pms_property1.id,
"pricelist_id": self.pricelist1.id,
"sale_channel_origin_id": self.sale_channel1.id,
}
)
self.env["pms.housekeeping.task.type"].create(
{
"name": "Task Type 1",
"is_empty": True,
"days_after_clean_empty": 2,
}
)
test_dates = ["2000-02-03", "2000-02-05", "2000-02-07"]
for test_date in test_dates:
with self.subTest(test_date=test_date):
with freeze_time(test_date):
# ACT
self.env["pms.housekeeping.task"].generate_tasks(self.pms_property1)
# ASSERT
housekeeping_task = self.env["pms.housekeeping.task"].search(
[("room_id", "=", self.room1.id), ("task_date", "=", test_date)]
)
self.assertTrue(housekeeping_task, "Empty tasks should be created")
@freeze_time("2000-02-11")
def test_task_generate_tasks_no_create_empty_tasks(self):
# ARRANGE
self.env["pms.reservation"].create(
{
"checkin": datetime.today() + timedelta(days=-20),
"checkout": datetime.today() + timedelta(days=-10),
"room_type_id": self.room_type1.id,
"partner_id": self.partner1.id,
"pms_property_id": self.pms_property1.id,
"pricelist_id": self.pricelist1.id,
"sale_channel_origin_id": self.sale_channel1.id,
}
)
self.env["pms.housekeeping.task.type"].create(
{
"name": "Task Type 1",
"is_empty": True,
"days_after_clean_empty": 2,
}
)
test_dates = ["2000-02-02", "2000-02-04", "2000-02-06"]
for test_date in test_dates:
with self.subTest(test_date=test_date):
with freeze_time(test_date):
# ACT
self.env["pms.housekeeping.task"].generate_tasks(self.pms_property1)
# ASSERT
housekeeping_task = self.env["pms.housekeeping.task"].search(
[("room_id", "=", self.room1.id), ("task_date", "=", test_date)]
)
self.assertFalse(
housekeeping_task, "Empty tasks should not be created"
)
@freeze_time("2000-01-04")
def test_task_generate_tasks_no_create_empty_task_no_previous_checkouts(self):
# ARRANGE
self.env["pms.housekeeping.task.type"].create(
{
"name": "Task Type 1",
"is_empty": True,
"days_after_clean_empty": 2,
}
)
# ACT
self.env["pms.housekeeping.task"].generate_tasks(self.pms_property1)
# ASSERT
housekeeping_task = self.env["pms.housekeeping.task"].search(
[("room_id", "=", self.room1.id)]
)
self.assertFalse(housekeeping_task, "Empty tasks shouldn't be created")
@freeze_time("2000-01-04")
def test_task_generate_tasks_create_checkin_task(self):
# ARRANGE
self.env["pms.housekeeping.task.type"].create(
{
"name": "Task Type 1",
"is_checkin": True,
}
)
self.env["pms.reservation"].create(
{
"checkin": datetime.today(),
"checkout": datetime.today() + timedelta(days=3),
"room_type_id": self.room_type1.id,
"partner_id": self.partner1.id,
"pms_property_id": self.pms_property1.id,
"pricelist_id": self.pricelist1.id,
"sale_channel_origin_id": self.sale_channel1.id,
}
)
# ACT
self.env["pms.housekeeping.task"].generate_tasks(self.pms_property1)
# ASSERT
housekeeping_task = self.env["pms.housekeeping.task"].search(
[("room_id", "=", self.room1.id)]
)
self.assertTrue(housekeeping_task, "Checkin tasks should be created")
@freeze_time("2000-01-04")
def test_task_generate_tasks_no_create_checkin_task(self):
# ARRANGE
self.env["pms.housekeeping.task.type"].create(
{
"name": "Task Type 1",
"is_checkin": True,
}
)
# ACT
self.env["pms.housekeeping.task"].generate_tasks(self.pms_property1)
# ASSERT
housekeeping_task = self.env["pms.housekeeping.task"].search(
[("room_id", "=", self.room1.id)]
)
self.assertFalse(housekeeping_task, "Checkin task shouldn't be created")
@freeze_time("2000-01-04")
def test_task_generate_tasks_create_checkout_task(self):
# ARRANGE
self.env["pms.housekeeping.task.type"].create(
{
"name": "Task Type 1",
"is_checkout": True,
}
)
self.env["pms.reservation"].create(
{
"checkin": datetime.today() + timedelta(days=-3),
"checkout": datetime.today(),
"room_type_id": self.room_type1.id,
"partner_id": self.partner1.id,
"pms_property_id": self.pms_property1.id,
"pricelist_id": self.pricelist1.id,
"sale_channel_origin_id": self.sale_channel1.id,
}
)
# ACT
self.env["pms.housekeeping.task"].generate_tasks(self.pms_property1)
# ASSERT
housekeeping_task = self.env["pms.housekeeping.task"].search(
[("room_id", "=", self.room1.id)]
)
self.assertTrue(housekeeping_task, "Checkout task should be created")
@freeze_time("2000-01-04")
def test_task_generate_tasks_no_create_checkout_task(self):
# ARRANGE
self.env["pms.housekeeping.task.type"].create(
{
"name": "Task Type 1",
"is_checkout": True,
}
)
# ACT
self.env["pms.housekeeping.task"].generate_tasks(self.pms_property1)
# ASSERT
housekeeping_task = self.env["pms.housekeeping.task"].search(
[("room_id", "=", self.room1.id)]
)
self.assertFalse(housekeeping_task, "Checkout task shouldn't be created")
@freeze_time("2000-01-04")
def test_task_generate_tasks_create_child_task(self):
# ARRANGE
parent_task_type = self.env["pms.housekeeping.task.type"].create(
{
"name": "Task Type Parent",
"is_checkout": True,
}
)
child_task_type = self.env["pms.housekeeping.task.type"].create(
{
"name": "Task Type Child",
"is_checkout": True,
"parent_id": parent_task_type.id,
}
)
self.env["pms.reservation"].create(
{
"checkin": datetime.today() + timedelta(days=-3),
"checkout": datetime.today(),
"room_type_id": self.room_type1.id,
"partner_id": self.partner1.id,
"pms_property_id": self.pms_property1.id,
"pricelist_id": self.pricelist1.id,
"sale_channel_origin_id": self.sale_channel1.id,
}
)
# ACT
self.env["pms.housekeeping.task"].generate_tasks(self.pms_property1)
# ASSERT
housekeeping_task = self.env["pms.housekeeping.task"].search(
[
("room_id", "=", self.room1.id),
("task_type_id", "=", child_task_type.id),
]
)
self.assertTrue(housekeeping_task, "Child task should be created")
def test_task_generate_tasks_no_create_child_task(self):
# ARRANGE
self.env["pms.housekeeping.task.type"].create(
{
"name": "Task Type Parent",
"is_checkout": True,
}
)
self.env["pms.reservation"].create(
{
"checkin": datetime.today() + timedelta(days=-3),
"checkout": datetime.today(),
"room_type_id": self.room_type1.id,
"partner_id": self.partner1.id,
"pms_property_id": self.pms_property1.id,
"pricelist_id": self.pricelist1.id,
"sale_channel_origin_id": self.sale_channel1.id,
}
)
# ACT
self.env["pms.housekeeping.task"].generate_tasks(self.pms_property1)
# ASSERT
housekeeping_task = self.env["pms.housekeeping.task"].search(
[("room_id", "=", self.room1.id)]
)
self.assertFalse(housekeeping_task.child_ids, "Child task shouldn´t be created")

View File

@@ -7,7 +7,7 @@ class TestPmsHousekeepingTask(TestPms):
def setUp(self):
super().setUp()
def test_days_after_clean_overnight_constraint(self):
def test_task_type_days_after_overnight_should_be_gt_zero(self):
# ARRANGE, ACT & ASSERT
# create task type and verify that the constraint is raised
with self.assertRaises(
@@ -21,7 +21,7 @@ class TestPmsHousekeepingTask(TestPms):
}
)
def test_days_after_clean_empty_constraint(self):
def test_task_type_days_after_empty_should_be_gt_zero(self):
# ARRANGE, ACT & ASSERT
# create task type and verify that the constraint is raised
with self.assertRaises(
@@ -35,7 +35,7 @@ class TestPmsHousekeepingTask(TestPms):
}
)
def test_no_create_grandchild_task_type(self):
def test_task_type_max_inheritance(self):
# ARRANGE
# create task type
parent_task_type = self.env["pms.housekeeping.task.type"].create(
@@ -53,7 +53,8 @@ class TestPmsHousekeepingTask(TestPms):
)
# ACT & ASSERT
with self.assertRaises(
ValidationError, msg="Grandchild task type shouldn´t exist."
ValidationError,
msg="The maximum level of inheritance between tasks types should be 2",
):
self.env["pms.housekeeping.task.type"].create(
{

View File

@@ -7,9 +7,10 @@ class TestPmsHrEmployee(TestPms):
def setUp(self):
super().setUp()
def test_employee_pre_assigned_room_inconsistent(self):
def test_hr_employee_inconsistency_between_employees_properties_and_pre_assigned_rooms(
self,
):
# ARRANGE
self.pms_property2 = self.env["pms.property"].create(
{
"name": "Property 2",
@@ -24,7 +25,6 @@ class TestPmsHrEmployee(TestPms):
"room_type_id": self.room_type1.id,
}
)
# ACT & ASSERT
with self.assertRaises(
ValidationError, msg="The room should belong to the employee's property."
@@ -39,7 +39,9 @@ class TestPmsHrEmployee(TestPms):
}
)
def test_employee_pre_assigned_room_consistent_with_property(self):
def test_hr_employee_consistency_between_employees_properties_and_pre_assigned_rooms(
self,
):
# ARRANGE
self.hr_employee = self.env["hr.employee"].create(
{
@@ -59,7 +61,9 @@ class TestPmsHrEmployee(TestPms):
"Pre assigned room is not consistent with property",
)
def test_employee_pre_assigned_room_consistent_without_properties(self):
def test_hr_employee_consistency_between_employees_no_properties_and_pre_assigned_rooms(
self,
):
# ARRANGE
self.hr_employee = self.env["hr.employee"].create(
{
@@ -78,7 +82,9 @@ class TestPmsHrEmployee(TestPms):
"Pre assigned room is not consistent without properties",
)
def test_not_pre_assigned_room_no_housekeeper_employee(self):
def test_hr_employee_consistency_between_employees_pre_assigned_rooms_and_position(
self,
):
# ARRANGE
self.job_id = self.env["hr.job"].create(
{