diff --git a/pms/tests/test_pms_availability_plan_rules.py b/pms/tests/test_pms_availability_plan_rules.py index e09fc952a..c4b753a2f 100644 --- a/pms/tests/test_pms_availability_plan_rules.py +++ b/pms/tests/test_pms_availability_plan_rules.py @@ -1,40 +1,27 @@ import datetime -from freezegun import freeze_time - from odoo import fields from odoo.exceptions import UserError, ValidationError -from odoo.tests import common + +from .common import TestPms -@freeze_time("1980-01-01") -class TestPmsRoomTypeAvailabilityRules(common.SavepointCase): - def create_common_scenario(self): - self.test_pricelist2 = self.env["product.pricelist"].create( - { - "name": "test pricelist 2", - } - ) - self.test_property1 = self.env["pms.property"].create( - { - "name": "Property 1", - "company_id": self.env.ref("base.main_company").id, - "default_pricelist_id": self.test_pricelist2.id, - } - ) - self.test_property2 = self.env["pms.property"].create( +class TestPmsRoomTypeAvailabilityRules(TestPms): + def setUp(self): + super().setUp() + self.pms_property2 = self.env["pms.property"].create( { "name": "Property 2", - "company_id": self.env.ref("base.main_company").id, - "default_pricelist_id": self.test_pricelist2.id, + "company_id": self.company1.id, + "default_pricelist_id": self.pricelist1.id, } ) - self.test_pricelist1 = self.env["product.pricelist"].create( + self.pricelist2 = self.env["product.pricelist"].create( { "name": "test pricelist 1", "pms_property_ids": [ - (4, self.test_property1.id), - (4, self.test_property2.id), + (4, self.pms_property1.id), + (4, self.pms_property2.id), ], } ) @@ -43,43 +30,15 @@ class TestPmsRoomTypeAvailabilityRules(common.SavepointCase): self.test_room_type_availability1 = self.env["pms.availability.plan"].create( { "name": "Availability plan for TEST", - "pms_pricelist_ids": [(6, 0, [self.test_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_pricelist_ids": [(6, 0, [self.pricelist2.id])], } ) # pms.property - self.test_property = self.env["pms.property"].create( + self.pms_property3 = self.env["pms.property"].create( { "name": "MY PMS TEST", - "company_id": self.env.ref("base.main_company").id, - "default_pricelist_id": self.test_pricelist1.id, - "folio_sequence_id": self.folio_sequence.id, - "reservation_sequence_id": self.reservation_sequence.id, - "checkin_sequence_id": self.checkin_sequence.id, + "company_id": self.company1.id, + "default_pricelist_id": self.pricelist2.id, } ) # pms.room.type.class @@ -90,7 +49,7 @@ class TestPmsRoomTypeAvailabilityRules(common.SavepointCase): # 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_property3.id], "name": "Single Test", "default_code": "SNG_Test", "class_id": self.test_room_type_class.id, @@ -100,7 +59,7 @@ class TestPmsRoomTypeAvailabilityRules(common.SavepointCase): self.test_room_type_double = self.env["pms.room.type"].create( { "pms_property_ids": [ - (4, self.test_property.id), + (4, self.pms_property3.id), ], "name": "Double Test", "default_code": "DBL_Test", @@ -110,7 +69,7 @@ class TestPmsRoomTypeAvailabilityRules(common.SavepointCase): # pms.room self.test_room1_double = self.env["pms.room"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property3.id, "name": "Double 201 test", "room_type_id": self.test_room_type_double.id, "capacity": 2, @@ -119,34 +78,15 @@ class TestPmsRoomTypeAvailabilityRules(common.SavepointCase): # pms.room self.test_room2_double = self.env["pms.room"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property3.id, "name": "Double 202 test", "room_type_id": self.test_room_type_double.id, "capacity": 2, } ) - # pms.room - # self.test_room3_double = self.env["pms.room"].create( - # { - # "pms_property_id": self.test_property.id, - # "name": "Double 203 test", - # "room_type_id": self.test_room_type_double.id, - # "capacity": 2, - # } - # ) - # # pms.room - # self.test_room4_double = self.env["pms.room"].create( - # { - # "pms_property_id": self.test_property.id, - # "name": "Double 204 test", - # "room_type_id": self.test_room_type_double.id, - # "capacity": 2, - # } - # ) - # pms.room self.test_room1_single = self.env["pms.room"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property3.id, "name": "Single 101 test", "room_type_id": self.test_room_type_single.id, "capacity": 1, @@ -155,7 +95,7 @@ class TestPmsRoomTypeAvailabilityRules(common.SavepointCase): # pms.room self.test_room2_single = self.env["pms.room"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property3.id, "name": "Single 102 test", "room_type_id": self.test_room_type_single.id, "capacity": 1, @@ -165,41 +105,42 @@ class TestPmsRoomTypeAvailabilityRules(common.SavepointCase): self.partner1 = self.env["res.partner"].create({"name": "Charles"}) def create_scenario_multiproperty(self): - self.create_common_scenario() - self.test_property3 = self.env["pms.property"].create( + self.pms_property4 = self.env["pms.property"].create( { "name": "Property 3", - "company_id": self.env.ref("base.main_company").id, - "default_pricelist_id": self.test_pricelist2.id, - "folio_sequence_id": self.folio_sequence.id, - "reservation_sequence_id": self.reservation_sequence.id, - "checkin_sequence_id": self.checkin_sequence.id, + "company_id": self.company1.id, + "default_pricelist_id": self.pricelist1.id, } ) self.availability_multiproperty = self.env["pms.availability.plan"].create( { "name": "Availability plan for TEST", - "pms_pricelist_ids": [(6, 0, [self.test_pricelist1.id])], + "pms_pricelist_ids": [(6, 0, [self.pricelist2.id])], "pms_property_ids": [ - (4, self.test_property1.id), - (4, self.test_property2.id), + (4, self.pms_property1.id), + (4, self.pms_property2.id), ], } ) def test_availability_rooms_all(self): - # TEST CASE - # get availability withouth rules + """ + Check the availability of rooms in a property with an availability plan without + availability rules. + --------------------- + The checkin and checkout dates on which the availability will be checked are saved + in a variable and in another all the rooms of the property are also saved. Then the + rooms_available() method is launched which should return the number of available rooms + of the property and they are saved in another variable with which it is verified that + all the rooms have been returned because there are no availability rules for that plan. + """ # ARRANGE - self.create_common_scenario() - checkin = fields.date.today() checkout = (fields.datetime.today() + datetime.timedelta(days=4)).date() test_rooms_double_rooms = self.env["pms.room"].search( - [("pms_property_id", "=", self.test_property.id)] + [("pms_property_id", "=", self.pms_property3.id)] ) - # ACT result = self.env["pms.availability.plan"].rooms_available( checkin=checkin, @@ -214,20 +155,29 @@ class TestPmsRoomTypeAvailabilityRules(common.SavepointCase): ) def test_availability_rooms_all_lines(self): - # TEST CASE - # get availability withouth rules - # given reservation lines to not consider + """ + Check the availability of rooms in a property with an availability plan without + availability rules and passing it the reservation lines of a reservation for that + property. + ----------------- + The checkin and checkout dates on which the availability will be checked are saved + in a variable and in another all the rooms of the property are also saved. Then create + a reservation for this property and the rooms_available() method is launched with the + parameters checkin, checkout and the reservation lines of the reservation as a curent + lines, this method should return the number of available rooms of the property. Then the + result is saved in another variable with which it is verified that all the rooms have + been returned because there are no availability rules for that plan. + """ # ARRANGE - self.create_common_scenario() checkin = fields.date.today() checkout = (fields.datetime.today() + datetime.timedelta(days=4)).date() test_rooms_double_rooms = self.env["pms.room"].search( - [("pms_property_id", "=", self.test_property.id)] + [("pms_property_id", "=", self.pms_property3.id)] ) test_reservation = self.env["pms.reservation"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property3.id, "checkin": checkin, "checkout": checkout, "partner_id": self.partner1.id, @@ -249,19 +199,22 @@ class TestPmsRoomTypeAvailabilityRules(common.SavepointCase): ) def test_availability_rooms_room_type(self): - # TEST CASE - # get availability withouth rules - # given a room type + """ + Check the availability of a room type for a property. + ---------------- + Double rooms of a property are saved in a variable. The rooms_available() method + is launched giving as parameters checkin, checkout and the type of room (in this + case double). Then with the all () function we check that all rooms of this type + were returned. + """ # ARRANGE - self.create_common_scenario() test_rooms_double_rooms = self.env["pms.room"].search( [ - ("pms_property_id", "=", self.test_property.id), + ("pms_property_id", "=", self.pms_property3.id), ("room_type_id", "=", self.test_room_type_double.id), ] ) - # ACT result = self.env["pms.availability.plan"].rooms_available( checkin=fields.date.today(), @@ -278,14 +231,18 @@ class TestPmsRoomTypeAvailabilityRules(common.SavepointCase): ) def test_availability_closed_no_room_type(self): - # TEST CASE: - # coverage for 2 points: - # 1. without room type, availability rules associated - # with the pricelist are applied - # 2. availability rule "closed" is taken into account - + """ + Check that rooms of a type with an availability rule with closed = True are + not available on the dates marked in the date field of the availability rule. + -------------------- + Create an availability rule for double rooms with the field closed = true + and the date from today until tomorrow. Then the availability is saved in a + variable through the rooms_available() method, passing it the pricelist that + it contains the availability plan where the rule is included, and the checkin + and checkout dates are between the date of the rule. Then it is verified that + the double rooms are not available. + """ # ARRANGE - self.create_common_scenario() self.test_room_type_availability_rule1 = self.env[ "pms.availability.plan.rule" ].create( @@ -294,7 +251,7 @@ class TestPmsRoomTypeAvailabilityRules(common.SavepointCase): "room_type_id": self.test_room_type_double.id, "date": (fields.datetime.today() + datetime.timedelta(days=2)).date(), "closed": True, # <- (1/2) - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property3.id, } ) # ACT @@ -302,7 +259,7 @@ class TestPmsRoomTypeAvailabilityRules(common.SavepointCase): checkin=fields.date.today(), checkout=(fields.datetime.today() + datetime.timedelta(days=4)).date(), # room_type_id=False, # <- (2/2) - pricelist_id=self.test_pricelist1.id, + pricelist_id=self.pricelist2.id, ) # ASSERT self.assertNotIn( @@ -313,13 +270,25 @@ class TestPmsRoomTypeAvailabilityRules(common.SavepointCase): ) def test_availability_rules(self): - # TEST CASE - # the availability should take into acount availability rules: - # closed_arrival, closed_departure, min_stay, max_stay, - # min_stay_arrival, max_stay_arrival + """ + Check through subtests that the availability rules are applied + for a specific room type. + ---------------- + Test cases: + 1. closed_arrival = True + 2. closed_departure = True + 3. min_stay = 5 + 4. max_stay = 2 + 5. min_stay_arrival = 5 + 6. max_stay_arrival = 3 + 7. quota = 0 + 8. max_avail = 0 + For each test case, it is verified through the rooms_available() method, + that double rooms are not available since the rules are applied to this + room type. + """ # ARRANGE - self.create_common_scenario() self.test_room_type_availability_rule1 = self.env[ "pms.availability.plan.rule" @@ -327,8 +296,8 @@ class TestPmsRoomTypeAvailabilityRules(common.SavepointCase): { "availability_plan_id": self.test_room_type_availability1.id, "room_type_id": self.test_room_type_double.id, - "date": (fields.datetime.today() + datetime.timedelta(days=0)).date(), - "pms_property_id": self.test_property.id, + "date": fields.date.today(), + "pms_property_id": self.pms_property3.id, } ) @@ -444,7 +413,7 @@ class TestPmsRoomTypeAvailabilityRules(common.SavepointCase): checkin=checkin, checkout=checkout, room_type_id=self.test_room_type_double.id, - pricelist_id=self.test_pricelist1.id, + pricelist_id=self.pricelist2.id, ) # ASSERT @@ -455,14 +424,18 @@ class TestPmsRoomTypeAvailabilityRules(common.SavepointCase): "which its availability rules applies", ) - @freeze_time("1980-11-01") def test_rule_on_create_reservation(self): - # TEST CASE - # an availability rule should be applied that would prevent the - # creation of reservations + """ + Check that a reservation is not created when an availability rule prevents it . + ------------------- + Create an availability rule for double rooms with the + field closed = True and the date from today until tomorrow. Then try to create + a reservation for that type of room with a checkin date today and a checkout + date within 4 days. This should throw a ValidationError since the rule does + not allow creating reservations for those dates. + """ # ARRANGE - self.create_common_scenario() self.test_room_type_availability_rule1 = self.env[ "pms.availability.plan.rule" ].create( @@ -471,7 +444,7 @@ class TestPmsRoomTypeAvailabilityRules(common.SavepointCase): "room_type_id": self.test_room_type_double.id, "date": (fields.datetime.today() + datetime.timedelta(days=2)).date(), "closed": True, - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property3.id, } ) checkin = datetime.datetime.now() @@ -485,89 +458,24 @@ class TestPmsRoomTypeAvailabilityRules(common.SavepointCase): ): self.env["pms.reservation"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property3.id, "checkin": checkin, "checkout": checkout, "adults": 2, "room_type_id": self.test_room_type_double.id, - "pricelist_id": self.test_pricelist1.id, + "pricelist_id": self.pricelist2.id, "partner_id": self.partner1.id, } ) - @freeze_time("1980-11-01") - def test_rules_on_create_splitted_reservation(self): - # TEST CASE - # an availability rule should be applied that would prevent the - # creation of reservations including splitted reservations. - - # ARRANGE - self.create_common_scenario() - self.test_room_type_availability_rule1 = self.env[ - "pms.availability.plan.rule" - ].create( - { - "availability_plan_id": self.test_room_type_availability1.id, - "room_type_id": self.test_room_type_double.id, - "date": (fields.datetime.today() + datetime.timedelta(days=2)).date(), - "closed": True, - "pms_property_id": self.test_property.id, - } - ) - - checkin_test = datetime.datetime.now() - checkout_test = datetime.datetime.now() + datetime.timedelta(days=4) - - self.env["pms.reservation"].create( - { - "pms_property_id": self.test_property.id, - "checkin": datetime.datetime.now(), - "checkout": datetime.datetime.now() + datetime.timedelta(days=2), - "adults": 2, - "room_type_id": self.test_room_type_double.id, - "preferred_room_id": self.test_room1_double.id, - "partner_id": self.partner1.id, - } - ) - - self.env["pms.reservation"].create( - { - "pms_property_id": self.test_property.id, - "checkin": datetime.datetime.now() + datetime.timedelta(days=2), - "checkout": datetime.datetime.now() + datetime.timedelta(days=4), - "adults": 2, - "room_type_id": self.test_room_type_double.id, - "preferred_room_id": self.test_room2_double.id, - "partner_id": self.partner1.id, - } - ) - - # ACT & ASSERT - with self.assertRaises( - ValidationError, - msg="Availability rule should be applied that would" - " prevent the creation of splitted reservation.", - ): - self.env["pms.reservation"].create( - { - "pms_property_id": self.test_property.id, - "checkin": checkin_test, - "checkout": checkout_test, - "adults": 2, - "room_type_id": self.test_room_type_double.id, - "pricelist_id": self.test_pricelist1.id, - "partner_id": self.partner1.id, - } - ) - - @freeze_time("1980-11-01") def test_rule_update_quota_on_create_reservation(self): - # TEST CASE - # quota rule is changed after creating a reservation - # with pricelist linked to a availability plan that applies + """ + Check that the availability rule with quota = 1 for a room + type does not allow you to create more reservations than 1 + for that room type. + """ # ARRANGE - self.create_common_scenario() self.test_room_type_availability_rule1 = self.env[ "pms.availability.plan.rule" @@ -577,22 +485,22 @@ class TestPmsRoomTypeAvailabilityRules(common.SavepointCase): "room_type_id": self.test_room_type_double.id, "date": datetime.date.today(), "quota": 1, - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property3.id, } ) - self.test_pricelist1.pms_property_ids = [ - (4, self.test_property1.id), - (4, self.test_property2.id), - (4, self.test_property.id), + self.pricelist2.pms_property_ids = [ + (4, self.pms_property1.id), + (4, self.pms_property2.id), + (4, self.pms_property3.id), ] r1 = self.env["pms.reservation"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property3.id, "checkin": datetime.date.today(), "checkout": datetime.date.today() + datetime.timedelta(days=1), "adults": 2, "room_type_id": self.test_room_type_double.id, - "pricelist_id": self.test_pricelist1.id, + "pricelist_id": self.pricelist2.id, "partner_id": self.partner1.id, } ) @@ -603,36 +511,35 @@ class TestPmsRoomTypeAvailabilityRules(common.SavepointCase): ): self.env["pms.reservation"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property3.id, "checkin": datetime.date.today(), "checkout": datetime.date.today() + datetime.timedelta(days=1), "adults": 2, "room_type_id": self.test_room_type_double.id, - "pricelist_id": self.test_pricelist1.id, + "pricelist_id": self.pricelist2.id, "partner_id": self.partner1.id, } ) - @freeze_time("1980-11-01") def test_rule_update_quota_on_update_reservation(self): - # TEST CASE - # quota rule is restored after creating a reservation - # with pricelist linked to a availability rule that applies - # and then modify the pricelist of the reservation and - # no rules applies - + """ + Checks that an availability rule is maintained if its pricelist is modified. + --------------------- + Quota rule is restored after creating a reservation with pricelist linked + to an availability rule that applies and then modify the pricelist of the + reservation and no rules applies + """ # ARRANGE - self.create_common_scenario() test_quota = 2 test_pricelist2 = self.env["product.pricelist"].create( { "name": "test pricelist 2", } ) - self.test_pricelist1.pms_property_ids = [ - (4, self.test_property1.id), - (4, self.test_property2.id), - (4, self.test_property.id), + self.pricelist2.pms_property_ids = [ + (4, self.pms_property1.id), + (4, self.pms_property2.id), + (4, self.pms_property3.id), ] rule = self.env["pms.availability.plan.rule"].create( { @@ -640,17 +547,17 @@ class TestPmsRoomTypeAvailabilityRules(common.SavepointCase): "room_type_id": self.test_room_type_double.id, "date": datetime.date.today(), "quota": test_quota, - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property3.id, } ) reservation = self.env["pms.reservation"].create( { - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property3.id, "checkin": datetime.date.today(), "checkout": datetime.date.today() + datetime.timedelta(days=1), "adults": 2, "room_type_id": self.test_room_type_double.id, - "pricelist_id": self.test_pricelist1.id, + "pricelist_id": self.pricelist2.id, "partner_id": self.partner1.id, } ) @@ -665,19 +572,20 @@ class TestPmsRoomTypeAvailabilityRules(common.SavepointCase): ) def test_availability_closed_no_room_type_check_property(self): - # TEST CASE: - # check that availability rules are applied to the correct properties - # There are two properties: - # test_property --> test_room_type_availability_rule1 - # test_property2 --> test_room_type_availability_rule2 - + """ + Check that availability rules are applied to the correct properties. + ---------- + Check that for that date test_property1 doesnt have rooms available + (of that type:test_room_type_special), + instead, property2 has test_room_type_special available + """ # ARRANGE self.create_scenario_multiproperty() self.test_room_type_special = self.env["pms.room.type"].create( { "pms_property_ids": [ - (4, self.test_property1.id), - (4, self.test_property2.id), + (4, self.pms_property1.id), + (4, self.pms_property2.id), ], "name": "Special Room Test", "default_code": "SP_Test", @@ -686,7 +594,7 @@ class TestPmsRoomTypeAvailabilityRules(common.SavepointCase): ) self.test_room1 = self.env["pms.room"].create( { - "pms_property_id": self.test_property1.id, + "pms_property_id": self.pms_property1.id, "name": "Double 201 test", "room_type_id": self.test_room_type_special.id, "capacity": 2, @@ -695,7 +603,7 @@ class TestPmsRoomTypeAvailabilityRules(common.SavepointCase): # pms.room self.test_room2 = self.env["pms.room"].create( { - "pms_property_id": self.test_property2.id, + "pms_property_id": self.pms_property2.id, "name": "Double 202 test", "room_type_id": self.test_room_type_special.id, "capacity": 2, @@ -709,7 +617,7 @@ class TestPmsRoomTypeAvailabilityRules(common.SavepointCase): "room_type_id": self.test_room_type_special.id, "date": (fields.datetime.today() + datetime.timedelta(days=2)).date(), "closed": True, - "pms_property_id": self.test_property1.id, + "pms_property_id": self.pms_property1.id, } ) self.test_room_type_availability_rule2 = self.env[ @@ -719,16 +627,13 @@ class TestPmsRoomTypeAvailabilityRules(common.SavepointCase): "availability_plan_id": self.availability_multiproperty.id, "room_type_id": self.test_room_type_special.id, "date": (fields.datetime.today() + datetime.timedelta(days=2)).date(), - "pms_property_id": self.test_property2.id, + "pms_property_id": self.pms_property2.id, } ) - # check that for that date test_property1 doesnt have rooms available - # (of that type:test_room_type_double), - # instead, property2 has test_room_type_double available properties = [ - {"property": self.test_property1.id, "value": False}, - {"property": self.test_property2.id, "value": True}, + {"property": self.pms_property1.id, "value": False}, + {"property": self.pms_property2.id, "value": True}, ] for p in properties: @@ -740,7 +645,7 @@ class TestPmsRoomTypeAvailabilityRules(common.SavepointCase): fields.datetime.today() + datetime.timedelta(days=2) ).date(), room_type_id=self.test_room_type_special.id, - pricelist_id=self.test_pricelist1.id, + pricelist_id=self.pricelist2.id, pms_property_id=p["property"], ) # ASSERT @@ -749,17 +654,27 @@ class TestPmsRoomTypeAvailabilityRules(common.SavepointCase): ) def test_check_property_availability_room_type(self): - # TEST CASE: - # check integrity between availability properties and room_type properties + """ + Check integrity between availability properties and room_type properties. + Test cases when creating a availability_rule: + Allowed properties: + Room Type(test_room_type_special) --> pms_property1, pms_property_4 + Availability Plan(availability_example) --> pms_property1, pms_property2 + Both cases throw an exception: + # 1:Rule for property2, + # it is allowed in availability_plan but not in room_type + # 2:Rule for property4, + # it is allowed in room_type, but not in availability_plan + """ # ARRANGE self.create_scenario_multiproperty() # create new room_type self.test_room_type_special = self.env["pms.room.type"].create( { "pms_property_ids": [ - (4, self.test_property1.id), - (4, self.test_property3.id), + (4, self.pms_property1.id), + (4, self.pms_property4.id), ], "name": "Special Room Test", "default_code": "SP_Test", @@ -770,10 +685,10 @@ class TestPmsRoomTypeAvailabilityRules(common.SavepointCase): self.availability_example = self.env["pms.availability.plan"].create( { "name": "Availability plan for TEST", - "pms_pricelist_ids": [(6, 0, [self.test_pricelist1.id])], + "pms_pricelist_ids": [(6, 0, [self.pricelist2.id])], "pms_property_ids": [ - (4, self.test_property1.id), - (4, self.test_property2.id), + (4, self.pms_property1.id), + (4, self.pms_property2.id), ], } ) @@ -783,26 +698,16 @@ class TestPmsRoomTypeAvailabilityRules(common.SavepointCase): "room_type_id": self.test_room_type_special.id, "date": (fields.datetime.today() + datetime.timedelta(days=2)).date(), "closed": True, - "pms_property_id": self.test_property1.id, + "pms_property_id": self.pms_property1.id, } ) - # Test cases when creating a availability_rule - # Allowed properties: - # Room Type(test_room_type_special) -->TEST_PROPERTY1 TEST_PROPERTY3 - # Availability Plan(availability_example)-->TEST_PROPERTY1 TEST_PROPERTY2 - - # Both cases throw an exception: - # 1:Rule for property2, - # it is allowed in availability_plan but not in room_type - # 2:Rule for property3, - # it is allowed in room_type, but not in availability_plan test_cases = [ { - "pms_property_id": self.test_property2.id, + "pms_property_id": self.pms_property2.id, }, { - "pms_property_id": self.test_property3.id, + "pms_property_id": self.pms_property4.id, }, ] # ASSERT diff --git a/pms/tests/test_pms_folio_sale_line.py b/pms/tests/test_pms_folio_sale_line.py index 6dd1a7da3..1d9f21851 100644 --- a/pms/tests/test_pms_folio_sale_line.py +++ b/pms/tests/test_pms_folio_sale_line.py @@ -32,6 +32,47 @@ class TestPmsFolioSaleLine(TestPms): } ) + self.product_test1 = self.env["product.product"].create( + { + "name": "Test Product 1", + "per_day": True, + } + ) + self.product_test2 = self.env["product.product"].create( + { + "name": "Test Product 1", + "per_day": True, + "consumed_on": "after", + } + ) + self.board_service_test = self.board_service = self.env[ + "pms.board.service" + ].create( + { + "name": "Test Board Service", + "default_code": "TPS", + } + ) + self.env["pms.board.service.line"].create( + { + "pms_board_service_id": self.board_service_test.id, + "product_id": self.product_test1.id, + "amount": 8, + } + ) + self.board_service_room_type = self.env["pms.board.service.room.type"].create( + { + "pms_room_type_id": self.room_type_double.id, + "pms_board_service_id": self.board_service_test.id, + } + ) + self.extra_service = self.env["pms.service"].create( + { + "is_board_service": False, + "product_id": self.product_test2.id, + } + ) + # RESERVATION LINES def test_comp_fsl_rooms_all_same_group(self): """ @@ -91,9 +132,15 @@ class TestPmsFolioSaleLine(TestPms): ) def test_comp_fsl_rooms_different_prices(self): - # TEST CASE - # 2-night reservation and different price per night - # should generate 2 reservation sale lines + """ + Check that a reservation with two nights and different prices per + night generates two sale lines. + ------------ + Create a reservation with a double room as a room type and 2 nights, + which has a price of 25.0 per night. Then the price of one of the reservation + lines is changed to 50.0. As there are two different prices per + night in the reservation the sale lines of the folio should be 2 . + """ # ARRANGE expected_sale_lines = 2 @@ -121,9 +168,15 @@ class TestPmsFolioSaleLine(TestPms): ) def test_comp_fsl_rooms_different_discount(self): - # TEST CASE - # 2-night reservationwith different discount per night - # should generate 2 reservation sale lines + """ + Check that a reservation with two nights and different discount per + night generates two sale lines. + ------------ + Create a reservation with a double room as a room type and 2 nights, which has + a default discount of 0 per night. Then the discount of one of the reservation + lines is changed to 50.0. As there are two different discounts per night in the + reservation the sale lines of the folio should be 2. + """ # ARRANGE expected_sale_lines = 2 @@ -151,9 +204,17 @@ class TestPmsFolioSaleLine(TestPms): ) def test_comp_fsl_rooms_different_cancel_discount(self): - # TEST CASE - # 2-night-reservation with different discount per night - # should generate 2 reservation sale lines + """ + Check that a reservation with two nights and different cancel + discount per night generates two sale lines. + ------------ + Create a reservation with a double room as a room type and 2 nights, + which has a default cancel discount of 0 per night. Then the cancel discount + of one of the reservation lines is changed to 50.0. As there are two + different cancel discount per night in the reservation the sale lines of + the folio should be 2. As one of the reservation lines has a 100% cancel + discount, the sale line should be 1 . + """ # ARRANGE expected_sale_lines = 2 @@ -181,11 +242,14 @@ class TestPmsFolioSaleLine(TestPms): ) def test_comp_fsl_rooms_one_full_cancel_discount(self): - # TEST CASE - # 2-night reservation with 100% cancel discount for 1 night - # should generate just 1 reservation sale line because the - # full cancel discount shouldn't be present @ invoice lines - + """ + Check that a reservation with a 100% cancel discount on one night + does not generate different sale lines. + ---------------- + Create a reservation with a double room as a room type, which has + a default cancel discount of 0 per night. Then the cancel discount + of one of the reservation lines is changed to 100.0. + """ # ARRANGE expected_sale_lines = 1 r_test = self.env["pms.reservation"].create( @@ -213,11 +277,16 @@ class TestPmsFolioSaleLine(TestPms): ) def test_comp_fsl_rooms_increase_stay(self): - # TEST CASE - # 2-night reservation increases 1 night with the same price, - # discount and cancel discount for all the reservation nights - # Should keep the same reservation sales line record. - + """ + Check when adding a night to a reservation after creating it and this night + has the same price, cancel and cancel discount values, the sales line that + were created with the reservation are maintained. + --------- + Create a reservation of 2 nights for a double room. The value of the sale lines + of that reservation is stored in a variable. Then one more night is added to the + reservation and it is verified that the sale lines are the same as the value of + the previously saved variable. + """ # ARRANGE r_test = self.env["pms.reservation"].create( { @@ -247,11 +316,15 @@ class TestPmsFolioSaleLine(TestPms): ) def test_comp_fsl_rooms_decrease_stay(self): - # TEST CASE - # 2-night reservation decreases 1 night with the same price, - # discount & cancel_discount for all the reservation nights - # Should keep the same reservation sales line record. - + """ + Check when a night is removed from a reservation after creating + it, the sales lines that were created with the reservation are kept. + --------- + Create a reservation of 2 nights for a double room. The value of the sale lines + of that reservation is stored in a variable. Then it is removed one night at + reservation and it is verified that the reservation sale lines are equal to the value of + the previously saved variable. + """ # ARRANGE r_test = self.env["pms.reservation"].create( { @@ -281,12 +354,18 @@ class TestPmsFolioSaleLine(TestPms): ) def test_comp_fsl_rooms_same_stay(self): - # TEST CASE - # Price is changed for all nights of a 2-night reservation. But - # price, discount & cancel discount after the change is the same - # for all nights. - # Should keep the same reservation sales line record. - + """ + Check that when changing the price of all the reservation lines in a + reservation, which before the change had the same price, discount + and cancel discount values, the same sale lines that existed before + the change are kept. + ------------------ + Create a reservation of 2 nights for a double room with a price of 25.0. + The value of the sale lines of that reservation is stored in a variable. + Then the value of the price of all the reservation lines is changed to 50.0 + and it is verified that the reservation sale lines are equal to the value + of the previously saved variable. + """ # ARRANGE r_test = self.env["pms.reservation"].create( { @@ -317,38 +396,17 @@ class TestPmsFolioSaleLine(TestPms): # BOARD SERVICES def test_comp_fsl_board_services_all_same_group(self): - # TEST CASE - # 2-night reservation and same price, discount & cancel_discount for - # all reservation board services - # should generate just 1 board service sale line + """ + Check that the board services of reservation with the same price, discount + and cancel discount values, should only generate one sale line. + ---------------- + Create a reservation of 2 nights, for a double room with a board service + room per night. Then it is verified that the length of the sale lines of the + board services in the reservation is equal to 1. + """ # ARRANGE expected_board_service_sale_lines = 1 - product_test1 = self.env["product.product"].create( - { - "name": "Test Product 1", - "per_day": True, - } - ) - board_service_test = self.board_service = self.env["pms.board.service"].create( - { - "name": "Test Board Service", - "default_code": "TPS", - } - ) - self.env["pms.board.service.line"].create( - { - "pms_board_service_id": board_service_test.id, - "product_id": product_test1.id, - "amount": 8, - } - ) - board_service_room_type = self.env["pms.board.service.room.type"].create( - { - "pms_room_type_id": self.room_type_double.id, - "pms_board_service_id": board_service_test.id, - } - ) # ACT r_test = self.env["pms.reservation"].create( @@ -359,7 +417,7 @@ class TestPmsFolioSaleLine(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.env.ref("base.res_partner_12").id, - "board_service_room_id": board_service_room_type.id, + "board_service_room_id": self.board_service_room_type.id, } ) @@ -377,38 +435,18 @@ class TestPmsFolioSaleLine(TestPms): ) def test_comp_fsl_board_services_different_prices(self): - # TEST CASE - # 2-night reservation and different price per day on board services - # should generate just 1 board service sale line - + """ + Check that the board services of reservation with different prices + should generate several sale lines. + ---------------- + Create a reservation of 2 nights, for a double room with a board service + room per night. Then change the price of the first board service line to + 1.0 and it is verified that the length of the sale lines of the board services + in the reservation is equal to 2 because there are 2 different board service + prices in the reservation. + """ # ARRANGE expected_board_service_sale_lines = 2 - product_test1 = self.env["product.product"].create( - { - "name": "Test Product 1", - "per_day": True, - } - ) - - board_service_test = self.board_service = self.env["pms.board.service"].create( - { - "name": "Test Board Service", - "default_code": "TPS", - } - ) - self.env["pms.board.service.line"].create( - { - "pms_board_service_id": board_service_test.id, - "product_id": product_test1.id, - "amount": 8, - } - ) - board_service_room_type = self.env["pms.board.service.room.type"].create( - { - "pms_room_type_id": self.room_type_double.id, - "pms_board_service_id": board_service_test.id, - } - ) r_test = self.env["pms.reservation"].create( { "pms_property_id": self.pms_property1.id, @@ -417,7 +455,7 @@ class TestPmsFolioSaleLine(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.env.ref("base.res_partner_12").id, - "board_service_room_id": board_service_room_type.id, + "board_service_room_id": self.board_service_room_type.id, } ) r_test.service_ids[0].service_line_ids[0].price_unit = 1.0 @@ -436,38 +474,18 @@ class TestPmsFolioSaleLine(TestPms): ) def test_comp_fsl_board_services_different_discount(self): - # TEST CASE - # 2-night reservation and different discount per day on board services - # should generate 2 board service sale lines - + """ + Check that the board services of reservation with different discounts + should generate several sale lines. + ---------------- + Create a reservation of 2 nights, for a double room with a board service + room per night. Then change the discount of the first board service line + to 1.0 and it is verified that the length of the sale lines of the board services + in the reservation is equal to 2 because there are 2 different board service + discounts in the reservation. + """ # ARRANGE expected_board_service_sale_lines = 2 - product_test1 = self.env["product.product"].create( - { - "name": "Test Product 1", - "per_day": True, - } - ) - - board_service_test = self.board_service = self.env["pms.board.service"].create( - { - "name": "Test Board Service", - "default_code": "TPS", - } - ) - self.env["pms.board.service.line"].create( - { - "pms_board_service_id": board_service_test.id, - "product_id": product_test1.id, - "amount": 8, - } - ) - board_service_room_type = self.env["pms.board.service.room.type"].create( - { - "pms_room_type_id": self.room_type_double.id, - "pms_board_service_id": board_service_test.id, - } - ) r_test = self.env["pms.reservation"].create( { "pms_property_id": self.pms_property1.id, @@ -476,7 +494,7 @@ class TestPmsFolioSaleLine(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.env.ref("base.res_partner_12").id, - "board_service_room_id": board_service_room_type.id, + "board_service_room_id": self.board_service_room_type.id, } ) @@ -497,39 +515,19 @@ class TestPmsFolioSaleLine(TestPms): ) def test_comp_fsl_board_services_different_cancel_discount(self): - # TEST CASE - # 2-night reservation and different cancel discount per day on - # board services - # should generate 2 board service sale lines + """ + Check that the board services of reservation with different cancel + discounts should generate several sale lines. + ---------------- + Create a reservation of 2 nights, for a double room with a board service + room per night. Then change the cancel discount of the first board service line + to 1.0 and it is verified that the length of the sale lines of the board services + in the reservation is equal to 2 because there are 2 different board service + cancel discounts in the reservation. + """ # ARRANGE expected_board_service_sale_lines = 2 - product_test1 = self.env["product.product"].create( - { - "name": "Test Product 1", - "per_day": True, - } - ) - - board_service_test = self.board_service = self.env["pms.board.service"].create( - { - "name": "Test Board Service", - "default_code": "TPS", - } - ) - self.env["pms.board.service.line"].create( - { - "pms_board_service_id": board_service_test.id, - "product_id": product_test1.id, - "amount": 8, - } - ) - board_service_room_type = self.env["pms.board.service.room.type"].create( - { - "pms_room_type_id": self.room_type_double.id, - "pms_board_service_id": board_service_test.id, - } - ) r_test = self.env["pms.reservation"].create( { "pms_property_id": self.pms_property1.id, @@ -538,7 +536,7 @@ class TestPmsFolioSaleLine(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.env.ref("base.res_partner_12").id, - "board_service_room_id": board_service_room_type.id, + "board_service_room_id": self.board_service_room_type.id, } ) @@ -559,39 +557,18 @@ class TestPmsFolioSaleLine(TestPms): ) def test_comp_fsl_board_services_one_full_cancel_discount(self): - # TEST CASE - # 2-night reservation with 100% cancel discount for 1 board service - # should generate just 1 board service sale line because the - # full cancel discount shouldn't be present @ invoice lines + """ + Check that the board services of reservation with 100% cancel + discount should generate only 1 sale line. + ---------------- + Create a reservation of 2 nights, for a double room with a board service + room per night. Then change the cancel discount of the first board service line + to 100.0 and it is verified that the length of the sale lines of the board services + in the reservation is equal to 1. + """ # ARRANGE expected_board_service_sale_lines = 1 - product_test1 = self.env["product.product"].create( - { - "name": "Test Product 1", - "per_day": True, - } - ) - - board_service_test = self.board_service = self.env["pms.board.service"].create( - { - "name": "Test Board Service", - "default_code": "TPS", - } - ) - self.env["pms.board.service.line"].create( - { - "pms_board_service_id": board_service_test.id, - "product_id": product_test1.id, - "amount": 8, - } - ) - board_service_room_type = self.env["pms.board.service.room.type"].create( - { - "pms_room_type_id": self.room_type_double.id, - "pms_board_service_id": board_service_test.id, - } - ) r_test = self.env["pms.reservation"].create( { "pms_property_id": self.pms_property1.id, @@ -600,7 +577,7 @@ class TestPmsFolioSaleLine(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.env.ref("base.res_partner_12").id, - "board_service_room_id": board_service_room_type.id, + "board_service_room_id": self.board_service_room_type.id, } ) @@ -621,37 +598,19 @@ class TestPmsFolioSaleLine(TestPms): ) def test_comp_fsl_board_services_increase_stay(self): - # TEST CASE - # 2-night reservation increases 1 night with the same price, - # discount & cancel_discount for all the board services - # Should keep the same board service sales line record. + """ + Check when adding a night to a reservation with board services room, + after creating it and this board service has the same price, cancel + and cancel discount values, the sale lines that were created with the + reservation are kept. + --------- + Create a reservation of 2 nights for a double room with a board service. + The value of the sale lines of that board services is stored in a variable. + Then one more night is added to the reservation and it is verified that + the sale lines are the same as the value of the previously saved variable. + """ # ARRANGE - product_test1 = self.env["product.product"].create( - { - "name": "Test Product 1", - "per_day": True, - } - ) - board_service_test = self.board_service = self.env["pms.board.service"].create( - { - "name": "Test Board Service", - "default_code": "TPS", - } - ) - self.env["pms.board.service.line"].create( - { - "pms_board_service_id": board_service_test.id, - "product_id": product_test1.id, - "amount": 8, - } - ) - board_service_room_type = self.env["pms.board.service.room.type"].create( - { - "pms_room_type_id": self.room_type_double.id, - "pms_board_service_id": board_service_test.id, - } - ) r_test = self.env["pms.reservation"].create( { "pms_property_id": self.pms_property1.id, @@ -660,7 +619,7 @@ class TestPmsFolioSaleLine(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.env.ref("base.res_partner_12").id, - "board_service_room_id": board_service_room_type.id, + "board_service_room_id": self.board_service_room_type.id, } ) previous_folio_board_service_sale_line = r_test.folio_id.sale_line_ids.filtered( @@ -681,41 +640,19 @@ class TestPmsFolioSaleLine(TestPms): ) def test_comp_fsl_board_services_decrease_stay(self): - # TEST CASE - # 2-night reservation decreases 1 night with the same price, - # discount & cancel_discount for all the board services - # Should keep the same board service sales line record. + """ + Check when removing a night to a reservation with board services room, + after creating it and this board service has the same price, cancel + and cancel discount values, the sale lines that were created with the + reservation are kept. + --------- + Create a reservation of 2 nights for a double room with a board service. + The value of the sale lines of that board services is stored in a variable. + Then one night is removed to the reservation and it is verified that + the sale lines are the same as the value of the previously saved variable. + """ # ARRANGE - product_test1 = self.env["product.product"].create( - { - "name": "Test Product 1", - "per_day": True, - } - ) - - board_service_test = self.board_service = self.env["pms.board.service"].create( - { - "name": "Test Board Service", - "default_code": "TPS", - } - ) - - self.env["pms.board.service.line"].create( - { - "pms_board_service_id": board_service_test.id, - "product_id": product_test1.id, - "amount": 8, - } - ) - - board_service_room_type = self.env["pms.board.service.room.type"].create( - { - "pms_room_type_id": self.room_type_double.id, - "pms_board_service_id": board_service_test.id, - } - ) - r_test = self.env["pms.reservation"].create( { "pms_property_id": self.pms_property1.id, @@ -724,7 +661,7 @@ class TestPmsFolioSaleLine(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.env.ref("base.res_partner_12").id, - "board_service_room_id": board_service_room_type.id, + "board_service_room_id": self.board_service_room_type.id, } ) @@ -746,42 +683,19 @@ class TestPmsFolioSaleLine(TestPms): ) def test_comp_fsl_board_services_same_stay(self): - # TEST CASE - # Price is changed for all board services of a 2-night reservation. - # But price, discount & cancel discount after the change is the same - # for all nights. - # Should keep the same board service sales line record. - + """ + Check that when changing the price of all board services in a + reservation, which before the change had the same price, discount + and cancel discount values, the same sale lines that existed before + the change are kept. + ------------------ + Create a reservation of 2 nights for a double room with a board service + price of 8.0. The value of the sale lines of the board services is stored + in a variable. Then the value of the price of all the reservation board services + is changed to 50 and it is verified that the reservation sale lines are equal to + the value of the previously saved variable. + """ # ARRANGE - product_test1 = self.env["product.product"].create( - { - "name": "Test Product 1", - "per_day": True, - } - ) - - board_service_test = self.board_service = self.env["pms.board.service"].create( - { - "name": "Test Board Service", - "default_code": "TPS", - } - ) - - self.env["pms.board.service.line"].create( - { - "pms_board_service_id": board_service_test.id, - "product_id": product_test1.id, - "amount": 8, - } - ) - - board_service_room_type = self.env["pms.board.service.room.type"].create( - { - "pms_room_type_id": self.room_type_double.id, - "pms_board_service_id": board_service_test.id, - } - ) - r_test = self.env["pms.reservation"].create( { "pms_property_id": self.pms_property1.id, @@ -790,7 +704,7 @@ class TestPmsFolioSaleLine(TestPms): "adults": 2, "room_type_id": self.room_type_double.id, "partner_id": self.env.ref("base.res_partner_12").id, - "board_service_room_id": board_service_room_type.id, + "board_service_room_id": self.board_service_room_type.id, } ) @@ -815,21 +729,17 @@ class TestPmsFolioSaleLine(TestPms): # RESERVATION EXTRA DAILY SERVICES def test_comp_fsl_res_extra_services_all_same_group(self): - # TEST CASE - # 2-night reservation and same price, discount & cancel_discount for - # all reservation services - # should generate just 1 reservation service sale line - + """ + Check that when adding a service that is not a board service to a + reservation with the same price, cancel and cancel discount, the + number of sales lines is kept. + ------------------ + Create a 2 night reservation. Then a service is added with + is_board_service = False and it is verified that the length of + the sale lines of the reservation is 1. + """ # ARRANGE expected_extra_service_sale_lines = 1 - product_test1 = self.env["product.product"].create( - { - "name": "Test Product 1", - "per_day": True, - "consumed_on": "after", - # REVIEW 'before' -> create pms.service.line with price 0.0 - } - ) r_test = self.env["pms.reservation"].create( { "pms_property_id": self.pms_property1.id, @@ -840,15 +750,8 @@ class TestPmsFolioSaleLine(TestPms): "partner_id": self.env.ref("base.res_partner_12").id, } ) - extra_service = self.env["pms.service"].create( - { - "is_board_service": False, - "product_id": product_test1.id, - } - ) - # ACT - r_test.service_ids = [(4, extra_service.id)] + r_test.service_ids = [(4, self.extra_service.id)] r_test.service_ids.service_line_ids.flush() # ASSERT @@ -856,7 +759,7 @@ class TestPmsFolioSaleLine(TestPms): expected_extra_service_sale_lines, len( r_test.folio_id.sale_line_ids.filtered( - lambda x: x.service_id == extra_service + lambda x: x.service_id == self.extra_service ) ), "Folio should contain {} reservation service sale lines".format( @@ -865,20 +768,19 @@ class TestPmsFolioSaleLine(TestPms): ) def test_comp_fsl_res_extra_services_different_prices(self): - # TEST CASE - # 2-night reservation and different price per day on services - # should generate just 1 reservation service sale line + """ + Check that a reservation of several nights and with different + prices per day on services should generate several sale lines. + ----------------- + Create a reservation for 2 nights. Then add a service to this + reservation and the price of the first service line is changed + to 44.5. It is verified that the length of the reservation's sale + lines is equal to 2, because there are two different prices per day + for service lines. + """ # ARRANGE expected_extra_service_sale_lines = 2 - product_test1 = self.env["product.product"].create( - { - "name": "Test Product 1", - "per_day": True, - "consumed_on": "after", - # REVIEW 'before' -> create pms.service.line with price 0.0 - } - ) r_test = self.env["pms.reservation"].create( { "pms_property_id": self.pms_property1.id, @@ -889,13 +791,7 @@ class TestPmsFolioSaleLine(TestPms): "partner_id": self.env.ref("base.res_partner_12").id, } ) - extra_service = self.env["pms.service"].create( - { - "is_board_service": False, - "product_id": product_test1.id, - } - ) - r_test.service_ids = [(4, extra_service.id)] + r_test.service_ids = [(4, self.extra_service.id)] r_test.service_ids.service_line_ids.flush() # ACT @@ -907,7 +803,7 @@ class TestPmsFolioSaleLine(TestPms): expected_extra_service_sale_lines, len( r_test.folio_id.sale_line_ids.filtered( - lambda x: x.service_id == extra_service + lambda x: x.service_id == self.extra_service ) ), "Folio should contain {} reservation service sale lines".format( @@ -916,20 +812,19 @@ class TestPmsFolioSaleLine(TestPms): ) def test_comp_fsl_res_extra_services_different_discount(self): - # TEST CASE - # 2-night reservation and different discount per day on reservation services - # should generate 2 reservation service sale lines + """ + Check that a reservation of several nights and with different + discount per day on services should generate several sale lines. + ----------------- + Create a reservation for 2 nights. Then add a service to this + reservation and the discount of the first service line is changed + to 44.5. It is verified that the length of the reservation's sale + lines is equal to 2, because there are two different discounts per day + for service lines. + """ # ARRANGE expected_extra_service_sale_lines = 2 - product_test1 = self.env["product.product"].create( - { - "name": "Test Product 1", - "per_day": True, - "consumed_on": "after", - # REVIEW 'before' -> create pms.service.line with price 0.0 - } - ) r_test = self.env["pms.reservation"].create( { "pms_property_id": self.pms_property1.id, @@ -940,13 +835,7 @@ class TestPmsFolioSaleLine(TestPms): "partner_id": self.env.ref("base.res_partner_12").id, } ) - extra_service = self.env["pms.service"].create( - { - "is_board_service": False, - "product_id": product_test1.id, - } - ) - r_test.service_ids = [(4, extra_service.id)] + r_test.service_ids = [(4, self.extra_service.id)] r_test.service_ids.service_line_ids.flush() # ACT @@ -958,7 +847,7 @@ class TestPmsFolioSaleLine(TestPms): expected_extra_service_sale_lines, len( r_test.folio_id.sale_line_ids.filtered( - lambda x: x.service_id == extra_service + lambda x: x.service_id == self.extra_service ) ), "Folio should contain {} reservation service sale lines".format( @@ -967,21 +856,20 @@ class TestPmsFolioSaleLine(TestPms): ) def test_comp_fsl_res_extra_services_different_cancel_discount(self): - # TEST CASE - # 2-night reservation and different cancel discount per day on - # reservation services - # should generate 2 reservation service sale lines + """ + Check that a reservation of several nights and with different + cancel discount per day on services should generate several sale + lines. + ----------------- + Create a reservation for 2 nights. Then add a service to this + reservation and the cancel discount of the first service line is changed + to 44.5. It is verified that the length of the reservation's sale + lines is equal to 2, because there are two different cancel discounts per + day for service lines. + """ # ARRANGE expected_extra_service_sale_lines = 2 - product_test1 = self.env["product.product"].create( - { - "name": "Test Product 1", - "per_day": True, - "consumed_on": "after", - # REVIEW 'before' -> create pms.service.line with price 0.0 - } - ) r_test = self.env["pms.reservation"].create( { "pms_property_id": self.pms_property1.id, @@ -992,13 +880,7 @@ class TestPmsFolioSaleLine(TestPms): "partner_id": self.env.ref("base.res_partner_12").id, } ) - extra_service = self.env["pms.service"].create( - { - "is_board_service": False, - "product_id": product_test1.id, - } - ) - r_test.service_ids = [(4, extra_service.id)] + r_test.service_ids = [(4, self.extra_service.id)] r_test.service_ids.service_line_ids.flush() # ACT @@ -1010,7 +892,7 @@ class TestPmsFolioSaleLine(TestPms): expected_extra_service_sale_lines, len( r_test.folio_id.sale_line_ids.filtered( - lambda x: x.service_id == extra_service + lambda x: x.service_id == self.extra_service ) ), "Folio should contain {} reservation service sale lines".format( @@ -1019,22 +901,18 @@ class TestPmsFolioSaleLine(TestPms): ) def test_comp_fsl_res_extra_services_one_full_cancel_discount(self): - # TEST CASE - # 2-night reservation with 100% cancelled discount for 1 reservation - # service - # should generate just 1 reservation service sale line because the - # full cancel discount shouldn't be present @ invoice lines + """ + Check that a reservation of several nights and with a 100% cancel + discount for a service should generate only 1 sale line. + ----------------- + Create a reservation for 2 nights. Then add a service to this + reservation and the cancel discount of the first service line is changed + to 100%. It is verified that the length of the reservation sale + lines is equal to 1. + """ # ARRANGE expected_extra_service_sale_lines = 1 - product_test1 = self.env["product.product"].create( - { - "name": "Test Product 1", - "per_day": True, - "consumed_on": "after", - # REVIEW 'before' -> create pms.service.line with price 0.0 - } - ) r_test = self.env["pms.reservation"].create( { "pms_property_id": self.pms_property1.id, @@ -1045,13 +923,7 @@ class TestPmsFolioSaleLine(TestPms): "partner_id": self.env.ref("base.res_partner_12").id, } ) - extra_service = self.env["pms.service"].create( - { - "is_board_service": False, - "product_id": product_test1.id, - } - ) - r_test.service_ids = [(4, extra_service.id)] + r_test.service_ids = [(4, self.extra_service.id)] r_test.service_ids.service_line_ids.flush() # ACT @@ -1063,7 +935,7 @@ class TestPmsFolioSaleLine(TestPms): expected_extra_service_sale_lines, len( r_test.folio_id.sale_line_ids.filtered( - lambda x: x.service_id == extra_service + lambda x: x.service_id == self.extra_service ) ), "Folio should contain {} reservation service sale lines".format( @@ -1072,20 +944,19 @@ class TestPmsFolioSaleLine(TestPms): ) def test_comp_fsl_res_extra_services_increase_stay(self): - # TEST CASE - # 2-night reservation increases 1 night with the same price, - # discount & cancel_discount for all the reservation services - # Should keep the same reservation service sales line record. + """ + Check when adding a night to a reservation after creating it and this services + has the same price, cancel and cancel discount values, the sales line that + were created with the reservation are maintained. + --------- + Create a reservation of 2 nights for a double room and add a service to this + reservation. The value of the sale lines of that reservation services is stored + in a variable. Then one more night is added to the reservation and it is verified + that the reservation service sale lines are the same as the value of the previously + saved variable. + """ # ARRANGE - product_test1 = self.env["product.product"].create( - { - "name": "Test Product 1", - "per_day": True, - "consumed_on": "after", - # REVIEW 'before' -> create pms.service.line with price 0.0 - } - ) r_test = self.env["pms.reservation"].create( { "pms_property_id": self.pms_property1.id, @@ -1096,16 +967,10 @@ class TestPmsFolioSaleLine(TestPms): "partner_id": self.env.ref("base.res_partner_12").id, } ) - extra_service = self.env["pms.service"].create( - { - "is_board_service": False, - "product_id": product_test1.id, - } - ) - r_test.service_ids = [(4, extra_service.id)] + r_test.service_ids = [(4, self.extra_service.id)] r_test.service_ids.service_line_ids.flush() previous_folio_extra_service_sale_line = r_test.folio_id.sale_line_ids.filtered( - lambda x: x.service_id == extra_service + lambda x: x.service_id == self.extra_service )[0] # ACT @@ -1116,27 +981,25 @@ class TestPmsFolioSaleLine(TestPms): self.assertEqual( previous_folio_extra_service_sale_line, r_test.folio_id.sale_line_ids.filtered( - lambda x: x.service_id == extra_service + lambda x: x.service_id == self.extra_service ), "Previous records of reservation service sales lines should not be " "deleted if it is not necessary", ) def test_comp_fsl_res_extra_services_decrease_stay(self): - # TEST CASE - # 2-night reservation decreases 1 night with the same price, - # discount & cancel_discount for all the reservation services - # Should keep the same reservation service sales line record. - + """ + Check when removing a night to a reservation after creating it and this services + has the same price, cancel and cancel discount values, the sales line that + were created with the reservation are maintained. + --------- + Create a reservation of 2 nights for a double room and add a service to this + reservation. The value of the sale lines of the services is stored + in a variable. Then one night is removed to the reservation and it is verified + that the reservation service sale lines are the same as the value of the previously + saved variable. + """ # ARRANGE - product_test1 = self.env["product.product"].create( - { - "name": "Test Product 1", - "per_day": True, - "consumed_on": "after", - # REVIEW 'before' -> create pms.service.line with price 0.0 - } - ) r_test = self.env["pms.reservation"].create( { "pms_property_id": self.pms_property1.id, @@ -1147,16 +1010,10 @@ class TestPmsFolioSaleLine(TestPms): "partner_id": self.env.ref("base.res_partner_12").id, } ) - extra_service = self.env["pms.service"].create( - { - "is_board_service": False, - "product_id": product_test1.id, - } - ) - r_test.service_ids = [(4, extra_service.id)] + r_test.service_ids = [(4, self.extra_service.id)] r_test.service_ids.service_line_ids.flush() previous_folio_extra_service_sale_line = r_test.folio_id.sale_line_ids.filtered( - lambda x: x.service_id == extra_service + lambda x: x.service_id == self.extra_service )[0] # ACT @@ -1167,7 +1024,7 @@ class TestPmsFolioSaleLine(TestPms): self.assertEqual( previous_folio_extra_service_sale_line, r_test.folio_id.sale_line_ids.filtered( - lambda x: x.service_id == extra_service + lambda x: x.service_id == self.extra_service ), "Previous records of reservation service sales lines should not be " "deleted if it is not necessary", @@ -1179,16 +1036,20 @@ class TestPmsFolioSaleLine(TestPms): # But price, discount & cancel discount after the change is the same # for all nights. # Should keep the same reservation service sales line record. + """ + Check that when changing the price of all services in a + reservation, which before the change had the same price, discount + and cancel discount values, the same sale lines that existed before + the change are kept. + ------------------ + Create a reservation of 2 nights for a double room and add a service to this + reservation. The value of the sale lines of the services is stored + in a variable. Then the value of the price of all the reservation services + is changed to 50 and it is verified that the reservation service sale lines + are equal to the value of the previously saved variable. + """ # ARRANGE - product_test1 = self.env["product.product"].create( - { - "name": "Test Product 1", - "per_day": True, - "consumed_on": "after", - # REVIEW 'before' -> create pms.service.line with price 0.0 - } - ) r_test = self.env["pms.reservation"].create( { "pms_property_id": self.pms_property1.id, @@ -1199,21 +1060,15 @@ class TestPmsFolioSaleLine(TestPms): "partner_id": self.env.ref("base.res_partner_12").id, } ) - extra_service = self.env["pms.service"].create( - { - "is_board_service": False, - "product_id": product_test1.id, - } - ) - r_test.service_ids = [(4, extra_service.id)] + r_test.service_ids = [(4, self.extra_service.id)] r_test.service_ids.service_line_ids.flush() previous_folio_extra_service_sale_line = r_test.folio_id.sale_line_ids.filtered( - lambda x: x.service_id == extra_service + lambda x: x.service_id == self.extra_service )[0] # ACT r_test.service_ids.filtered( - lambda x: x.id == extra_service.id + lambda x: x.id == self.extra_service.id ).service_line_ids.price_unit = 50 r_test.service_ids.service_line_ids.flush() @@ -1221,7 +1076,7 @@ class TestPmsFolioSaleLine(TestPms): self.assertEqual( previous_folio_extra_service_sale_line, r_test.folio_id.sale_line_ids.filtered( - lambda x: x.service_id == extra_service + lambda x: x.service_id == self.extra_service ), "Previous records of reservation service sales lines should not be " "deleted if it is not necessary", @@ -1232,14 +1087,17 @@ class TestPmsFolioSaleLine(TestPms): # TEST CASE # Folio with extra services # should generate 1 folio service sale line - + """ + Check that when adding a service that is not a board service to a + folio with the same price, cancel and cancel discount, the number + of sales lines is kept. + ------------------ + Create a 2 night reservation. Then a service is added with + is_board_service = False and it is verified that the length of + the sale lines of the folio is 1. + """ # ARRANGE expected_folio_service_sale_lines = 1 - product_test1 = self.env["product.product"].create( - { - "name": "Test Product 1", - } - ) r_test = self.env["pms.reservation"].create( { "pms_property_id": self.pms_property1.id, @@ -1250,15 +1108,9 @@ class TestPmsFolioSaleLine(TestPms): "partner_id": self.env.ref("base.res_partner_12").id, } ) - extra_service = self.env["pms.service"].create( - { - "is_board_service": False, - "product_id": product_test1.id, - } - ) # ACT - r_test.folio_id.service_ids = [(4, extra_service.id)] + r_test.folio_id.service_ids = [(4, self.extra_service.id)] r_test.folio_id.service_ids.service_line_ids.flush() # ASSERT @@ -1266,7 +1118,7 @@ class TestPmsFolioSaleLine(TestPms): expected_folio_service_sale_lines, len( r_test.folio_id.sale_line_ids.filtered( - lambda x: x.service_id == extra_service + lambda x: x.service_id == self.extra_service ) ), "Folio should contain {} folio service sale lines".format( @@ -1275,17 +1127,17 @@ class TestPmsFolioSaleLine(TestPms): ) def test_comp_fsl_fol_extra_services_two(self): - # TEST CASE - # Folio with 2 extra services (but the same product) - # Should generate 2 folio service sale line + """ + Check that when adding several services to a folio, + several sale lines should be generated on the folio. + ----------------- + Create a 2 night reservation. Two services are added + to the reservation and it is verified that the length + of the folio sale lines is equal to 2. + """ # ARRANGE expected_folio_service_sale_lines = 2 - product_test1 = self.env["product.product"].create( - { - "name": "Test Product 1", - } - ) product_test2 = self.env["product.product"].create( { "name": "Test Product 1", @@ -1302,12 +1154,6 @@ class TestPmsFolioSaleLine(TestPms): "partner_id": self.env.ref("base.res_partner_12").id, } ) - extra_service1 = self.env["pms.service"].create( - { - "is_board_service": False, - "product_id": product_test1.id, - } - ) extra_service2 = self.env["pms.service"].create( { @@ -1317,7 +1163,7 @@ class TestPmsFolioSaleLine(TestPms): ) # ACT - r_test.folio_id.service_ids = [(4, extra_service1.id)] + r_test.folio_id.service_ids = [(4, self.extra_service.id)] r_test.folio_id.service_ids = [(4, extra_service2.id)] r_test.folio_id.service_ids.service_line_ids.flush()