diff --git a/pms/tests/test_pms_room_type_class.py b/pms/tests/test_pms_room_type_class.py index b5dc0c1ac..a064e785c 100644 --- a/pms/tests/test_pms_room_type_class.py +++ b/pms/tests/test_pms_room_type_class.py @@ -25,16 +25,12 @@ class TestRoomTypeClass(TestPms): # external integrity def test_external_case_01(self): """ - PRE: - room type class cl1 exists - - room_type_class1 has code c1 - - room_type_class1 has pms_property1 - - pms_property1 has company company1 - ACT: - create a new room_type_class2 class - - room_type_class2 has code c1 - - room_type_class2 has pms_property1 - - pms_property1 has company company1 - POST: - Integrity error: the room type already exists - - room_type_class2 not created + Check that a room type class cannot be created with an existing default_code + in the same property. + ---------- + A room type class is created with the default_code = 'c1' in property pms_property1. + Then try to create another room type class in the same property with the same code, + but this should throw a ValidationError. """ # ARRANGE # room_type_class1 @@ -61,18 +57,13 @@ class TestRoomTypeClass(TestPms): def test_external_case_02(self): """ - PRE: - room type class cl1 exists - - room_type_class1 has code c1 - - room_type_class1 has property pms_property1 - - pms_property1 has company company1 - ACT: - create a new room_type_class2 class - - room_type_class2 has code c1 - - room_type_class2 has property pms_property1, pms_property2, - pms_property3 - - pms_property1, pms_property2 has company company1 - - pms_property3 has company company2 - POST: - Integrity error: the room type class already exists - - room_type_class2 not created + Check that a room type class cannot be created with an existing default_code + in the same property. + ---------- + A room type class is created with the default_code = 'c1' in property pms_property1. + Then try to create another room type class with the same code in 3 properties and one + of them is the same property in which the other room type class was + created(pms_property1), but this should throw a ValidationError. """ # ARRANGE self.pms_property2 = self.env["pms.property"].create( @@ -116,13 +107,14 @@ class TestRoomTypeClass(TestPms): def test_single_case_01(self): """ - PRE: - room type class cl1 exists - - room_type_class1 has code c1 - - room_type_class1 has 2 properties pms_property1 and pms_property2 - - pms_property_1 and pms_property2 have the same company company1 - ACT: - search room type class with code c1 and pms_property1 - - pms_property1 has company company1 - POST: - only room_type_class1 room type class found + Check that the room type class was created correctly and that + it is in the property in which it was searched through its default code. + ----------- + Create a room type class with default code as 'c1' for properties 1 and 3 + (different companies), save the value returned by the get_unique_by_property_code() + method, passing property1 and default_code 'c1' as parameters. It is checked + that the id of the room type class created and the id of the record returned by the + method match. """ # ARRANGE room_type_class1 = self.env["pms.room.type.class"].create( @@ -149,22 +141,29 @@ class TestRoomTypeClass(TestPms): def test_single_case_02(self): """ - PRE: - room type class cl1 exists - - room_type_class1 has code c1 - - room_type_class1 has 2 properties pms_property1 and pms_property3 - - pms_property1 and pms_property2 have different companies - - pms_property1 have company company1 and pms_property3 have company2 - ACT: - search room type class with code c1 and property pms_property1 - - pms_property1 has company company1 - POST: - only room_type_class1 room type found + Check that the room type class was created correctly and that + it is in the property in which it was searched through its default code. + ----------- + Create a room type class with default code as 'c1' for properties 1 and 3 + (same company), save the value returned by the get_unique_by_property_code() + method, passing property1 and default_code 'c1' as parameters. It is checked + that the id of the room type class created and the id of the record returned by the + method match. """ # ARRANGE + self.pms_property2 = self.env["pms.property"].create( + { + "name": "Property 2", + "company_id": self.company1.id, + "default_pricelist_id": self.pricelist1.id, + } + ) cl1 = self.env["pms.room.type.class"].create( { "name": "Room type class 1", "default_code": "c1", "pms_property_ids": [ - (6, 0, [self.pms_property1.id, self.pms_property3.id]) + (6, 0, [self.pms_property1.id, self.pms_property2.id]) ], } ) @@ -181,13 +180,14 @@ class TestRoomTypeClass(TestPms): def test_single_case_03(self): """ - PRE: - room_type_class1 exists - - room_type_class1 has code c1 - - room_type_class1 with 2 properties pms_property1 and pms_property2 - - pms_property1 and pms_property2 have same company company1 - ACT: - search room type class with code c1 and property pms_property3 - - pms_property3 have company company2 - POST: - no room type found + Check that a room type class created for a property is not + found in another property with a different company. + ----------- + A room type class is created with default_code 'c1' for properties + 1 and 2. It is searched through get_unique_by_property_code() + passing it as parameters 'c1' and property 3 (from a different + company than 1 and 2). It is verified that that room type class + does not exist in that property. """ # ARRANGE self.pms_property2 = self.env["pms.property"].create( @@ -220,12 +220,15 @@ class TestRoomTypeClass(TestPms): def test_single_case_04(self): """ - PRE: - room_type_class1 exists - - room_type_class1 has code c1 - - room_type_class1 properties are null - ACT: - search room type class with code c1 and property pms_property1 - - pms_property1 have company company1 - POST: - only room_type_class1 room type class found + Check that a room type class with properties = False + (all properties) is found by searching for it in one + of the properties. + -------------- + A room type is created with default code = 'c1' and with + pms_property_ids = False. The room_type_class with + code 'c1' in property 1 is searched through the + get_unique_by_property_code() method and it is verified + that the returned value is correct. """ # ARRANGE room_type_class1 = self.env["pms.room.type.class"].create( @@ -251,16 +254,14 @@ class TestRoomTypeClass(TestPms): # tests with more than one room type class def test_multiple_case_01(self): """ - PRE: - room_type_class1 exists - - room_type_class1 has code c1 - - room_type_class1 has 2 properties pms_property1 and pms_property2 - - pms_property1 and pms_property2 have the same company company1 - - room type class room_type_class2 exists - - room_type_class2 has code c1 - - room_type_class2 has no properties - ACT: - search room type class with code c1 and property pms_property1 - - pms_property1 have company company1 - POST: - only room_type_class1 room type class found + Check that a room type class can be created with the same + code as another when one of them has pms_property_ids = False + ------------ + A room type class is created with code 'c1' for properties 1 and 3. + Another room type class is created with code 'c1' and the properties + set to False. The room_type with code 'c1' in property 1 is + searched through the get_unique_by_property_code() method and it is + verified that the returned value is correct. """ # ARRANGE room_type_class1 = self.env["pms.room.type.class"].create( @@ -295,16 +296,14 @@ class TestRoomTypeClass(TestPms): def test_multiple_case_02(self): """ - PRE: - room_type_class1 exists - - room_type_class1 has code c1 - - room_type_class1 has property pms_property1 - - pms_property1 have the company company1 - - room type class room_type_class2 exists - - room_type_class2 has code c1 - - room_type_class2 has no properties - ACT: - search room type class with code c1 and pms_property2 - - pms_property2 have company company1 - POST: - only room_type_class1 room type class found + Check that a room type class can be created with the same + code as another when one of them has pms_property_ids = False + ---------- + A room type class is created with code 'c1' for property 1(company1). + Another room type class is created with code 'c1' and the + properties set to False. Then the room_type with code 'c1' + in property 2(company1) is searched through the + get_unique_by_property_code() method and the result is checked. """ # ARRANGE self.pms_property2 = self.env["pms.property"].create( @@ -344,16 +343,14 @@ class TestRoomTypeClass(TestPms): def test_multiple_case_03(self): """ - PRE: - room_type_class1 exists - - room_type_class1 has code c1 - - room_type_class1 has property pms_property1 - - pms_property1 have the company company1 - - room type class room_type_class2 exists - - room_type_class2 has code c1 - - room_type_class2 has no properties - ACT: - search room type class with code c1 and property pms_property3 - - pms_property3 have company company2 - POST: - only room_type_class2 room type class found + Check that a room type class can be created with the same + code as another when one of them has pms_property_ids = False + ---------- + A room type class is created with code 'c1' for property 1(company1). + Another room type class is created with code 'c1' and the + properties set to False. Then the room_type with code 'c1' + in property 3(company2) is searched through the + get_unique_by_property_code() method and the result is checked. """ # ARRANGE # room_type_class1 @@ -383,43 +380,3 @@ class TestRoomTypeClass(TestPms): room_type_class2.id, "Expected room type class not found", ) - - def test_multiple_case_04(self): - """ - PRE: - room_type_class1 exists - - room_type_class1 has code c1 - - room_type_class1 has property pms_property1 - - pms_property1 have the company company1 - - room type room_type_class2 exists - - room_type_class2 has code c1 - - room_type_class2 has no properties - ACT: - search room type class with code c1 and property pms_property3 - - pms_property3 have company company2 - POST: - r2 room type class found - """ - # ARRANGE - # room_type_class1 - self.env["pms.room.type.class"].create( - { - "name": "Room type class 1", - "default_code": "c1", - "pms_property_ids": [(6, 0, [self.pms_property1.id])], - } - ) - room_type_class2 = self.env["pms.room.type.class"].create( - { - "name": "Room type class cl2", - "default_code": "c1", - "pms_property_ids": False, - } - ) - - # ACT - room_type_classes = self.env["pms.room.type.class"].get_unique_by_property_code( - self.pms_property3.id, "c1" - ) - - # ASSERT - self.assertEqual( - room_type_classes.id, room_type_class2.id, "Expected room type not found" - ) diff --git a/pms/tests/test_pms_wizard_split_join_swap_reservation.py b/pms/tests/test_pms_wizard_split_join_swap_reservation.py index ec7d2e852..cfe93b7d9 100644 --- a/pms/tests/test_pms_wizard_split_join_swap_reservation.py +++ b/pms/tests/test_pms_wizard_split_join_swap_reservation.py @@ -1,88 +1,44 @@ import datetime from odoo.exceptions import UserError -from odoo.tests import common + +from .common import TestPms -class TestPmsWizardMassiveChanges(common.SavepointCase): - def create_common_scenario(self): - # product.pricelist - self.test_pricelist = self.env["product.pricelist"].create( - { - "name": "test pricelist 1", - } - ) +class TestPmsWizardSplitJoinSwapReservation(TestPms): + def setUp(self): + super().setUp() # pms.availability.plan self.test_availability_plan = self.env["pms.availability.plan"].create( { "name": "Availability plan for TEST", - "pms_pricelist_ids": [(6, 0, [self.test_pricelist.id])], + "pms_pricelist_ids": [(6, 0, [self.pricelist1.id])], } ) - # sequences - self.folio_sequence = self.env["ir.sequence"].create( - { - "name": "PMS Folio", - "code": "pms.folio", - "padding": 4, - "company_id": self.env.ref("base.main_company").id, - } - ) - self.reservation_sequence = self.env["ir.sequence"].create( - { - "name": "PMS Reservation", - "code": "pms.reservation", - "padding": 4, - "company_id": self.env.ref("base.main_company").id, - } - ) - self.checkin_sequence = self.env["ir.sequence"].create( - { - "name": "PMS Checkin", - "code": "pms.checkin.partner", - "padding": 4, - "company_id": self.env.ref("base.main_company").id, - } - ) - # pms.property - self.test_property = self.env["pms.property"].create( - { - "name": "MY PMS TEST", - "company_id": self.env.ref("base.main_company").id, - "default_pricelist_id": self.test_pricelist.id, - "folio_sequence_id": self.folio_sequence.id, - "reservation_sequence_id": self.reservation_sequence.id, - "checkin_sequence_id": self.checkin_sequence.id, - } - ) - # pms.room.type.class - self.test_room_type_class = self.env["pms.room.type.class"].create( - {"name": "Room", "default_code": "ROOM"} - ) # pms.room.type self.test_room_type_single = self.env["pms.room.type"].create( { - "pms_property_ids": [self.test_property.id], + "pms_property_ids": [self.pms_property1.id], "name": "Single Test", "default_code": "SNG_Test", - "class_id": self.test_room_type_class.id, + "class_id": self.room_type_class1.id, } ) # pms.room.type self.test_room_type_double = self.env["pms.room.type"].create( { - "pms_property_ids": [self.test_property.id], + "pms_property_ids": [self.pms_property1.id], "name": "Double Test", "default_code": "DBL_Test", - "class_id": self.test_room_type_class.id, + "class_id": self.room_type_class1.id, } ) # create rooms self.room1 = self.env["pms.room"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property1.id, "name": "Double 101", "room_type_id": self.test_room_type_double.id, "capacity": 2, @@ -91,42 +47,42 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): self.room2 = self.env["pms.room"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property1.id, "name": "Double 102", "room_type_id": self.test_room_type_double.id, "capacity": 2, } ) - # self.room3 = self.env["pms.room"].create( - # { - # "pms_property_id": self.test_property.id, - # "name": "Double 103", - # "room_type_id": self.test_room_type_double.id, - # "capacity": 2, - # } - # ) + self.partner1 = self.env["res.partner"].create({"name": "Antón"}) # UNIFY TESTS # review def test_unify_reservation_avail_should(self): - # TEST CASE - # Unify reservation in one room with avail for that room - # +------------+------+------+------+----+----+----+ - # | room/date | 01 | 02 | 03 | 04 | 05 | 06 | - # +------------+------+------+------+----+----+----+ - # | Double 101 | r1 | | r1 | | | | - # | Double 102 | | r1 | | | | | - # +------------+------+------+------+----+----+----+ + """ + Check that, if there is availability, a reservation with several + rooms on different days can be unified into a one room reservation. + ------------ + Create a reservation with room1.Then, in the first reservation line, + the room is changed to room2.The reservation_join() method of the wizard + is launched, passing the reservation and room2 as parameters and it is + verified that room2 is found in all the reservation lines. + + +------------+------+------+------+----+----+----+ + | room/date | 01 | 02 | 03 | 04 | 05 | 06 | + +------------+------+------+------+----+----+----+ + | Double 101 | r1 | | r1 | | | | + | Double 102 | | r1 | | | | | + +------------+------+------+------+----+----+----+ + """ # ARRANGE - self.create_common_scenario() r1 = self.env["pms.reservation"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property1.id, "checkin": datetime.datetime.now(), "checkout": datetime.datetime.now() + datetime.timedelta(days=3), "adults": 2, "preferred_room_id": self.room1.id, - "partner_id": self.env.ref("base.res_partner_12").id, + "partner_id": self.partner1.id, } ) r1.flush() @@ -143,46 +99,46 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): ) def test_unify_reservation_avail_not(self): - # TEST CASE - # Unify reservation in one room and - # there's not availability for that room - - # +------------+------+------+------+----+----+----+ - # | room/date | 01 | 02 | 03 | 04 | 05 | 06 | - # +------------+------+------+------+----+----+----+ - # | Double 101 | r1 | r1 | r2 | | | | - # | Double 102 | r0 | r0 | r1 | | | | - # +------------+------+------+------+----+----+----+ + """ + Check that you cannot unify a reservation with two different rooms + because there is no availability in the required room. + ---------- + +------------+------+------+------+----+----+----+ + | room/date | 01 | 02 | 03 | 04 | 05 | 06 | + +------------+------+------+------+----+----+----+ + | Double 101 | r1 | r1 | r2 | | | | + | Double 102 | r0 | r0 | r1 | | | | + +------------+------+------+------+----+----+----+ + """ # ARRANGE - self.create_common_scenario() self.env["pms.reservation"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property1.id, "checkin": datetime.datetime.now(), "checkout": datetime.datetime.now() + datetime.timedelta(days=2), "adults": 2, "preferred_room_id": self.room2.id, - "partner_id": self.env.ref("base.res_partner_12").id, + "partner_id": self.partner1.id, } ) r2 = self.env["pms.reservation"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property1.id, "checkin": datetime.datetime.now() + datetime.timedelta(days=2), "checkout": datetime.datetime.now() + datetime.timedelta(days=3), "adults": 2, "preferred_room_id": self.room1.id, - "partner_id": self.env.ref("base.res_partner_12").id, + "partner_id": self.partner1.id, } ) r1 = self.env["pms.reservation"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property1.id, "checkin": datetime.datetime.now(), "checkout": datetime.datetime.now() + datetime.timedelta(days=3), "adults": 2, "room_type_id": self.test_room_type_double.id, - "partner_id": self.env.ref("base.res_partner_12").id, + "partner_id": self.partner1.id, } ) r2.flush() @@ -193,30 +149,31 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): ) def test_unify_reservation_avail_not_room_exist(self): - # TEST CASE - # Unify reservation in one room and - # the room indicated doesn't exist: pms.room() + """ + Check that you cannot unify a reservation with two different rooms + because there the required room does not exists. + """ # ARRANGE - self.create_common_scenario() + self.env["pms.reservation"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property1.id, "checkin": datetime.datetime.now(), "checkout": datetime.datetime.now() + datetime.timedelta(days=3), "adults": 2, "preferred_room_id": self.room1.id, - "partner_id": self.env.ref("base.res_partner_12").id, + "partner_id": self.partner1.id, } ) r2 = self.env["pms.reservation"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property1.id, "checkin": datetime.datetime.now(), "checkout": datetime.datetime.now() + datetime.timedelta(days=3), "adults": 2, "preferred_room_id": self.room2.id, - "partner_id": self.env.ref("base.res_partner_12").id, + "partner_id": self.partner1.id, } ) r2.flush() @@ -228,43 +185,46 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): # SWAP TESTS def test_swap_reservation_rooms_01(self): # TEST CASE + """ + Check that the rooms of two different reservations was swapped correctly + by applying the reservations_swap() method of the wizard. + ------------ + Initial state + +------------+------+------+------+----+----+----+ + | room/date | 01 | 02 | 03 | 04 | 05 | 06 | + +------------+------+------+------+----+----+----+ + | Double 101 | r1 | r1 | r1 | | | | + | Double 102 | r2 | r2 | r2 | | | | + +------------+------+------+------+----+----+----+ - # Initial state - # +------------+------+------+------+----+----+----+ - # | room/date | 01 | 02 | 03 | 04 | 05 | 06 | - # +------------+------+------+------+----+----+----+ - # | Double 101 | r1 | r1 | r1 | | | | - # | Double 102 | r2 | r2 | r2 | | | | - # +------------+------+------+------+----+----+----+ - - # State after swap - # +------------+------+------+------+----+----+----+ - # | room/date | 01 | 02 | 03 | 04 | 05 | 06 | - # +------------+------+------+------+----+----+----+ - # | Double 101 | r2 | r2 | r2 | | | | - # | Double 102 | r1 | r1 | r1 | | | | - # +------------+------+------+------+----+----+----+ - + State after swap + +------------+------+------+------+----+----+----+ + | room/date | 01 | 02 | 03 | 04 | 05 | 06 | + +------------+------+------+------+----+----+----+ + | Double 101 | r2 | r2 | r2 | | | | + | Double 102 | r1 | r1 | r1 | | | | + +------------+------+------+------+----+----+----+ + """ # ARRANGE - self.create_common_scenario() + r1 = self.env["pms.reservation"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property1.id, "checkin": datetime.datetime.now(), "checkout": datetime.datetime.now() + datetime.timedelta(days=3), "adults": 2, "preferred_room_id": self.room1.id, - "partner_id": self.env.ref("base.res_partner_12").id, + "partner_id": self.partner1.id, } ) r2 = self.env["pms.reservation"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property1.id, "checkin": datetime.datetime.now(), "checkout": datetime.datetime.now() + datetime.timedelta(days=3), "adults": 2, "preferred_room_id": self.room2.id, - "partner_id": self.env.ref("base.res_partner_12").id, + "partner_id": self.partner1.id, } ) r1.flush() @@ -283,44 +243,47 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): ) def test_swap_reservation_rooms_02(self): - # TEST CASE + """ + Check that two rooms from two different reservations are swapped + correctly. + ------------------- - # Initial state - # +------------+------+------+------+----+----+----+ - # | room/date | 01 | 02 | 03 | 04 | 05 | 06 | - # +------------+------+------+------+----+----+----+ - # | Double 101 | | r1 | r1 | | | | - # | Double 102 | r2 | r2 | r2 | | | | - # +------------+------+------+------+----+----+----+ - - # State after swap - # +------------+------+------+------+----+----+----+ - # | room/date | 01 | 02 | 03 | 04 | 05 | 06 | - # +------------+------+------+------+----+----+----+ - # | Double 101 | | r2 | r2 | | | | - # | Double 102 | r2 | r1 | r1 | | | | - # +------------+------+------+------+----+----+----+ + Initial state + +------------+------+------+------+----+----+----+ + | room/date | 01 | 02 | 03 | 04 | 05 | 06 | + +------------+------+------+------+----+----+----+ + | Double 101 | | r1 | r1 | | | | + | Double 102 | r2 | r2 | r2 | | | | + +------------+------+------+------+----+----+----+ + State after swap + +------------+------+------+------+----+----+----+ + | room/date | 01 | 02 | 03 | 04 | 05 | 06 | + +------------+------+------+------+----+----+----+ + | Double 101 | | r2 | r2 | | | | + | Double 102 | r2 | r1 | r1 | | | | + +------------+------+------+------+----+----+----+ + """ # ARRANGE - self.create_common_scenario() + r1 = self.env["pms.reservation"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property1.id, "checkin": datetime.datetime.now() + datetime.timedelta(days=1), "checkout": datetime.datetime.now() + datetime.timedelta(days=3), "adults": 2, "preferred_room_id": self.room1.id, - "partner_id": self.env.ref("base.res_partner_12").id, + "partner_id": self.partner1.id, } ) r2 = self.env["pms.reservation"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property1.id, "checkin": datetime.datetime.now(), "checkout": datetime.datetime.now() + datetime.timedelta(days=3), "adults": 2, "preferred_room_id": self.room2.id, - "partner_id": self.env.ref("base.res_partner_12").id, + "partner_id": self.partner1.id, } ) r1.flush() @@ -339,44 +302,46 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): ) def test_swap_reservation_rooms_03(self): - # TEST CASE - - # Initial state - # +------------+------+------+------+----+----+----+ - # | room/date | 01 | 02 | 03 | 04 | 05 | 06 | - # +------------+------+------+------+----+----+----+ - # | Double 101 | | r1 | r1 | | | | - # | Double 102 | r2 | r2 | r2 | | | | - # +------------+------+------+------+----+----+----+ - - # State after swap - # +------------+------+------+------+----+----+----+ - # | room/date | 01 | 02 | 03 | 04 | 05 | 06 | - # +------------+------+------+------+----+----+----+ - # | Double 101 | r2 | r2 | r2 | | | | - # | Double 102 | | r1 | r1 | | | | - # +------------+------+------+------+----+----+----+ + """ + Check that two rooms from two different reservations are swapped + correctly. + ------------------- + Initial state + +------------+------+------+------+----+----+----+ + | room/date | 01 | 02 | 03 | 04 | 05 | 06 | + +------------+------+------+------+----+----+----+ + | Double 101 | | r1 | r1 | | | | + | Double 102 | r2 | r2 | r2 | | | | + +------------+------+------+------+----+----+----+ + State after swap + +------------+------+------+------+----+----+----+ + | room/date | 01 | 02 | 03 | 04 | 05 | 06 | + +------------+------+------+------+----+----+----+ + | Double 101 | r2 | r2 | r2 | | | | + | Double 102 | | r1 | r1 | | | | + +------------+------+------+------+----+----+----+ + """ # ARRANGE - self.create_common_scenario() + r1 = self.env["pms.reservation"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property1.id, "checkin": datetime.datetime.now() + datetime.timedelta(days=1), "checkout": datetime.datetime.now() + datetime.timedelta(days=3), "adults": 2, "preferred_room_id": self.room1.id, - "partner_id": self.env.ref("base.res_partner_12").id, + "partner_id": self.partner1.id, } ) r2 = self.env["pms.reservation"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property1.id, "checkin": datetime.datetime.now(), "checkout": datetime.datetime.now() + datetime.timedelta(days=3), "adults": 2, "preferred_room_id": self.room2.id, - "partner_id": self.env.ref("base.res_partner_12").id, + "partner_id": self.partner1.id, } ) r1.flush() @@ -396,43 +361,47 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): def test_swap_reservation_rooms_04(self): # TEST CASE + """ + Check that two rooms from two different reservations are swapped + correctly. + -------- - # Initial state - # +------------+------+------+------+----+----+----+ - # | room/date | 01 | 02 | 03 | 04 | 05 | 06 | - # +------------+------+------+------+----+----+----+ - # | Double 101 | r1 | r1 | | | | | - # | Double 102 | r2 | r2 | r2 | | | | - # +------------+------+------+------+----+----+----+ - - # State after swap - # +------------+------+------+------+----+----+----+ - # | room/date | 01 | 02 | 03 | 04 | 05 | 06 | - # +------------+------+------+------+----+----+----+ - # | Double 101 | r2 | r2 | | | | | - # | Double 102 | r1 | r1 | r2 | | | | - # +------------+------+------+------+----+----+----+ + Initial state + +------------+------+------+------+----+----+----+ + | room/date | 01 | 02 | 03 | 04 | 05 | 06 | + +------------+------+------+------+----+----+----+ + | Double 101 | r1 | r1 | | | | | + | Double 102 | r2 | r2 | r2 | | | | + +------------+------+------+------+----+----+----+ + State after swap + +------------+------+------+------+----+----+----+ + | room/date | 01 | 02 | 03 | 04 | 05 | 06 | + +------------+------+------+------+----+----+----+ + | Double 101 | r2 | r2 | | | | | + | Double 102 | r1 | r1 | r2 | | | | + +------------+------+------+------+----+----+----+ + """ # ARRANGE - self.create_common_scenario() + r1 = self.env["pms.reservation"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property1.id, "checkin": datetime.datetime.now(), "checkout": datetime.datetime.now() + datetime.timedelta(days=2), "adults": 2, "preferred_room_id": self.room1.id, - "partner_id": self.env.ref("base.res_partner_12").id, + "partner_id": self.partner1.id, } ) r2 = self.env["pms.reservation"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property1.id, "checkin": datetime.datetime.now(), "checkout": datetime.datetime.now() + datetime.timedelta(days=3), "adults": 2, "preferred_room_id": self.room2.id, - "partner_id": self.env.ref("base.res_partner_12").id, + "partner_id": self.partner1.id, } ) r1.flush() @@ -451,44 +420,48 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): ) def test_swap_reservation_rooms_05(self): - # TEST CASE + """ + Check that two rooms from two different reservations are swapped + correctly. + --------------- - # Initial state - # +------------+------+------+------+----+----+----+ - # | room/date | 01 | 02 | 03 | 04 | 05 | 06 | - # +------------+------+------+------+----+----+----+ - # | Double 101 | r1 | r1 | | | | | - # | Double 102 | r2 | r2 | r2 | | | | - # +------------+------+------+------+----+----+----+ + Initial state + +------------+------+------+------+----+----+----+ + | room/date | 01 | 02 | 03 | 04 | 05 | 06 | + +------------+------+------+------+----+----+----+ + | Double 101 | r1 | r1 | | | | | + | Double 102 | r2 | r2 | r2 | | | | + +------------+------+------+------+----+----+----+ - # State after swap - # +------------+------+------+------+----+----+----+ - # | room/date | 01 | 02 | 03 | 04 | 05 | 06 | - # +------------+------+------+------+----+----+----+ - # | Double 101 | r2 | r2 | r2 | | | | - # | Double 102 | r1 | r1 | | | | | - # +------------+------+------+------+----+----+----+ + State after swap + +------------+------+------+------+----+----+----+ + | room/date | 01 | 02 | 03 | 04 | 05 | 06 | + +------------+------+------+------+----+----+----+ + | Double 101 | r2 | r2 | r2 | | | | + | Double 102 | r1 | r1 | | | | | + +------------+------+------+------+----+----+----+ + """ # ARRANGE - self.create_common_scenario() + r1 = self.env["pms.reservation"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property1.id, "checkin": datetime.datetime.now(), "checkout": datetime.datetime.now() + datetime.timedelta(days=2), "adults": 2, "preferred_room_id": self.room1.id, - "partner_id": self.env.ref("base.res_partner_12").id, + "partner_id": self.partner1.id, } ) r2 = self.env["pms.reservation"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property1.id, "checkin": datetime.datetime.now(), "checkout": datetime.datetime.now() + datetime.timedelta(days=3), "adults": 2, "preferred_room_id": self.room2.id, - "partner_id": self.env.ref("base.res_partner_12").id, + "partner_id": self.partner1.id, } ) r1.flush() @@ -507,37 +480,37 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): ) def test_swap_reservation_rooms_06(self): - # TEST CASE - # Swap room1 with room2 should raise an error - # because room1 has no reservation between - # checkin & checkout provided + """ + Check that the room is exchanged correctly for every day because there + is no reservation for another room in those days. + --------------------------- - # Initial state - # +------------+------+------+------+----+----+----+ - # | room/date | 01 | 02 | 03 | 04 | 05 | 06 | - # +------------+------+------+------+----+----+----+ - # | Double 101 | | | | | | | - # | Double 102 | r1 | r1 | r1 | | | | - # +------------+------+------+------+----+----+----+ - - # State after swap - # +------------+------+------+------+----+----+----+ - # | room/date | 01 | 02 | 03 | 04 | 05 | 06 | - # +------------+------+------+------+----+----+----+ - # | Double 101 | r1 | r1 | r1 | | | | - # | Double 102 | | | | | | | - # +------------+------+------+------+----+----+----+ + Initial state + +------------+------+------+------+----+----+----+ + | room/date | 01 | 02 | 03 | 04 | 05 | 06 | + +------------+------+------+------+----+----+----+ + | Double 101 | | | | | | | + | Double 102 | r1 | r1 | r1 | | | | + +------------+------+------+------+----+----+----+ + State after swap + +------------+------+------+------+----+----+----+ + | room/date | 01 | 02 | 03 | 04 | 05 | 06 | + +------------+------+------+------+----+----+----+ + | Double 101 | r1 | r1 | r1 | | | | + | Double 102 | | | | | | | + +------------+------+------+------+----+----+----+ + """ # ARRANGE - self.create_common_scenario() + r1 = self.env["pms.reservation"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property1.id, "checkin": datetime.datetime.now(), "checkout": datetime.datetime.now() + datetime.timedelta(days=3), "adults": 2, "preferred_room_id": self.room2.id, - "partner_id": self.env.ref("base.res_partner_12").id, + "partner_id": self.partner1.id, } ) @@ -552,55 +525,59 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): self.assertTrue(r1.reservation_line_ids.room_id == self.room1) def test_swap_reservation_rooms_gap_01(self): - # TEST CASE + """ + Check that three rooms from three different reservations are swapped + correctly. + ----------- - # Initial state - # +------------+------+------+------+----+----+----+ - # | room/date | 01 | 02 | 03 | 04 | 05 | 06 | - # +------------+------+------+------+----+----+----+ - # | Double 101 | r0 | | r1 | | | | - # | Double 102 | r2 | r2 | r2 | | | | - # +------------+------+------+------+----+----+----+ + Initial state + +------------+------+------+------+----+----+----+ + | room/date | 01 | 02 | 03 | 04 | 05 | 06 | + +------------+------+------+------+----+----+----+ + | Double 101 | r0 | | r1 | | | | + | Double 102 | r2 | r2 | r2 | | | | + +------------+------+------+------+----+----+----+ - # State after swap - # +------------+------+------+------+----+----+----+ - # | room/date | 01 | 02 | 03 | 04 | 05 | 06 | - # +------------+------+------+------+----+----+----+ - # | Double 101 | r2 | | r2 | | | | - # | Double 102 | r0 | r2 | r1 | | | | - # +------------+------+------+------+----+----+----+ + State after swap + +------------+------+------+------+----+----+----+ + | room/date | 01 | 02 | 03 | 04 | 05 | 06 | + +------------+------+------+------+----+----+----+ + | Double 101 | r2 | | r2 | | | | + | Double 102 | r0 | r2 | r1 | | | | + +------------+------+------+------+----+----+----+ + """ # ARRANGE - self.create_common_scenario() + r0 = self.env["pms.reservation"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property1.id, "checkin": datetime.datetime.now(), "checkout": datetime.datetime.now() + datetime.timedelta(days=1), "adults": 2, "preferred_room_id": self.room1.id, - "partner_id": self.env.ref("base.res_partner_12").id, + "partner_id": self.partner1.id, } ) r1 = self.env["pms.reservation"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property1.id, "checkin": datetime.datetime.now() + datetime.timedelta(days=2), "checkout": datetime.datetime.now() + datetime.timedelta(days=3), "adults": 2, "preferred_room_id": self.room1.id, - "partner_id": self.env.ref("base.res_partner_12").id, + "partner_id": self.partner1.id, } ) r2 = self.env["pms.reservation"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property1.id, "checkin": datetime.datetime.now(), "checkout": datetime.datetime.now() + datetime.timedelta(days=3), "adults": 2, "preferred_room_id": self.room2.id, - "partner_id": self.env.ref("base.res_partner_12").id, + "partner_id": self.partner1.id, } ) r1.flush() @@ -623,54 +600,58 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): def test_swap_reservation_rooms_gap_02(self): # TEST CASE + """ + Check that three rooms from three different reservations are swapped + correctly. + ----------- - # Initial state - # +------------+------+------+------+----+----+----+ - # | room/date | 01 | 02 | 03 | 04 | 05 | 06 | - # +------------+------+------+------+----+----+----+ - # | Double 101 | r0 | | r1 | | | | - # | Double 102 | r2 | r2 | r2 | | | | - # +------------+------+------+------+----+----+----+ - - # State after swap - # +------------+------+------+------+----+----+----+ - # | room/date | 01 | 02 | 03 | 04 | 05 | 06 | - # +------------+------+------+------+----+----+----+ - # | Double 101 | r2 | r2 | r2 | | | | - # | Double 102 | r0 | | r1 | | | | - # +------------+------+------+------+----+----+----+ + Initial state + +------------+------+------+------+----+----+----+ + | room/date | 01 | 02 | 03 | 04 | 05 | 06 | + +------------+------+------+------+----+----+----+ + | Double 101 | r0 | | r1 | | | | + | Double 102 | r2 | r2 | r2 | | | | + +------------+------+------+------+----+----+----+ + State after swap + +------------+------+------+------+----+----+----+ + | room/date | 01 | 02 | 03 | 04 | 05 | 06 | + +------------+------+------+------+----+----+----+ + | Double 101 | r2 | r2 | r2 | | | | + | Double 102 | r0 | | r1 | | | | + +------------+------+------+------+----+----+----+ + """ # ARRANGE - self.create_common_scenario() + r0 = self.env["pms.reservation"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property1.id, "checkin": datetime.datetime.now(), "checkout": datetime.datetime.now() + datetime.timedelta(days=1), "adults": 2, "preferred_room_id": self.room1.id, - "partner_id": self.env.ref("base.res_partner_12").id, + "partner_id": self.partner1.id, } ) r1 = self.env["pms.reservation"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property1.id, "checkin": datetime.datetime.now() + datetime.timedelta(days=2), "checkout": datetime.datetime.now() + datetime.timedelta(days=3), "adults": 2, "preferred_room_id": self.room1.id, - "partner_id": self.env.ref("base.res_partner_12").id, + "partner_id": self.partner1.id, } ) r2 = self.env["pms.reservation"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property1.id, "checkin": datetime.datetime.now(), "checkout": datetime.datetime.now() + datetime.timedelta(days=3), "adults": 2, "preferred_room_id": self.room2.id, - "partner_id": self.env.ref("base.res_partner_12").id, + "partner_id": self.partner1.id, } ) r1.flush() @@ -691,29 +672,31 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): # NOT VALID TEST CASES def test_swap_reservation_not_valid_01(self): - # TEST CASE - # Swap room1 with room2 should raise an error - # because room1 has no reservation between - # checkin & checkout provided - - # Initial state - # +------------+------+------+------+----+----+----+ - # | room/date | 01 | 02 | 03 | 04 | 05 | 06 | - # +------------+------+------+------+----+----+----+ - # | Double 101 | | | | | | | - # | Double 102 | r1 | r1 | r1 | | | | - # +------------+------+------+------+----+----+----+ + """ + Check that an error is thrown if you try to pass a room that is + not reserved for those days to the reservations_swap() method. + --------------------------- + Swap room1 with room2 should raise an error because room1 has + no reservation between checkin & checkout provided. + Initial state + +------------+------+------+------+----+----+----+ + | room/date | 01 | 02 | 03 | 04 | 05 | 06 | + +------------+------+------+------+----+----+----+ + | Double 101 | | | | | | | + | Double 102 | r1 | r1 | r1 | | | | + +------------+------+------+------+----+----+----+ + """ # ARRANGE - self.create_common_scenario() + self.env["pms.reservation"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property1.id, "checkin": datetime.datetime.now(), "checkout": datetime.datetime.now() + datetime.timedelta(days=3), "adults": 2, "preferred_room_id": self.room2.id, - "partner_id": self.env.ref("base.res_partner_12").id, + "partner_id": self.partner1.id, } ) @@ -728,27 +711,29 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): # SPLIT TESTS def test_split_reservation_check_room_splitted_valid_01(self): - # TEST CASE - # A reservation is created with preferred room - # The room for 1st night is switched to another room - # Expected result: - # +------------+------+------+------+----+----+----+ - # | room/date | 01 | 02 | 03 | 04 | 05 | 06 | - # +------------+------+------+------+----+----+----+ - # | Double 101 | | r1 | r1 | | | | - # | Double 102 | r1 | | | | | | - # +------------+------+------+------+----+----+----+ + """ + A reservation is created with preferred room. The room for 1st night + is switched to another room. + ------------------- + Expected result: + +------------+------+------+------+----+----+----+ + | room/date | 01 | 02 | 03 | 04 | 05 | 06 | + +------------+------+------+------+----+----+----+ + | Double 101 | | r1 | r1 | | | | + | Double 102 | r1 | | | | | | + +------------+------+------+------+----+----+----+ + """ # ARRANGE - self.create_common_scenario() + r1 = self.env["pms.reservation"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property1.id, "checkin": datetime.datetime.now(), "checkout": datetime.datetime.now() + datetime.timedelta(days=3), "adults": 2, "preferred_room_id": self.room1.id, - "partner_id": self.env.ref("base.res_partner_12").id, + "partner_id": self.partner1.id, } ) r1.flush() @@ -763,27 +748,29 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): ) def test_split_reservation_check_room_splitted_valid_02(self): - # TEST CASE - # A reservation is created with preferred room - # The room for 1st night is switched to another room - # Expected result: - # +------------+------+------+------+----+----+----+ - # | room/date | 01 | 02 | 03 | 04 | 05 | 06 | - # +------------+------+------+------+----+----+----+ - # | Double 101 | r1 | r1 | | | | | - # | Double 102 | | | r1 | | | | - # +------------+------+------+------+----+----+----+ + """ + A reservation is created with preferred room. The room for 1st + night is switched to another room + -------------- + Expected result: + +------------+------+------+------+----+----+----+ + | room/date | 01 | 02 | 03 | 04 | 05 | 06 | + +------------+------+------+------+----+----+----+ + | Double 101 | r1 | r1 | | | | | + | Double 102 | | | r1 | | | | + +------------+------+------+------+----+----+----+ + """ # ARRANGE - self.create_common_scenario() + r1 = self.env["pms.reservation"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property1.id, "checkin": datetime.datetime.now(), "checkout": datetime.datetime.now() + datetime.timedelta(days=3), "adults": 2, "preferred_room_id": self.room1.id, - "partner_id": self.env.ref("base.res_partner_12").id, + "partner_id": self.partner1.id, } ) r1.flush() @@ -807,27 +794,29 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): ) def test_split_reservation_check_room_splitted_valid_03(self): - # TEST CASE - # A reservation is created with preferred room - # The room for 1st night is switched to another room - # Expected result: - # +------------+------+------+------+----+----+----+ - # | room/date | 01 | 02 | 03 | 04 | 05 | 06 | - # +------------+------+------+------+----+----+----+ - # | Double 101 | r1 | | r1 | | | | - # | Double 102 | | r1 | | | | | - # +------------+------+------+------+----+----+----+ + """ + A reservation is created with preferred room. The room for 1st + night is switched to another room. + ----------- + + Expected result: + +------------+------+------+------+----+----+----+ + | room/date | 01 | 02 | 03 | 04 | 05 | 06 | + +------------+------+------+------+----+----+----+ + | Double 101 | r1 | | r1 | | | | + | Double 102 | | r1 | | | | | + +------------+------+------+------+----+----+----+""" # ARRANGE - self.create_common_scenario() + r1 = self.env["pms.reservation"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property1.id, "checkin": datetime.datetime.now(), "checkout": datetime.datetime.now() + datetime.timedelta(days=3), "adults": 2, "preferred_room_id": self.room1.id, - "partner_id": self.env.ref("base.res_partner_12").id, + "partner_id": self.partner1.id, } ) r1.flush() @@ -852,26 +841,30 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): ) def test_split_reservation_check_room_splitted_not_valid_01(self): - # TEST CASE - # Try to split the reservation for one night - # and set with a non valid room + """ + Try to split the reservation for one night and set with a non valid room. + ---------- + Create a reservation for room1. Then create a room and it is deleted. The + reservation_split method is launched but an error should appear because + the room does not exist. + """ # ARRANGE - self.create_common_scenario() + r1 = self.env["pms.reservation"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property1.id, "checkin": datetime.datetime.now(), "checkout": datetime.datetime.now() + datetime.timedelta(days=3), "adults": 2, "preferred_room_id": self.room1.id, - "partner_id": self.env.ref("base.res_partner_12").id, + "partner_id": self.partner1.id, } ) r1.flush() room_not_exist = self.room3 = self.env["pms.room"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property1.id, "name": "Double 103", "room_type_id": self.test_room_type_double.id, "capacity": 2, @@ -886,43 +879,55 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): def test_split_reservation_check_room_splitted_not_valid_02(self): # TEST CASE - # Try to split the reservation for one night - # and that night doesn't belong to reservation - + """ + Try to split the reservation for one night and that night + doesn't belongto reservation. + --------------- + A reservation is created with a date interval of 3 days. + After the reservation_split() method is launched, passing + that reservation but with a date interval of 100 days, + this should throw an error. + """ # ARRANGE - self.create_common_scenario() + r1 = self.env["pms.reservation"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property1.id, "checkin": datetime.datetime.now(), "checkout": datetime.datetime.now() + datetime.timedelta(days=3), "adults": 2, "preferred_room_id": self.room1.id, - "partner_id": self.env.ref("base.res_partner_12").id, + "partner_id": self.partner1.id, } ) r1.flush() # ACT & ASSERT with self.assertRaises(UserError): self.env["pms.reservation.split.join.swap.wizard"].reservation_split( - r1, datetime.datetime.now() + datetime.timedelta(days=100), self.room2 + r1, datetime.datetime.now() + datetime.timedelta(days=100), self.room1 ) def test_split_reservation_check_room_splitted_not_valid_03(self): - # TEST CASE - # Try to split the reservation for one night - # and the reservation not exists + + """ + Try to split the reservation for one night and the reservation + not exists. + ------------- + A reservation is created, but it is not the reservation that is + passed to the reservation_split() method, one that does not exist + is passed to it, this should throw an error. + """ # ARRANGE - self.create_common_scenario() + r1 = self.env["pms.reservation"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property1.id, "checkin": datetime.datetime.now(), "checkout": datetime.datetime.now() + datetime.timedelta(days=3), "adults": 2, "preferred_room_id": self.room1.id, - "partner_id": self.env.ref("base.res_partner_12").id, + "partner_id": self.partner1.id, } ) r1.flush() @@ -933,30 +938,35 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): ) def test_split_reservation_check_room_splitted_not_valid_04(self): - # TEST CASE - # Try to split the reservation to one room - # and the room is not available - + """ + Try to split the reservation to one room and the room is not available. + --------------- + A reservation is created with room2 as favorite_room. Another reservation + is created for the same days with room1. An attempt is made to separate + the room from the second reservation using the reservations_split() method, + passing it the same days as the reservations and room2, but this should + throw an error because room2 is not available for those days. + """ # ARRANGE - self.create_common_scenario() + self.env["pms.reservation"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property1.id, "checkin": datetime.datetime.now(), "checkout": datetime.datetime.now() + datetime.timedelta(days=3), "adults": 2, "preferred_room_id": self.room2.id, - "partner_id": self.env.ref("base.res_partner_12").id, + "partner_id": self.partner1.id, } ) r1 = self.env["pms.reservation"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property1.id, "checkin": datetime.datetime.now(), "checkout": datetime.datetime.now() + datetime.timedelta(days=3), "adults": 2, "preferred_room_id": self.room1.id, - "partner_id": self.env.ref("base.res_partner_12").id, + "partner_id": self.partner1.id, } ) r1.flush()