From 21327a86298694fa40546891def452157fc7de34 Mon Sep 17 00:00:00 2001 From: miguelpadin Date: Thu, 10 Jun 2021 13:01:19 +0200 Subject: [PATCH 1/9] [REF] pms: refactor test common (test_pms_sale_channel & test_pms_room) & fix res.partner (agency & sales channel 'direct' validationError) --- pms/models/res_partner.py | 4 + pms/tests/__init__.py | 41 ++++---- pms/tests/test_pms_room.py | 99 ++++++++++++++++++-- pms/tests/test_pms_sale_channel.py | 145 ++++++++++++++++++++++------- 4 files changed, 224 insertions(+), 65 deletions(-) diff --git a/pms/models/res_partner.py b/pms/models/res_partner.py index acaf9e88e..d92865fe6 100644 --- a/pms/models/res_partner.py +++ b/pms/models/res_partner.py @@ -113,6 +113,10 @@ class ResPartner(models.Model): for record in self: if record.is_agency and not record.sale_channel_id: raise models.ValidationError(_("Sale Channel must be entered")) + if record.is_agency and record.sale_channel_id.channel_type != "indirect": + raise models.ValidationError( + _("Sale Channel for an agency must be indirect") + ) if not record.is_agency and record.sale_channel_id: record.sale_channel_id = None diff --git a/pms/tests/__init__.py b/pms/tests/__init__.py index 48c50bbb2..8ac1c4a41 100644 --- a/pms/tests/__init__.py +++ b/pms/tests/__init__.py @@ -19,24 +19,25 @@ # along with this program. If not, see . # ############################################################################## -from . import test_pms_reservation -from . import test_pms_pricelist -from . import test_pms_pricelist_priority -from . import test_pms_checkin_partner +# from . import test_pms_reservation +# from . import test_pms_pricelist +# from . import test_pms_pricelist_priority +# from . import test_pms_checkin_partner from . import test_pms_sale_channel -from . import test_pms_folio -from . import test_pms_availability_plan_rules -from . import test_pms_room_type -from . import test_pms_room_type_class -from . import test_pms_board_service -from . import test_pms_wizard_massive_changes -from . import test_pms_wizard_folio -from . import test_pms_res_users -from . import test_pms_amenity -from . import test_pms_room -from . import test_pms_board_service_line -from . import test_pms_board_service_room_type -from . import test_pms_board_service_room_type_line -from . import test_pms_folio_invoice -from . import test_pms_folio_sale_line -from . import test_pms_wizard_split_join_swap_reservation + +# from . import test_pms_folio +# from . import test_pms_availability_plan_rules +# from . import test_pms_room_type +# from . import test_pms_room_type_class +# from . import test_pms_board_service +# from . import test_pms_wizard_massive_changes +# from . import test_pms_wizard_folio +# from . import test_pms_res_users +# from . import test_pms_amenity +# from . import test_pms_room +# from . import test_pms_board_service_line +# from . import test_pms_board_service_room_type +# from . import test_pms_board_service_room_type_line +# from . import test_pms_folio_invoice +# from . import test_pms_folio_sale_line +# from . import test_pms_wizard_split_join_swap_reservation diff --git a/pms/tests/test_pms_room.py b/pms/tests/test_pms_room.py index 90d4768a9..81c649ba5 100644 --- a/pms/tests/test_pms_room.py +++ b/pms/tests/test_pms_room.py @@ -27,7 +27,12 @@ class TestPmsRoom(TestPms): } ) - def test_check_property_ubication(self): + def test_inconsistency_room_ubication_property(self): + """ + Room property and its ubication properties are inconsistent. + A Room with property that is not included in available properties + for its ubication cannot be created. + """ # ARRANGE ubication1 = self.env["pms.ubication"].create( { @@ -37,8 +42,12 @@ class TestPmsRoom(TestPms): ], } ) - # ACT & ARRANGE - with self.assertRaises(UserError, msg="Room has been created and it should't"): + # ACT & ASSERT + with self.assertRaises( + UserError, + msg="The room should not be created if its property is not included " + "in the available properties for its ubication.", + ): self.env["pms.room"].create( { "name": "Room 101", @@ -48,7 +57,44 @@ class TestPmsRoom(TestPms): } ) - def test_check_property_room_type(self): + def test_consistency_room_ubication_property(self): + """ + Room property and its ubication properties are consistent. + A Room with property included in available properties + for its ubication can be created. + """ + # ARRANGE + ubication1 = self.env["pms.ubication"].create( + { + "name": "UbicationTest", + "pms_property_ids": [ + (4, self.pms_property1.id), + ], + } + ) + # ACT + new_room1 = self.env["pms.room"].create( + { + "name": "Room 101", + "pms_property_id": self.pms_property1.id, + "room_type_id": self.room_type1.id, + "ubication_id": ubication1.id, + } + ) + # ASSERT + self.assertIn( + new_room1.pms_property_id, + ubication1.pms_property_ids, + "The room should be created if its property belongs to the availabe" + "properties for its ubication.", + ) + + def test_inconsistency_room_type_property(self): + """ + Room property and its room type properties are inconsistent. + A Room with property that is not included in available properties + for its room type cannot be created. + """ # ARRANGE self.pms_property3 = self.env["pms.property"].create( { @@ -58,7 +104,11 @@ class TestPmsRoom(TestPms): } ) # ACT & ARRANGE - with self.assertRaises(UserError, msg="Room has been created and it should't"): + with self.assertRaises( + UserError, + msg="The room should not be created if its property is not included " + "in the available properties for its room type.", + ): self.env["pms.room"].create( { "name": "Room 101", @@ -67,9 +117,32 @@ class TestPmsRoom(TestPms): } ) - @mute_logger("odoo.sql_db") - def test_name_property_unique_01(self): + def test_consistency_room_type_property(self): """ + Room property and its room type properties are inconsistent. + A Room with property included in available properties + for its room type can be created. + """ + # ARRANGE & ACT + room1 = self.env["pms.room"].create( + { + "name": "Room 101", + "pms_property_id": self.pms_property1.id, + "room_type_id": self.room_type1.id, + } + ) + # ASSERT + self.assertIn( + room1.pms_property_id, + self.room_type1.pms_property_ids, + "The room should be created if its property is included " + "in the available properties for its room type.", + ) + + @mute_logger("odoo.sql_db") + def test_room_name_uniqueness_by_property(self): + """ + Check that there are no two rooms with the same name in the same property PRE: - room1 'Room 101' exists - room1 has pms_property1 ACT: - create a new room2 @@ -89,7 +162,9 @@ class TestPmsRoom(TestPms): ) # ACT & ASSERT with self.assertRaises( - IntegrityError, msg="Room has been created and it shouldn't" + IntegrityError, + msg="The room should not be created if its name is equal " + "to another room that belongs to the same property.", ): self.env["pms.room"].create( { @@ -99,8 +174,9 @@ class TestPmsRoom(TestPms): } ) - def test_name_property_unique_02(self): + def test_room_name_duplicated_different_property(self): """ + Check that two rooms with the same name can exist in multiple properties PRE: - room1 'Room 101' exists - room1 has pms_property1 ACT: - create a new room2 @@ -126,4 +202,7 @@ class TestPmsRoom(TestPms): } ) except IntegrityError: - self.fail("Duplicated Room found but it shouldn't") + self.fail( + "The room should be created even if its name is equal " + "to another room, but that room not belongs to the same property." + ) diff --git a/pms/tests/test_pms_sale_channel.py b/pms/tests/test_pms_sale_channel.py index 3c1bc1eed..70702b53a 100644 --- a/pms/tests/test_pms_sale_channel.py +++ b/pms/tests/test_pms_sale_channel.py @@ -1,23 +1,26 @@ import datetime -from freezegun import freeze_time - from odoo.exceptions import ValidationError from .common import TestPms -@freeze_time("2010-01-01") class TestPmsSaleChannel(TestPms): - def test_not_agency_as_agency(self): + def test_reservation_with_invalid_agency(self): + """ + Reservation with an invalid agency cannot be created. + Create a partner that is not an agency and create + a reservation with that partner as an agency. + """ # ARRANGE PmsReservation = self.env["pms.reservation"] not_agency = self.env["res.partner"].create( {"name": "partner1", "is_agency": False} ) - # ACT & ASSERT - with self.assertRaises(ValidationError), self.cr.savepoint(): + with self.assertRaises( + ValidationError, msg="Reservation with an invalid agency cannot be created." + ): PmsReservation.create( { "checkin": datetime.datetime.now(), @@ -27,30 +30,12 @@ class TestPmsSaleChannel(TestPms): } ) - def test_channel_type_id_only_directs(self): - # ARRANGE - PmsReservation = self.env["pms.reservation"] - PmsSaleChannel = self.env["pms.sale.channel"] - # ACT - sale_channel1 = PmsSaleChannel.create({"channel_type": "direct"}) - partner1 = self.env["res.partner"].create({"name": "partner1"}) - reservation1 = PmsReservation.create( - { - "checkin": datetime.datetime.now(), - "checkout": datetime.datetime.now() + datetime.timedelta(days=3), - "channel_type_id": sale_channel1.id, - "partner_id": partner1.id, - "pms_property_id": self.pms_property1.id, - } - ) - # ASSERT - self.assertEqual( - reservation1.channel_type_id.channel_type, - "direct", - "Sale channel is not direct", - ) - - def test_agency_id_is_agency(self): + def test_reservation_with_valid_agency(self): + """ + Reservation with a valid agency must be created. + Create a partner that is an agency and create + a reservation with that partner as an agency can be created. + """ # ARRANGE PmsReservation = self.env["pms.reservation"] PmsSaleChannel = self.env["pms.sale.channel"] @@ -73,18 +58,83 @@ class TestPmsSaleChannel(TestPms): "pms_property_id": self.pms_property1.id, } ) + # ASSERT self.assertEqual( reservation1.agency_id.is_agency, True, - "Agency_id doesn't correspond to an agency", + "Reservation with a valid agency should be created.", ) - def test_sale_channel_id_only_indirect(self): + def test_reservation_with_partner_direct(self): + """ + Reservation create with partner (no agency) and sale channel + 'direct' must be set reservation sale channel to 'direct'. + A reservation with partner and sale channel as 'direct' + should be created. + """ # ARRANGE + PmsReservation = self.env["pms.reservation"] PmsSaleChannel = self.env["pms.sale.channel"] # ACT + sale_channel1 = PmsSaleChannel.create({"channel_type": "direct"}) + partner1 = self.env["res.partner"].create({"name": "partner1"}) + reservation1 = PmsReservation.create( + { + "checkin": datetime.datetime.now(), + "checkout": datetime.datetime.now() + datetime.timedelta(days=3), + "channel_type_id": sale_channel1.id, + "partner_id": partner1.id, + "pms_property_id": self.pms_property1.id, + } + ) + # ASSERT + self.assertEqual( + reservation1.channel_type_id.channel_type, + "direct", + "A reservation with partner and sale channel as 'direct'" + "should be created a 'direct' reservation.", + ) + + def test_reservation_with_partner_indirect(self): + """ + Reservation create with partner (no agency) and sale channel + 'indirect' must be set reservation sale channel to 'direct'. + A reservation with partner and sale channel as 'direct' + should be created. + """ + # ARRANGE + PmsReservation = self.env["pms.reservation"] + PmsSaleChannel = self.env["pms.sale.channel"] + # ACT + sale_channel1 = PmsSaleChannel.create({"channel_type": "indirect"}) + partner1 = self.env["res.partner"].create({"name": "partner1"}) + reservation1 = PmsReservation.create( + { + "checkin": datetime.datetime.now(), + "checkout": datetime.datetime.now() + datetime.timedelta(days=3), + "channel_type_id": sale_channel1.id, + "partner_id": partner1.id, + "pms_property_id": self.pms_property1.id, + } + ) + # ASSERT + self.assertEqual( + reservation1.channel_type_id.channel_type, + "indirect", + "A reservation with partner and sale channel as 'direct'" + "should be created a 'indirect' reservation.", + ) + + def test_create_agency_with_sale_channel_indirect(self): + """ + Agency should be created as partner setted as 'agency' + and its sale channel as 'indirect'. + """ + # ARRANGE + PmsSaleChannel = self.env["pms.sale.channel"] saleChannel1 = PmsSaleChannel.create({"channel_type": "indirect"}) + # ACT agency1 = self.env["res.partner"].create( {"name": "example", "is_agency": True, "sale_channel_id": saleChannel1.id} ) @@ -92,12 +142,37 @@ class TestPmsSaleChannel(TestPms): self.assertEqual( agency1.sale_channel_id.channel_type, "indirect", - "An agency should be a indirect channel", + "An agency should be an indirect channel.", ) - def test_agency_without_sale_channel_id(self): + def test_create_agency_with_sale_channel_direct(self): + """ + Agency shouldnt be created as partner setted as 'agency' + and its sale channel as 'direct'. + """ + # ARRANGE + PmsSaleChannel = self.env["pms.sale.channel"] + saleChannel1 = PmsSaleChannel.create({"channel_type": "direct"}) + # ACT & ASSERT + with self.assertRaises( + ValidationError, msg="An agency should be an indirect channel." + ): + self.env["res.partner"].create( + { + "name": "example", + "is_agency": True, + "sale_channel_id": saleChannel1.id, + } + ) + + def test_create_agency_without_sale_channel(self): + """ + Agency creation should fails if there's no sale channel. + """ # ARRANGE & ACT & ASSERT - with self.assertRaises(ValidationError), self.cr.savepoint(): + with self.assertRaises( + ValidationError, msg="Agency should not be created without sale channel." + ): self.env["res.partner"].create( {"name": "example", "is_agency": True, "sale_channel_id": None} ) From 9d2579021c74462aae52b0adac3a930718230078 Mon Sep 17 00:00:00 2001 From: miguelpadin Date: Thu, 10 Jun 2021 20:29:52 +0200 Subject: [PATCH 2/9] [REF] pms: refactor tests wizard_massive-changes --- pms/tests/__init__.py | 5 +- pms/tests/test_pms_wizard_massive_changes.py | 952 +++++++++++-------- 2 files changed, 539 insertions(+), 418 deletions(-) diff --git a/pms/tests/__init__.py b/pms/tests/__init__.py index 8ac1c4a41..3dde71f10 100644 --- a/pms/tests/__init__.py +++ b/pms/tests/__init__.py @@ -23,14 +23,13 @@ # from . import test_pms_pricelist # from . import test_pms_pricelist_priority # from . import test_pms_checkin_partner -from . import test_pms_sale_channel - +# from . import test_pms_sale_channel # from . import test_pms_folio # from . import test_pms_availability_plan_rules # from . import test_pms_room_type # from . import test_pms_room_type_class # from . import test_pms_board_service -# from . import test_pms_wizard_massive_changes +from . import test_pms_wizard_massive_changes # from . import test_pms_wizard_folio # from . import test_pms_res_users # from . import test_pms_amenity diff --git a/pms/tests/test_pms_wizard_massive_changes.py b/pms/tests/test_pms_wizard_massive_changes.py index 96aeb6302..b669a6e85 100644 --- a/pms/tests/test_pms_wizard_massive_changes.py +++ b/pms/tests/test_pms_wizard_massive_changes.py @@ -3,180 +3,67 @@ import datetime from freezegun import freeze_time from odoo import fields -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", - } - ) - # pms.availability.plan - self.test_availability_plan = self.env["pms.availability.plan"].create( +class TestPmsWizardMassiveChanges(TestPms): + + def setUp(self): + super().setUp() + self.availability_plan1 = self.env["pms.availability.plan"].create( { "name": "Availability plan for TEST", - "pms_pricelist_ids": [(6, 0, [self.test_pricelist.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], - "name": "Single Test", - "default_code": "SNG_Test", - "class_id": self.test_room_type_class.id, - } - ) - self.test_room_type_double = self.env["pms.room.type"].create( - { - "pms_property_ids": [self.test_property.id], - "name": "Double Test", - "default_code": "DBL_Test", - "class_id": self.test_room_type_class.id, - } - ) - - # pms.board.service - self.test_board_service_only_breakfast = self.env["pms.board.service"].create( - { - "name": "Test Only Breakfast", - "default_code": "CB1", - } - ) - self.test_board_service_half_board = self.env["pms.board.service"].create( - { - "name": "Test Half Board", - "default_code": "CB2", - } - ) - # product.product 1 - self.test_service_breakfast = self.env["product.product"].create( - {"name": "Test Breakfast"} - ) - self.test_service_dinner = self.env["product.product"].create( - {"name": "Test Dinner"} - ) - self.test_service_spa = self.env["product.product"].create({"name": "Test Spa"}) - # pms.board.service.room.type - self.test_board_service_single = self.env["pms.board.service.room.type"].create( - { - "pms_room_type_id": self.test_room_type_single.id, - "pms_board_service_id": self.test_board_service_only_breakfast.id, - } - ) - self.test_board_service_double = self.env["pms.board.service.room.type"].create( - { - "pms_room_type_id": self.test_room_type_double.id, - "pms_board_service_id": self.test_board_service_half_board.id, - } - ) - # pms.board.service.line - self.board_service_line_single_1 = self.env["pms.board.service.line"].create( - { - "product_id": self.test_service_breakfast.id, - "pms_board_service_id": self.test_board_service_only_breakfast.id, - } - ) - self.board_service_line_double_1 = self.env["pms.board.service.line"].create( - { - "product_id": self.test_service_breakfast.id, - "pms_board_service_id": self.test_board_service_half_board.id, - } - ) - self.board_service_line_double_2 = self.board_service_line = self.env[ - "pms.board.service.line" - ].create( - { - "product_id": self.test_service_dinner.id, - "pms_board_service_id": self.test_board_service_half_board.id, + "pms_pricelist_ids": [(6, 0, [self.pricelist1.id])], } ) # MASSIVE CHANGE WIZARD TESTS ON AVAILABILITY RULES - @freeze_time("1980-12-01") def test_num_availability_rules_create(self): - - # TEST CASE - # rules should be created consistently for 1,2,3,4 days - + """ + Rules should be created consistently for 1,2,3,4 days + subtests: {1 day -> 1 rule, n days -> n rules} + """ # ARRANGE - self.create_common_scenario() - + room_type_double = self.env["pms.room.type"].create( + { + "pms_property_ids": [self.pms_property1.id], + "name": "Double Test", + "default_code": "DBL_Test", + "class_id": self.room_type_class1.id, + } + ) for days in [0, 1, 2, 3]: with self.subTest(k=days): num_exp_rules_to_create = days + 1 - + # ACT self.env["pms.massive.changes.wizard"].create( { "massive_changes_on": "availability_plan", "availability_plan_ids": [ - (6, 0, [self.test_availability_plan.id]) + (6, 0, [self.availability_plan1.id]) ], "start_date": fields.date.today(), "end_date": fields.date.today() + datetime.timedelta(days=days), - "room_type_ids": [(6, 0, [self.test_room_type_double.id])], - "pms_property_ids": [self.test_property.id], + "room_type_ids": [(6, 0, [room_type_double.id])], + "pms_property_ids": [self.pms_property1.id], } ).apply_massive_changes() - + # ASSERT self.assertEqual( - len(self.test_availability_plan.rule_ids), + len(self.availability_plan1.rule_ids), num_exp_rules_to_create, - "the number of rules created by should contains all the " + "the number of rules created should contains all the " "days between start and finish (both included)", ) - @freeze_time("1980-12-01") def test_num_availability_rules_create_no_room_type(self): - # TEST CASE - # (days x room_types) rules should be created - + """ + Rules should be created consistently for all rooms & days. + (days * num rooom types) + Create rules for 4 days and for all room types. + """ # ARRANGE - self.create_common_scenario() date_from = fields.date.today() date_to = fields.date.today() + datetime.timedelta(days=3) @@ -184,7 +71,7 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): [ "|", ("pms_property_ids", "=", False), - ("pms_property_ids", "in", self.test_property.id), + ("pms_property_ids", "in", self.pms_property1.id), ] ) num_exp_rules_to_create = ((date_to - date_from).days + 1) * num_room_types @@ -193,37 +80,42 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): self.env["pms.massive.changes.wizard"].create( { "massive_changes_on": "availability_plan", - "availability_plan_ids": [(6, 0, [self.test_availability_plan.id])], + "availability_plan_ids": [(6, 0, [self.availability_plan1.id])], "start_date": date_from, "end_date": date_to, - "pms_property_ids": [self.test_property.id], + "pms_property_ids": [self.pms_property1.id], } ).apply_massive_changes() # ASSERT self.assertEqual( - len(self.test_availability_plan.rule_ids), + len(self.availability_plan1.rule_ids), num_exp_rules_to_create, "the number of rules created by the wizard should consider all " "room types", ) - @freeze_time("1980-12-01") def test_value_availability_rules_create(self): - # TEST CASE - # Rule values should be set correctly - + """ + The value of the rules created is setted properly. + """ # ARRANGE - self.create_common_scenario() + room_type_double = self.env["pms.room.type"].create( + { + "pms_property_ids": [self.pms_property1.id], + "name": "Double Test", + "default_code": "DBL_Test", + "class_id": self.room_type_class1.id, + } + ) date_from = fields.date.today() date_to = fields.date.today() - vals = { "massive_changes_on": "availability_plan", - "availability_plan_ids": [(6, 0, [self.test_availability_plan.id])], + "availability_plan_ids": [(6, 0, [self.availability_plan1.id])], "start_date": date_from, "end_date": date_to, - "room_type_ids": [(6, 0, [self.test_room_type_double.id])], + "room_type_ids": [(6, 0, [room_type_double.id])], "quota": 50, "max_avail": 5, "min_stay": 10, @@ -233,12 +125,10 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): "closed": True, "closed_arrival": True, "closed_departure": True, - "pms_property_ids": [self.test_property.id], + "pms_property_ids": [self.pms_property1.id], } - # ACT self.env["pms.massive.changes.wizard"].create(vals).apply_massive_changes() - # ASSERT del vals["massive_changes_on"] del vals["availability_plan_ids"] @@ -249,18 +139,25 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): for key in vals: with self.subTest(k=key): self.assertEqual( - self.test_availability_plan.rule_ids[0][key], + self.availability_plan1.rule_ids[0][key], vals[key], "The value of " + key + " is not correctly established", ) @freeze_time("1980-12-01") def test_day_of_week_availability_rules_create(self): - # TEST CASE - # rules for each day of week should be created - + """ + Rules for each day of week should be created. + """ # ARRANGE - self.create_common_scenario() + room_type_double = self.env["pms.room.type"].create( + { + "pms_property_ids": [self.pms_property1.id], + "name": "Double Test", + "default_code": "DBL_Test", + "class_id": self.room_type_class1.id, + } + ) test_case_week_days = [ [1, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0], @@ -270,18 +167,17 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): [0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 1], ] - date_from = fields.date.today() date_to = fields.date.today() + datetime.timedelta(days=6) wizard = self.env["pms.massive.changes.wizard"].create( { "massive_changes_on": "availability_plan", - "availability_plan_ids": [(6, 0, [self.test_availability_plan.id])], - "room_type_ids": [(6, 0, [self.test_room_type_double.id])], + "availability_plan_ids": [(6, 0, [self.availability_plan1.id])], + "room_type_ids": [(6, 0, [room_type_double.id])], "start_date": date_from, "end_date": date_to, - "pms_property_ids": [self.test_property.id], + "pms_property_ids": [self.pms_property1.id], } ) @@ -301,76 +197,88 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): ) # ACT wizard.apply_massive_changes() - availability_rules = self.test_availability_plan.rule_ids.sorted( + availability_rules = self.availability_plan1.rule_ids.sorted( key=lambda s: s.date ) # ASSERT self.assertTrue( availability_rules[index].date.timetuple()[6] == index and test_case[index], - "Rule not created on correct day of week", + "Rule not created on correct day of week.", ) - @freeze_time("1980-12-01") def test_no_overwrite_values_not_setted(self): - # TEST CASE - # A rule value shouldnt overwrite with the default values - # another rules for the same day and room type - + """ + A rule value shouldnt overwrite with the default values + another rules for the same day and room type. + Create a rule with quota and another rule for the same date with max + avail. Should not overwrite quota. + """ # ARRANGE - self.create_common_scenario() + room_type_double = self.env["pms.room.type"].create( + { + "pms_property_ids": [self.pms_property1.id], + "name": "Double Test", + "default_code": "DBL_Test", + "class_id": self.room_type_class1.id, + } + ) date = fields.date.today() initial_quota = 20 self.env["pms.availability.plan.rule"].create( { - "availability_plan_id": self.test_availability_plan.id, - "room_type_id": self.test_room_type_double.id, + "availability_plan_id": self.availability_plan1.id, + "room_type_id": room_type_double.id, "date": date, "quota": initial_quota, - "pms_property_id": self.test_property.id, + "pms_property_id": self.pms_property1.id, } ) vals_wizard = { "massive_changes_on": "availability_plan", - "availability_plan_ids": [(6, 0, [self.test_availability_plan.id])], + "availability_plan_ids": [(6, 0, [self.availability_plan1.id])], "start_date": date, "end_date": date, - "room_type_ids": [(6, 0, [self.test_room_type_double.id])], + "room_type_ids": [(6, 0, [room_type_double.id])], "apply_max_avail": True, "max_avail": 2, - "pms_property_ids": [self.test_property.id], + "pms_property_ids": [self.pms_property1.id], } - # ACT self.env["pms.massive.changes.wizard"].create( vals_wizard ).apply_massive_changes() - # ASSERT self.assertEqual( - self.test_availability_plan.rule_ids[0].quota, + self.availability_plan1.rule_ids[0].quota, initial_quota, "A rule value shouldnt overwrite with the default values " "another rules for the same day and room type", ) - @freeze_time("2025-12-01") - def test_several_availability_plan(self): - # TEST CASE - # If several availability plans are set, the wizard should create as - # many rules as availability plans. - + def test_several_availability_plans(self): + """ + If several availability plans are set, the wizard should create as + many rules as availability plans. + """ # ARRANGE - self.create_common_scenario() - self.test_availability_plan_2 = self.env["pms.availability.plan"].create( + room_type_double = self.env["pms.room.type"].create( + { + "pms_property_ids": [self.pms_property1.id], + "name": "Double Test", + "default_code": "DBL_Test", + "class_id": self.room_type_class1.id, + } + ) + availability_plan2 = self.env["pms.availability.plan"].create( { "name": "Second availability plan for TEST", - "pms_pricelist_ids": [self.test_pricelist.id], + "pms_pricelist_ids": [self.pricelist1.id], } ) expected_av_plans = [ - self.test_availability_plan.id, - self.test_availability_plan_2.id, + self.availability_plan1.id, + availability_plan2.id, ] date_from = fields.date.today() date_to = fields.date.today() @@ -381,13 +289,13 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): 6, 0, [ - self.test_availability_plan.id, - self.test_availability_plan_2.id, + self.availability_plan1.id, + availability_plan2.id, ], ) ], - "room_type_ids": [(6, 0, [self.test_room_type_double.id])], - "pms_property_ids": [self.test_property.id], + "room_type_ids": [(6, 0, [room_type_double.id])], + "pms_property_ids": [self.pms_property1.id], "start_date": date_from, "end_date": date_to, } @@ -400,44 +308,52 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): set(expected_av_plans), set( self.env["pms.availability.plan.rule"] - .search([("room_type_id", "=", self.test_room_type_double.id)]) + .search([("room_type_id", "=", room_type_double.id)]) .mapped("availability_plan_id") .ids ), "The wizard should create as many rules as availability plans given.", ) - @freeze_time("2025-02-01") def test_several_room_types_availability_plan(self): - # TEST CASE - # If several room types are set, the wizard should create as - # many rules as room types. - + """ + If several room types are set, the wizard should create as + many rules as room types. + """ # ARRANGE - self.create_common_scenario() - self.test_availability_plan_2 = self.env["pms.availability.plan"].create( + room_type_double = self.env["pms.room.type"].create( { - "name": "Second availability plan for TEST", - "pms_pricelist_ids": [self.test_pricelist.id], + "pms_property_ids": [self.pms_property1.id], + "name": "Double Test", + "default_code": "DBL_Test", + "class_id": self.room_type_class1.id, + } + ) + room_type_single = self.env["pms.room.type"].create( + { + "pms_property_ids": [self.pms_property1.id], + "name": "Single Test", + "default_code": "SNG_Test", + "class_id": self.room_type_class1.id, } ) expected_room_types = [ - self.test_room_type_double.id, - self.test_room_type_single.id, + room_type_double.id, + room_type_single.id, ] date_from = fields.date.today() date_to = fields.date.today() vals_wizard = { "massive_changes_on": "availability_plan", - "availability_plan_ids": [(6, 0, [self.test_availability_plan.id])], + "availability_plan_ids": [(6, 0, [self.availability_plan1.id])], "room_type_ids": [ ( 6, 0, - [self.test_room_type_double.id, self.test_room_type_single.id], + [room_type_double.id, room_type_single.id], ) ], - "pms_property_ids": [self.test_property.id], + "pms_property_ids": [self.pms_property1.id], "start_date": date_from, "end_date": date_to, } @@ -450,42 +366,48 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): set(expected_room_types), set( self.env["pms.availability.plan.rule"] - .search([("availability_plan_id", "=", self.test_availability_plan.id)]) + .search([("availability_plan_id", "=", self.availability_plan1.id)]) .mapped("room_type_id") .ids ), "The wizard should create as many rules as room types given.", ) - @freeze_time("1980-12-01") def test_several_properties_availability_plan(self): - # TEST CASE - # If several properties are set, the wizard should create as - # many rules as properties. - + """ + If several properties are set, the wizard should create as + many rules as properties. + """ # ARRANGE - self.create_common_scenario() - self.test_property2 = self.env["pms.property"].create( + pms_property2 = self.env["pms.property"].create( { "name": "MY 2nd PMS TEST", "company_id": self.env.ref("base.main_company").id, } ) - self.test_room_type_double.pms_property_ids = [ - (6, 0, [self.test_property.id, self.test_property2.id]) + room_type_double = self.env["pms.room.type"].create( + { + "pms_property_ids": [self.pms_property1.id], + "name": "Double Test", + "default_code": "DBL_Test", + "class_id": self.room_type_class1.id, + } + ) + room_type_double.pms_property_ids = [ + (6, 0, [self.pms_property1.id, pms_property2.id]) ] expected_properties = [ - self.test_property.id, - self.test_property2.id, + self.pms_property1.id, + pms_property2.id, ] date_from = fields.date.today() date_to = fields.date.today() vals_wizard = { "massive_changes_on": "availability_plan", - "availability_plan_ids": [(6, 0, [self.test_availability_plan.id])], - "room_type_ids": [(6, 0, [self.test_room_type_double.id])], + "availability_plan_ids": [(6, 0, [self.availability_plan1.id])], + "room_type_ids": [(6, 0, [room_type_double.id])], "pms_property_ids": [ - (6, 0, [self.test_property.id, self.test_property2.id]) + (6, 0, [self.pms_property1.id, pms_property2.id]) ], "start_date": date_from, "end_date": date_to, @@ -499,7 +421,7 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): set(expected_properties), set( self.env["pms.availability.plan.rule"] - .search([("availability_plan_id", "=", self.test_availability_plan.id)]) + .search([("availability_plan_id", "=", self.availability_plan1.id)]) .mapped("pms_property_id") .ids ), @@ -508,36 +430,41 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): # MASSIVE CHANGE WIZARD TESTS ON PRICELIST ITEMS - @freeze_time("1980-12-01") def test_pricelist_items_create(self): - # TEST CASE - # items should be created consistently for 1,2,3,4 days - + """ + Pricelist items should be created consistently for 1,2,3,4 days + subtests: {1 day -> 1 pricelist item, n days -> n pricelist items} + """ # ARRANGE - self.create_common_scenario() + room_type_double = self.env["pms.room.type"].create( + { + "pms_property_ids": [self.pms_property1.id], + "name": "Double Test", + "default_code": "DBL_Test", + "class_id": self.room_type_class1.id, + } + ) for days in [0, 1, 2, 3]: with self.subTest(k=days): - # ARRANGE num_exp_items_to_create = days + 1 - self.test_pricelist.item_ids = False - + self.pricelist1.item_ids = False # ACT self.env["pms.massive.changes.wizard"].create( { "massive_changes_on": "pricelist", - "pricelist_ids": [(6, 0, [self.test_pricelist.id])], + "pricelist_ids": [(6, 0, [self.pricelist1.id])], "start_date": fields.date.today(), "end_date": fields.date.today() + datetime.timedelta(days=days), - "room_type_ids": [(6, 0, [self.test_room_type_double.id])], - "pms_property_ids": [self.test_property.id], + "room_type_ids": [(6, 0, [room_type_double.id])], + "pms_property_ids": [self.pms_property1.id], } ).apply_massive_changes() # ASSERT self.assertEqual( len( - self.test_pricelist.item_ids - if self.test_pricelist.item_ids + self.pricelist1.item_ids + if self.pricelist1.item_ids else [] ), num_exp_items_to_create, @@ -545,101 +472,108 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): "days between start and finish (both included)", ) - @freeze_time("1980-12-01") def test_num_pricelist_items_create_no_room_type(self): - # TEST CASE - # (days x room_types) items should be created - + """ + Pricelist items should be created consistently for all rooms & days. + (days * num rooom types) + Create pricelist item for 4 days and for all room types. + """ # ARRANGE - self.create_common_scenario() date_from = fields.date.today() date_to = fields.date.today() + datetime.timedelta(days=3) num_room_types = self.env["pms.room.type"].search_count( [ "|", ("pms_property_ids", "=", False), - ("pms_property_ids", "in", self.test_property.id), + ("pms_property_ids", "in", self.pms_property1.id), ] ) num_exp_items_to_create = ((date_to - date_from).days + 1) * num_room_types - # ACT self.env["pms.massive.changes.wizard"].create( { "massive_changes_on": "pricelist", - "pricelist_ids": [(6, 0, [self.test_pricelist.id])], + "pricelist_ids": [(6, 0, [self.pricelist1.id])], "start_date": date_from, "end_date": date_to, - "pms_property_ids": [self.test_property.id], + "pms_property_ids": [self.pms_property1.id], } ).apply_massive_changes() - # ASSERT self.assertEqual( - len(self.test_pricelist.item_ids), + len(self.pricelist1.item_ids), num_exp_items_to_create, "the number of rules created by the wizard should consider all " "room types when one is not applied", ) - @freeze_time("1980-12-01") def test_value_pricelist_items_create(self): - # TEST CASE - # Item values should be set correctly - + """ + The value of the rules created is setted properly. + """ # ARRANGE - self.create_common_scenario() + room_type_double = self.env["pms.room.type"].create( + { + "pms_property_ids": [self.pms_property1.id], + "name": "Double Test", + "default_code": "DBL_Test", + "class_id": self.room_type_class1.id, + } + ) date_from = fields.date.today() date_to = fields.date.today() - price = 20 min_quantity = 3 - vals = { - "pricelist_id": self.test_pricelist, + "pricelist_id": self.pricelist1, "date_start": date_from, "date_end": date_to, "compute_price": "fixed", "applied_on": "0_product_variant", - "product_id": self.test_room_type_double.product_id, + "product_id": room_type_double.product_id, "fixed_price": price, "min_quantity": min_quantity, } - # ACT self.env["pms.massive.changes.wizard"].create( { "massive_changes_on": "pricelist", - "pricelist_ids": [(6, 0, [self.test_pricelist.id])], + "pricelist_ids": [(6, 0, [self.pricelist1.id])], "start_date": date_from, "end_date": date_to, - "room_type_ids": [(6, 0, [self.test_room_type_double.id])], + "room_type_ids": [(6, 0, [room_type_double.id])], "price": price, "min_quantity": min_quantity, - "pms_property_ids": [self.test_property.id], + "pms_property_ids": [self.pms_property1.id], } ).apply_massive_changes() vals["date_start_consumption"] = date_from vals["date_end_consumption"] = date_to - del vals["date_start"] del vals["date_end"] - # ASSERT for key in vals: with self.subTest(k=key): self.assertEqual( - self.test_pricelist.item_ids[0][key], + self.pricelist1.item_ids[0][key], vals[key], "The value of " + key + " is not correctly established", ) @freeze_time("1980-12-01") def test_day_of_week_pricelist_items_create(self): - # TEST CASE - # items for each day of week should be created + """ + Pricelist items for each day of week should be created. + """ # ARRANGE - self.create_common_scenario() + room_type_double = self.env["pms.room.type"].create( + { + "pms_property_ids": [self.pms_property1.id], + "name": "Double Test", + "default_code": "DBL_Test", + "class_id": self.room_type_class1.id, + } + ) test_case_week_days = [ [1, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0], @@ -654,11 +588,11 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): wizard = self.env["pms.massive.changes.wizard"].create( { "massive_changes_on": "pricelist", - "pricelist_ids": [(6, 0, [self.test_pricelist.id])], - "room_type_ids": [(6, 0, [self.test_room_type_double.id])], + "pricelist_ids": [(6, 0, [self.pricelist1.id])], + "room_type_ids": [(6, 0, [room_type_double.id])], "start_date": date_from, "end_date": date_to, - "pms_property_ids": [self.test_property.id], + "pms_property_ids": [self.pms_property1.id], } ) for index, test_case in enumerate(test_case_week_days): @@ -675,16 +609,12 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): "apply_on_sunday": test_case[6], } ) - self.test_pricelist.item_ids = False - + self.pricelist1.item_ids = False # ACT wizard.apply_massive_changes() - - # ASSERT - pricelist_items = self.test_pricelist.item_ids.sorted( + pricelist_items = self.pricelist1.item_ids.sorted( key=lambda s: s.date_start_consumption ) - # ASSERT self.assertTrue( pricelist_items[index].date_start_consumption.timetuple()[6] @@ -693,30 +623,35 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): "Rule not created on correct day of week", ) - @freeze_time("2025-01-01") def test_several_pricelists(self): - # TEST CASE - # If several pricelist are set, the wizard should create as - # many items as pricelists. - + """ + If several pricelist are set, the wizard should create as + many pricelist items as pricelists. + """ # ARRANGE - self.create_common_scenario() - self.test_pricelist_2 = self.env["product.pricelist"].create( + room_type_double = self.env["pms.room.type"].create( + { + "pms_property_ids": [self.pms_property1.id], + "name": "Double Test", + "default_code": "DBL_Test", + "class_id": self.room_type_class1.id, + } + ) + pricelist2 = self.env["product.pricelist"].create( { "name": "test pricelist 2", } ) - expected_pricelists = [self.test_pricelist.id, self.test_pricelist_2.id] - + expected_pricelists = [self.pricelist1.id, pricelist2.id] date_from = fields.date.today() date_to = fields.date.today() vals_wizard = { "massive_changes_on": "pricelist", "pricelist_ids": [ - (6, 0, [self.test_pricelist.id, self.test_pricelist_2.id]) + (6, 0, [self.pricelist1.id, pricelist2.id]) ], - "room_type_ids": [(6, 0, [self.test_room_type_double.id])], - "pms_property_ids": [self.test_property.id], + "room_type_ids": [(6, 0, [room_type_double.id])], + "pms_property_ids": [self.pms_property1.id], "start_date": date_from, "end_date": date_to, } @@ -729,38 +664,52 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): set(expected_pricelists), set( self.env["product.pricelist.item"] - .search([("product_id", "=", self.test_room_type_double.product_id.id)]) + .search([("product_id", "=", room_type_double.product_id.id)]) .mapped("pricelist_id") .ids ), "The wizard should create as many items as pricelists given.", ) - @freeze_time("2025-02-01") def test_several_room_types_pricelist(self): - # TEST CASE - # If several room types are set, the wizard should create as - # many items as room types. - + """ + If several room types are set, the wizard should create as + many pricelist items as room types. + """ # ARRANGE - self.create_common_scenario() + room_type_double = self.env["pms.room.type"].create( + { + "pms_property_ids": [self.pms_property1.id], + "name": "Double Test", + "default_code": "DBL_Test", + "class_id": self.room_type_class1.id, + } + ) + room_type_single = self.env["pms.room.type"].create( + { + "pms_property_ids": [self.pms_property1.id], + "name": "Single Test", + "default_code": "SNG_Test", + "class_id": self.room_type_class1.id, + } + ) date_from = fields.date.today() date_to = fields.date.today() expected_product_ids = [ - self.test_room_type_double.product_id.id, - self.test_room_type_single.product_id.id, + room_type_double.product_id.id, + room_type_single.product_id.id, ] vals_wizard = { "massive_changes_on": "pricelist", - "pricelist_ids": [(6, 0, [self.test_pricelist.id])], + "pricelist_ids": [(6, 0, [self.pricelist1.id])], "room_type_ids": [ ( 6, 0, - [self.test_room_type_double.id, self.test_room_type_single.id], + [room_type_double.id, room_type_single.id], ) ], - "pms_property_ids": [self.test_property.id], + "pms_property_ids": [self.pms_property1.id], "start_date": date_from, "end_date": date_to, } @@ -773,38 +722,65 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): set(expected_product_ids), set( self.env["product.pricelist.item"] - .search([("pricelist_id", "=", self.test_pricelist.id)]) + .search([("pricelist_id", "=", self.pricelist1.id)]) .mapped("product_id") .ids ), "The wizard should create as many items as room types given.", ) - @freeze_time("2025-02-01") def test_one_board_service_room_type_no_board_service(self): - # TEST CASE - # Call to wizard with one board service room type and no - # board service. - # The wizard must create as many pricelist items as there - # are services on the given board service. - + """ + Call to wizard with one board service room type and no + board service. + The wizard must create as many pricelist items as there + are services on the given board service. + """ # ARRANGE - self.create_common_scenario() + room_type_single = self.env["pms.room.type"].create( + { + "pms_property_ids": [self.pms_property1.id], + "name": "Double Test", + "default_code": "DBL_Test", + "class_id": self.room_type_class1.id, + } + ) + board_service_only_breakfast = self.env["pms.board.service"].create( + { + "name": "Test Only Breakfast", + "default_code": "CB1", + } + ) + service_breakfast = self.env["product.product"].create( + {"name": "Test Breakfast"} + ) + board_service_single = self.env["pms.board.service.room.type"].create( + { + "pms_room_type_id": room_type_single.id, + "pms_board_service_id": board_service_only_breakfast.id, + } + ) + board_service_line_single_1 = self.env["pms.board.service.line"].create( + { + "product_id": service_breakfast.id, + "pms_board_service_id": board_service_only_breakfast.id, + } + ) date_from = fields.date.today() date_to = fields.date.today() wizard_result = self.env["pms.massive.changes.wizard"].create( { "massive_changes_on": "pricelist", - "pricelist_ids": [(6, 0, [self.test_pricelist.id])], + "pricelist_ids": [(6, 0, [self.pricelist1.id])], "apply_pricelists_on": "board_services", "board_service_room_type_ids": [ ( 6, 0, - [self.test_board_service_single.id], + [board_service_single.id], ) ], - "pms_property_ids": [self.test_property.id], + "pms_property_ids": [self.pms_property1.id], "start_date": date_from, "end_date": date_to, "date_types": "consumption_dates", @@ -815,45 +791,72 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): items_created = self.env["product.pricelist.item"].search( [ - ("pricelist_id", "=", self.test_pricelist.id), - ("pms_property_ids", "=", self.test_property.id), - ("product_id", "=", self.board_service_line_single_1.product_id.id), + ("pricelist_id", "=", self.pricelist1.id), + ("pms_property_ids", "=", self.pms_property1.id), + ("product_id", "=", board_service_line_single_1.product_id.id), ] ) # ASSERT self.assertIn( - self.test_service_breakfast, + service_breakfast, items_created.mapped("product_id"), "The wizard must create as many pricelist items as there " "are services on the given board service.", ) - @freeze_time("2025-02-01") def test_one_board_service_room_type_with_board_service(self): - # TEST CASE - # Call to wizard with one board service room type and - # board service. - # The wizard must create one pricelist items with - # the board service given. - + """ + Call to wizard with one board service room type and + board service. + The wizard must create one pricelist items with + the board service given. + """ # ARRANGE - self.create_common_scenario() + room_type_single = self.env["pms.room.type"].create( + { + "pms_property_ids": [self.pms_property1.id], + "name": "Double Test", + "default_code": "DBL_Test", + "class_id": self.room_type_class1.id, + } + ) + board_service_only_breakfast = self.env["pms.board.service"].create( + { + "name": "Test Only Breakfast", + "default_code": "CB1", + } + ) + service_breakfast = self.env["product.product"].create( + {"name": "Test Breakfast"} + ) + board_service_single = self.env["pms.board.service.room.type"].create( + { + "pms_room_type_id": room_type_single.id, + "pms_board_service_id": board_service_only_breakfast.id, + } + ) + board_service_line_single_1 = self.env["pms.board.service.line"].create( + { + "product_id": service_breakfast.id, + "pms_board_service_id": board_service_only_breakfast.id, + } + ) date_from = fields.date.today() date_to = fields.date.today() wizard_result = self.env["pms.massive.changes.wizard"].create( { "massive_changes_on": "pricelist", - "pricelist_ids": [(6, 0, [self.test_pricelist.id])], + "pricelist_ids": [(6, 0, [self.pricelist1.id])], "apply_pricelists_on": "board_services", "board_service_room_type_ids": [ ( 6, 0, - [self.test_board_service_single.id], + [board_service_single.id], ) ], - "board_service": self.board_service_line_single_1.product_id.id, - "pms_property_ids": [self.test_property.id], + "board_service": board_service_line_single_1.product_id.id, + "pms_property_ids": [self.pms_property1.id], "start_date": date_from, "end_date": date_to, "date_types": "consumption_dates", @@ -864,55 +867,117 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): items_created = self.env["product.pricelist.item"].search( [ - ("pricelist_id", "=", self.test_pricelist.id), - ("pms_property_ids", "=", self.test_property.id), - ("product_id", "=", self.board_service_line_single_1.product_id.id), + ("pricelist_id", "=", self.pricelist1.id), + ("pms_property_ids", "=", self.pms_property1.id), + ("product_id", "=", board_service_line_single_1.product_id.id), ] ) # ASSERT self.assertIn( - self.test_service_breakfast, + service_breakfast, items_created.mapped("product_id"), "The wizard must create one pricelist items with " " the board service given.", ) - @freeze_time("2025-02-01") def test_several_board_service_room_type_no_board_service(self): - # TEST CASE - # Call to wizard with several board service room type and no - # board service. - # The wizard must create as many pricelist items as there - # are services on the given board services. - + """ + Call to wizard with several board service room type and no + board service. + The wizard must create as many pricelist items as there + are services on the given board services. + """ # ARRANGE - self.create_common_scenario() + room_type_single = self.env["pms.room.type"].create( + { + "pms_property_ids": [self.pms_property1.id], + "name": "Double Test", + "default_code": "SNG_Test", + "class_id": self.room_type_class1.id, + } + ) + room_type_double = self.env["pms.room.type"].create( + { + "pms_property_ids": [self.pms_property1.id], + "name": "Double Test", + "default_code": "DBL_Test", + "class_id": self.room_type_class1.id, + } + ) + board_service_only_breakfast = self.env["pms.board.service"].create( + { + "name": "Test Only Breakfast", + "default_code": "CB1", + } + ) + board_service_half_board = self.env["pms.board.service"].create( + { + "name": "Test Half Board", + "default_code": "CB2", + } + ) + service_breakfast = self.env["product.product"].create( + {"name": "Test Breakfast"} + ) + service_dinner = self.env["product.product"].create( + {"name": "Test Dinner"} + ) + board_service_single = self.env["pms.board.service.room.type"].create( + { + "pms_room_type_id": room_type_single.id, + "pms_board_service_id": board_service_only_breakfast.id, + } + ) + board_service_double = self.env["pms.board.service.room.type"].create( + { + "pms_room_type_id": room_type_double.id, + "pms_board_service_id": board_service_half_board.id, + } + ) + board_service_line_single_1 = self.env["pms.board.service.line"].create( + { + "product_id": service_breakfast.id, + "pms_board_service_id": board_service_only_breakfast.id, + } + ) + board_service_line_double_1 = self.env["pms.board.service.line"].create( + { + "product_id": service_breakfast.id, + "pms_board_service_id": board_service_half_board.id, + } + ) + board_service_line_double_2 = self.env["pms.board.service.line"].create( + { + "product_id": service_dinner.id, + "pms_board_service_id": board_service_half_board.id, + } + ) date_from = fields.date.today() date_to = fields.date.today() product_ids_expected = ( - self.test_board_service_double.pms_board_service_id.board_service_line_ids.mapped( + board_service_double.pms_board_service_id.board_service_line_ids.mapped( "product_id" ).ids - + self.test_board_service_single.pms_board_service_id.board_service_line_ids.mapped( + + board_service_single.pms_board_service_id.board_service_line_ids.mapped( "product_id" ).ids ) wizard_result = self.env["pms.massive.changes.wizard"].create( { "massive_changes_on": "pricelist", - "pricelist_ids": [(6, 0, [self.test_pricelist.id])], + "pricelist_ids": [(6, 0, [self.pricelist1.id])], "apply_pricelists_on": "board_services", "board_service_room_type_ids": [ ( 6, 0, [ - self.test_board_service_single.id, - self.test_board_service_double.id, + board_service_single.id, + board_service_double.id, ], ) ], - "pms_property_ids": [self.test_property.id], + "pms_property_ids": [self.pms_property1.id], "start_date": date_from, "end_date": date_to, "date_types": "consumption_dates", @@ -920,11 +985,10 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): ) # ACT wizard_result.apply_massive_changes() - items_created = self.env["product.pricelist.item"].search( [ - ("pricelist_id", "=", self.test_pricelist.id), - ("pms_property_ids", "=", self.test_property.id), + ("pricelist_id", "=", self.pricelist1.id), + ("pms_property_ids", "=", self.pms_property1.id), ("product_id", "in", product_ids_expected), ] ) @@ -936,20 +1000,83 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): " are services on the given board services.", ) - @freeze_time("2025-02-01") def test_several_board_service_room_type_with_board_service(self): - # TEST CASE - # Call to wizard with several board service room types and - # board service. - # The wizard must create as many pricelist items as there - # are services on the given board services. + """ + Call to wizard with several board service room types and + board service. + The wizard must create as many pricelist items as there + are services on the given board services. + """ # ARRANGE - self.create_common_scenario() + room_type_single = self.env["pms.room.type"].create( + { + "pms_property_ids": [self.pms_property1.id], + "name": "Double Test", + "default_code": "SNG_Test", + "class_id": self.room_type_class1.id, + } + ) + room_type_double = self.env["pms.room.type"].create( + { + "pms_property_ids": [self.pms_property1.id], + "name": "Double Test", + "default_code": "DBL_Test", + "class_id": self.room_type_class1.id, + } + ) + board_service_only_breakfast = self.env["pms.board.service"].create( + { + "name": "Test Only Breakfast", + "default_code": "CB1", + } + ) + board_service_half_board = self.env["pms.board.service"].create( + { + "name": "Test Half Board", + "default_code": "CB2", + } + ) + service_breakfast = self.env["product.product"].create( + {"name": "Test Breakfast"} + ) + service_dinner = self.env["product.product"].create( + {"name": "Test Dinner"} + ) + board_service_single = self.env["pms.board.service.room.type"].create( + { + "pms_room_type_id": room_type_single.id, + "pms_board_service_id": board_service_only_breakfast.id, + } + ) + board_service_double = self.env["pms.board.service.room.type"].create( + { + "pms_room_type_id": room_type_double.id, + "pms_board_service_id": board_service_half_board.id, + } + ) + board_service_line_single_1 = self.env["pms.board.service.line"].create( + { + "product_id": service_breakfast.id, + "pms_board_service_id": board_service_only_breakfast.id, + } + ) + board_service_line_double_1 = self.env["pms.board.service.line"].create( + { + "product_id": service_breakfast.id, + "pms_board_service_id": board_service_half_board.id, + } + ) + board_service_line_double_2 = self.env["pms.board.service.line"].create( + { + "product_id": service_dinner.id, + "pms_board_service_id": board_service_half_board.id, + } + ) date_from = fields.date.today() date_to = fields.date.today() - board_service_id_double = self.test_board_service_double.pms_board_service_id - board_service_id_single = self.test_board_service_single.pms_board_service_id + board_service_id_double = board_service_double.pms_board_service_id + board_service_id_single = board_service_single.pms_board_service_id product_ids_expected = list( set(board_service_id_double.board_service_line_ids.mapped("product_id").ids) & set( @@ -959,20 +1086,20 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): wizard_result = self.env["pms.massive.changes.wizard"].create( { "massive_changes_on": "pricelist", - "pricelist_ids": [(6, 0, [self.test_pricelist.id])], + "pricelist_ids": [(6, 0, [self.pricelist1.id])], "apply_pricelists_on": "board_services", "board_service_room_type_ids": [ ( 6, 0, [ - self.test_board_service_single.id, - self.test_board_service_double.id, + board_service_single.id, + board_service_double.id, ], ) ], - "board_service": self.test_service_breakfast.id, - "pms_property_ids": [self.test_property.id], + "board_service": service_breakfast.id, + "pms_property_ids": [self.pms_property1.id], "start_date": date_from, "end_date": date_to, "date_types": "consumption_dates", @@ -983,8 +1110,8 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): items_created = self.env["product.pricelist.item"].search( [ - ("pricelist_id", "=", self.test_pricelist.id), - ("pms_property_ids", "=", self.test_property.id), + ("pricelist_id", "=", self.pricelist1.id), + ("pms_property_ids", "=", self.pms_property1.id), ("product_id", "in", product_ids_expected), ] ) @@ -996,24 +1123,23 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): " are services on the given board services.", ) - @freeze_time("2025-02-01") def test_service(self): - # TEST CASE - # Call to wizard with one service (product_id) - # The wizard must create one pricelist items with - # the given service (product_id). - + """ + Call to wizard with one service (product_id) + The wizard must create one pricelist items with + the given service (product_id). + """ # ARRANGE - self.create_common_scenario() + service_spa = self.env["product.product"].create({"name": "Test Spa"}) date_from = fields.date.today() date_to = fields.date.today() wizard_result = self.env["pms.massive.changes.wizard"].create( { "massive_changes_on": "pricelist", - "pricelist_ids": [(6, 0, [self.test_pricelist.id])], + "pricelist_ids": [(6, 0, [self.pricelist1.id])], "apply_pricelists_on": "service", - "service": self.test_service_spa.id, - "pms_property_ids": [self.test_property.id], + "service": service_spa.id, + "pms_property_ids": [self.pms_property1.id], "start_date": date_from, "end_date": date_to, "date_types": "consumption_dates", @@ -1021,41 +1147,39 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): ) # ACT wizard_result.apply_massive_changes() - items_created = self.env["product.pricelist.item"].search( [ - ("pricelist_id", "=", self.test_pricelist.id), - ("pms_property_ids", "=", self.test_property.id), - ("product_id", "=", self.test_service_spa.id), + ("pricelist_id", "=", self.pricelist1.id), + ("pms_property_ids", "=", self.pms_property1.id), + ("product_id", "=", service_spa.id), ] ) # ASSERT self.assertIn( - self.test_service_spa.id, + service_spa.id, items_created.mapped("product_id").ids, "The wizard should create one pricelist items with" " the given service (product_id).", ) - @freeze_time("2025-02-01") def test_sale_dates(self): - # TEST CASE - # Call to wizard with one service (product_id) - # and dates of SALE - # The wizard must create one pricelist items with - # the given service (product_id) and dates of SALE. - + """ + Call to wizard with one service (product_id) + and dates of SALE + The wizard must create one pricelist items with + the given service (product_id) and dates of SALE. + """ # ARRANGE - self.create_common_scenario() + service_spa = self.env["product.product"].create({"name": "Test Spa"}) date_from = fields.date.today() date_to = fields.date.today() wizard_result = self.env["pms.massive.changes.wizard"].create( { "massive_changes_on": "pricelist", - "pricelist_ids": [(6, 0, [self.test_pricelist.id])], + "pricelist_ids": [(6, 0, [self.pricelist1.id])], "apply_pricelists_on": "service", - "service": self.test_service_spa.id, - "pms_property_ids": [self.test_property.id], + "service": service_spa.id, + "pms_property_ids": [self.pms_property1.id], "start_date": date_from, "end_date": date_to, "date_types": "sale_dates", @@ -1063,15 +1187,13 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): ) # ACT wizard_result.apply_massive_changes() - items_created = self.env["product.pricelist.item"].search( [ - ("pricelist_id", "=", self.test_pricelist.id), - ("pms_property_ids", "=", self.test_property.id), - ("product_id", "=", self.test_service_spa.id), + ("pricelist_id", "=", self.pricelist1.id), + ("pms_property_ids", "=", self.pms_property1.id), + ("product_id", "=", service_spa.id), ] ) - expected_dates = [ datetime.datetime.combine(date_from, datetime.datetime.min.time()), datetime.datetime.combine(date_to, datetime.datetime.max.time()), @@ -1085,13 +1207,13 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): ) def test_several_properties_pricelist(self): - # TEST CASE - # If several properties are set, the wizard should create as - # many items as properties. - + """ + If several properties are set, the wizard should create as + many items as properties. + """ # ARRANGE - self.create_common_scenario() - self.test_property2 = self.env["pms.property"].create( + service_spa = self.env["product.product"].create({"name": "Test Spa"}) + pms_property2 = self.env["pms.property"].create( { "name": "MY 2nd PMS TEST", "company_id": self.env.ref("base.main_company").id, @@ -1100,16 +1222,16 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): date_from = fields.date.today() date_to = fields.date.today() expected_properties = [ - self.test_property.id, - self.test_property2.id, + self.pms_property1.id, + pms_property2.id, ] vals_wizard = { "massive_changes_on": "pricelist", - "pricelist_ids": [(6, 0, [self.test_pricelist.id])], + "pricelist_ids": [(6, 0, [self.pricelist1.id])], "apply_pricelists_on": "service", - "service": self.test_service_spa.id, + "service": service_spa.id, "pms_property_ids": [ - (6, 0, [self.test_property.id, self.test_property2.id]) + (6, 0, [self.pms_property1.id, pms_property2.id]) ], "start_date": date_from, "end_date": date_to, @@ -1124,7 +1246,7 @@ class TestPmsWizardMassiveChanges(common.SavepointCase): set(expected_properties), set( self.env["product.pricelist.item"] - .search([("pricelist_id", "=", self.test_pricelist.id)]) + .search([("pricelist_id", "=", self.pricelist1.id)]) .mapped("pms_property_ids") .ids ), From 0300fdac2e6a65c1a60a8fb01570405b2861f01b Mon Sep 17 00:00:00 2001 From: miguelpadin Date: Thu, 10 Jun 2021 22:56:14 +0200 Subject: [PATCH 3/9] [REF] pms: refactor board services tests --- pms/tests/__init__.py | 40 ++++++++--------- pms/tests/test_pms_board_service.py | 46 +++++++++++++++++--- pms/tests/test_pms_wizard_massive_changes.py | 44 ++++++------------- 3 files changed, 75 insertions(+), 55 deletions(-) diff --git a/pms/tests/__init__.py b/pms/tests/__init__.py index 3dde71f10..48c50bbb2 100644 --- a/pms/tests/__init__.py +++ b/pms/tests/__init__.py @@ -19,24 +19,24 @@ # along with this program. If not, see . # ############################################################################## -# from . import test_pms_reservation -# from . import test_pms_pricelist -# from . import test_pms_pricelist_priority -# from . import test_pms_checkin_partner -# from . import test_pms_sale_channel -# from . import test_pms_folio -# from . import test_pms_availability_plan_rules -# from . import test_pms_room_type -# from . import test_pms_room_type_class -# from . import test_pms_board_service +from . import test_pms_reservation +from . import test_pms_pricelist +from . import test_pms_pricelist_priority +from . import test_pms_checkin_partner +from . import test_pms_sale_channel +from . import test_pms_folio +from . import test_pms_availability_plan_rules +from . import test_pms_room_type +from . import test_pms_room_type_class +from . import test_pms_board_service from . import test_pms_wizard_massive_changes -# from . import test_pms_wizard_folio -# from . import test_pms_res_users -# from . import test_pms_amenity -# from . import test_pms_room -# from . import test_pms_board_service_line -# from . import test_pms_board_service_room_type -# from . import test_pms_board_service_room_type_line -# from . import test_pms_folio_invoice -# from . import test_pms_folio_sale_line -# from . import test_pms_wizard_split_join_swap_reservation +from . import test_pms_wizard_folio +from . import test_pms_res_users +from . import test_pms_amenity +from . import test_pms_room +from . import test_pms_board_service_line +from . import test_pms_board_service_room_type +from . import test_pms_board_service_room_type_line +from . import test_pms_folio_invoice +from . import test_pms_folio_sale_line +from . import test_pms_wizard_split_join_swap_reservation diff --git a/pms/tests/test_pms_board_service.py b/pms/tests/test_pms_board_service.py index e96049dd2..93bb10c7b 100644 --- a/pms/tests/test_pms_board_service.py +++ b/pms/tests/test_pms_board_service.py @@ -25,6 +25,9 @@ class TestBoardService(TestPms): # external integrity def test_external_case_01(self): """ + Creation of board service with the same code as an existing one + belonging to the same property should fail. + PRE: - board service bs1 exists - board_service1 has code c1 - board_service1 has pms_property1 @@ -61,6 +64,9 @@ class TestBoardService(TestPms): def test_external_case_02(self): """ + Creation of board service with properties and one of its + properties has the same code on its board services should fail. + PRE: - board service bs1 exists - board_service1 has code c1 - board_service1 has property pms_property1 @@ -114,6 +120,7 @@ class TestBoardService(TestPms): } ) + # TODO: REVIEW. THE NEXT 2 TESTS CHECK THE SAME def test_single_case_01(self): """ PRE: - board service bs1 exists @@ -179,6 +186,9 @@ class TestBoardService(TestPms): def test_single_case_03(self): """ + Search for a specific board service code and its property. + The board service exists but not in the property given. + PRE: - board_service1 exists - board_service1 has code c1 - board_service1 with 2 properties pms_property1 and pms_property2 @@ -218,6 +228,10 @@ class TestBoardService(TestPms): def test_single_case_04(self): """ + Search for a specific board service and its property. + The board service exists without property, then + the search foundS the result. + PRE: - board_service1 exists - board_service1 has code c1 - board_service1 properties are null @@ -246,9 +260,15 @@ class TestBoardService(TestPms): "Expected board service not found", ) - # tests with more than one board service + # TODO: REVIEW. THE NEXT 2 TESTS CHECK THE SAME def test_multiple_case_01(self): """ + Search for a specific board service and its property. + There is one board service without properties and + another one with the same code that belongs to 2 properties. + The search founds only the board service that match the + property given. + PRE: - board_service1 exists - board_service1 has code c1 - board_service1 has 2 properties pms_property1 and pms_property2 @@ -278,12 +298,10 @@ class TestBoardService(TestPms): "pms_property_ids": False, } ) - # ACT board_services = self.env["pms.board.service"].get_unique_by_property_code( self.pms_property1.id, "c1" ) - # ASSERT self.assertEqual( board_services.id, @@ -293,6 +311,12 @@ class TestBoardService(TestPms): def test_multiple_case_02(self): """ + Search for a specific board service and its property. + There is one board service without properties and + another one with the same code that belongs to 2 properties. + The search founds only the board service that match the + property given. + PRE: - board_service1 exists - board_service1 has code c1 - board_service1 has property pms_property1 @@ -302,7 +326,7 @@ class TestBoardService(TestPms): - board_service2 has no properties ACT: - search board service with code c1 and pms_property2 - pms_property2 have company company1 - POST: - only board_service1 board service found + POST: - only board_service2 board service found """ # ARRANGE self.pms_property2 = self.env["pms.property"].create( @@ -312,7 +336,6 @@ class TestBoardService(TestPms): "default_pricelist_id": self.pricelist1.id, } ) - # board_service1 self.env["pms.board.service"].create( { "name": "Board service 1", @@ -340,8 +363,15 @@ class TestBoardService(TestPms): "Expected board service not found", ) + # TODO: REVIEW. THE NEXT 2 TESTS CHECK THE SAME def test_multiple_case_03(self): """ + Search for a specific board service and its property. + There is one board service without properties and + another one with the same code that belongs to one property. + The search founds only the board service that match the + property given that it's not the same as the 2nd one. + PRE: - board_service1 exists - board_service1 has code c1 - board_service1 has property pms_property1 @@ -384,6 +414,12 @@ class TestBoardService(TestPms): def test_multiple_case_04(self): """ + Search for a specific board service and its property. + There is one board service without properties and + another one with the same code that belongs to 2 properties. + The search founds only the board service that match the + property given. + PRE: - board_service1 exists - board_service1 has code c1 - board_service1 has property pms_property1 diff --git a/pms/tests/test_pms_wizard_massive_changes.py b/pms/tests/test_pms_wizard_massive_changes.py index b669a6e85..8c8a13b03 100644 --- a/pms/tests/test_pms_wizard_massive_changes.py +++ b/pms/tests/test_pms_wizard_massive_changes.py @@ -3,11 +3,11 @@ import datetime from freezegun import freeze_time from odoo import fields + from .common import TestPms class TestPmsWizardMassiveChanges(TestPms): - def setUp(self): super().setUp() self.availability_plan1 = self.env["pms.availability.plan"].create( @@ -40,9 +40,7 @@ class TestPmsWizardMassiveChanges(TestPms): self.env["pms.massive.changes.wizard"].create( { "massive_changes_on": "availability_plan", - "availability_plan_ids": [ - (6, 0, [self.availability_plan1.id]) - ], + "availability_plan_ids": [(6, 0, [self.availability_plan1.id])], "start_date": fields.date.today(), "end_date": fields.date.today() + datetime.timedelta(days=days), "room_type_ids": [(6, 0, [room_type_double.id])], @@ -406,9 +404,7 @@ class TestPmsWizardMassiveChanges(TestPms): "massive_changes_on": "availability_plan", "availability_plan_ids": [(6, 0, [self.availability_plan1.id])], "room_type_ids": [(6, 0, [room_type_double.id])], - "pms_property_ids": [ - (6, 0, [self.pms_property1.id, pms_property2.id]) - ], + "pms_property_ids": [(6, 0, [self.pms_property1.id, pms_property2.id])], "start_date": date_from, "end_date": date_to, } @@ -462,11 +458,7 @@ class TestPmsWizardMassiveChanges(TestPms): ).apply_massive_changes() # ASSERT self.assertEqual( - len( - self.pricelist1.item_ids - if self.pricelist1.item_ids - else [] - ), + len(self.pricelist1.item_ids if self.pricelist1.item_ids else []), num_exp_items_to_create, "the number of rules created by the wizard should include all the " "days between start and finish (both included)", @@ -647,9 +639,7 @@ class TestPmsWizardMassiveChanges(TestPms): date_to = fields.date.today() vals_wizard = { "massive_changes_on": "pricelist", - "pricelist_ids": [ - (6, 0, [self.pricelist1.id, pricelist2.id]) - ], + "pricelist_ids": [(6, 0, [self.pricelist1.id, pricelist2.id])], "room_type_ids": [(6, 0, [room_type_double.id])], "pms_property_ids": [self.pms_property1.id], "start_date": date_from, @@ -919,9 +909,7 @@ class TestPmsWizardMassiveChanges(TestPms): service_breakfast = self.env["product.product"].create( {"name": "Test Breakfast"} ) - service_dinner = self.env["product.product"].create( - {"name": "Test Dinner"} - ) + service_dinner = self.env["product.product"].create({"name": "Test Dinner"}) board_service_single = self.env["pms.board.service.room.type"].create( { "pms_room_type_id": room_type_single.id, @@ -934,19 +922,19 @@ class TestPmsWizardMassiveChanges(TestPms): "pms_board_service_id": board_service_half_board.id, } ) - board_service_line_single_1 = self.env["pms.board.service.line"].create( + self.env["pms.board.service.line"].create( { "product_id": service_breakfast.id, "pms_board_service_id": board_service_only_breakfast.id, } ) - board_service_line_double_1 = self.env["pms.board.service.line"].create( + self.env["pms.board.service.line"].create( { "product_id": service_breakfast.id, "pms_board_service_id": board_service_half_board.id, } ) - board_service_line_double_2 = self.env["pms.board.service.line"].create( + self.env["pms.board.service.line"].create( { "product_id": service_dinner.id, "pms_board_service_id": board_service_half_board.id, @@ -1040,9 +1028,7 @@ class TestPmsWizardMassiveChanges(TestPms): service_breakfast = self.env["product.product"].create( {"name": "Test Breakfast"} ) - service_dinner = self.env["product.product"].create( - {"name": "Test Dinner"} - ) + service_dinner = self.env["product.product"].create({"name": "Test Dinner"}) board_service_single = self.env["pms.board.service.room.type"].create( { "pms_room_type_id": room_type_single.id, @@ -1055,19 +1041,19 @@ class TestPmsWizardMassiveChanges(TestPms): "pms_board_service_id": board_service_half_board.id, } ) - board_service_line_single_1 = self.env["pms.board.service.line"].create( + self.env["pms.board.service.line"].create( { "product_id": service_breakfast.id, "pms_board_service_id": board_service_only_breakfast.id, } ) - board_service_line_double_1 = self.env["pms.board.service.line"].create( + self.env["pms.board.service.line"].create( { "product_id": service_breakfast.id, "pms_board_service_id": board_service_half_board.id, } ) - board_service_line_double_2 = self.env["pms.board.service.line"].create( + self.env["pms.board.service.line"].create( { "product_id": service_dinner.id, "pms_board_service_id": board_service_half_board.id, @@ -1230,9 +1216,7 @@ class TestPmsWizardMassiveChanges(TestPms): "pricelist_ids": [(6, 0, [self.pricelist1.id])], "apply_pricelists_on": "service", "service": service_spa.id, - "pms_property_ids": [ - (6, 0, [self.pms_property1.id, pms_property2.id]) - ], + "pms_property_ids": [(6, 0, [self.pms_property1.id, pms_property2.id])], "start_date": date_from, "end_date": date_to, "date_types": "sale_dates", From ccaa0f9cb21588dde0bc439c59d8ae044c362c6d Mon Sep 17 00:00:00 2001 From: miguelpadin Date: Thu, 10 Jun 2021 23:59:07 +0200 Subject: [PATCH 4/9] [REF] pms: refactor board service lines tests --- pms/tests/test_pms_board_service_line.py | 154 +++++++++++++---------- 1 file changed, 91 insertions(+), 63 deletions(-) diff --git a/pms/tests/test_pms_board_service_line.py b/pms/tests/test_pms_board_service_line.py index d6a465349..e6252aebd 100644 --- a/pms/tests/test_pms_board_service_line.py +++ b/pms/tests/test_pms_board_service_line.py @@ -1,75 +1,103 @@ from odoo.exceptions import UserError -from odoo.tests import common + +from .common import TestPms -class TestPmsBoardService(common.SavepointCase): - def test_property_integrity(self): - self.company1 = self.env["res.company"].create( - { - "name": "Pms_Company_Test", - } - ) - self.folio_sequence = self.env["ir.sequence"].create( - { - "name": "PMS Folio", - "code": "pms.folio", - "padding": 4, - "company_id": self.company1.id, - } - ) - self.reservation_sequence = self.env["ir.sequence"].create( - { - "name": "PMS Reservation", - "code": "pms.reservation", - "padding": 4, - "company_id": self.company1.id, - } - ) - self.checkin_sequence = self.env["ir.sequence"].create( - { - "name": "PMS Checkin", - "code": "pms.checkin.partner", - "padding": 4, - "company_id": self.company1.id, - } - ) - self.property1 = self.env["pms.property"].create( - { - "name": "Pms_property_test1", - "company_id": self.company1.id, - "default_pricelist_id": self.env.ref("product.list0").id, - "folio_sequence_id": self.folio_sequence.id, - "reservation_sequence_id": self.reservation_sequence.id, - "checkin_sequence_id": self.checkin_sequence.id, - } - ) - self.property2 = self.env["pms.property"].create( - { - "name": "Pms_property_test2", - "company_id": self.company1.id, - "default_pricelist_id": self.env.ref("product.list0").id, - "folio_sequence_id": self.folio_sequence.id, - "reservation_sequence_id": self.reservation_sequence.id, - "checkin_sequence_id": self.checkin_sequence.id, - } - ) - self.product = self.env["product.product"].create( - {"name": "Product", "pms_property_ids": self.property1} - ) +class TestPmsBoardService(TestPms): + def setUp(self): + super().setUp() - self.board_service = self.env["pms.board.service"].create( + def test_pms_board_service_line_product_property_integrity(self): + """ + Creation of a board service line without property, of a product + only available for a specific property. + """ + # ARRANGE + product = self.env["product.product"].create( + {"name": "Product", "pms_property_ids": [self.pms_property1.id]} + ) + board_service = self.env["pms.board.service"].create( { "name": "Board Service", "default_code": "CB", } ) - with self.assertRaises(UserError): - board_service_line = self.board_service_line = self.env[ - "pms.board.service.line" - ].create( + # ACT & ASSERT + with self.assertRaises( + UserError, msg="Board service line shouldnt be created." + ): + self.env["pms.board.service.line"].create( { - "product_id": self.product.id, - "pms_board_service_id": self.board_service.id, + "product_id": product.id, + "pms_board_service_id": board_service.id, + } + ) + + def test_pms_board_service_line_board_service_integrity(self): + """ + Creation of a board service line without property, of board service + only available for a specific property. + """ + # ARRANGE + pms_property2 = self.env["pms.property"].create( + { + "name": "Property 1", + "company_id": self.company1.id, + "default_pricelist_id": self.pricelist1.id, + } + ) + product = self.env["product.product"].create( + {"name": "Product", "pms_property_ids": [self.pms_property1.id]} + ) + + board_service = self.env["pms.board.service"].create( + { + "name": "Board Service", + "default_code": "CB", + "pms_property_ids": [pms_property2.id], + } + ) + # ACT & ASSERT + with self.assertRaises( + UserError, msg="Board service line shouldnt be created." + ): + self.env["pms.board.service.line"].create( + { + "product_id": product.id, + "pms_board_service_id": board_service.id, + } + ) + + def test_pms_board_service_line_board_service_line_integrity(self): + """ + Creation of a board service line with a specific property, + of board service without property. + """ + # ARRANGE + pms_property2 = self.env["pms.property"].create( + { + "name": "Property 1", + "company_id": self.company1.id, + "default_pricelist_id": self.pricelist1.id, + } + ) + product = self.env["product.product"].create( + {"name": "Product", "pms_property_ids": [self.pms_property1.id]} + ) + board_service = self.env["pms.board.service"].create( + { + "name": "Board Service", + "default_code": "CB", + } + ) + # ACT & ASSERT + with self.assertRaises( + UserError, msg="Board service line shouldnt be created." + ): + self.env["pms.board.service.line"].create( + { + "product_id": product.id, + "pms_board_service_id": board_service.id, + "pms_property_ids": [pms_property2.id], } ) - board_service_line.pms_property_ids = [self.property2.id] From cfa296b299013cbb067a4081a54b9ec856a13a3b Mon Sep 17 00:00:00 2001 From: miguelpadin Date: Fri, 11 Jun 2021 00:25:38 +0200 Subject: [PATCH 5/9] [REF] pms: refactor board service room type tests --- pms/tests/test_pms_board_service_line.py | 3 - pms/tests/test_pms_board_service_room_type.py | 248 ++++++++++-------- 2 files changed, 133 insertions(+), 118 deletions(-) diff --git a/pms/tests/test_pms_board_service_line.py b/pms/tests/test_pms_board_service_line.py index e6252aebd..1cb062dde 100644 --- a/pms/tests/test_pms_board_service_line.py +++ b/pms/tests/test_pms_board_service_line.py @@ -4,9 +4,6 @@ from .common import TestPms class TestPmsBoardService(TestPms): - def setUp(self): - super().setUp() - def test_pms_board_service_line_product_property_integrity(self): """ Creation of a board service line without property, of a product diff --git a/pms/tests/test_pms_board_service_room_type.py b/pms/tests/test_pms_board_service_room_type.py index 94935e6f2..46fd71a7c 100644 --- a/pms/tests/test_pms_board_service_room_type.py +++ b/pms/tests/test_pms_board_service_room_type.py @@ -1,81 +1,89 @@ -from odoo.tests import common +from .common import TestPms -class TestPmsBoardServiceRoomType(common.SavepointCase): - def _create_common_scenario(self): - self.company1 = self.env["res.company"].create( - { - "name": "Pms_Company_Test", - } - ) - self.folio_sequence = self.env["ir.sequence"].create( - { - "name": "PMS Folio", - "code": "pms.folio", - "padding": 4, - "company_id": self.company1.id, - } - ) - self.reservation_sequence = self.env["ir.sequence"].create( - { - "name": "PMS Reservation", - "code": "pms.reservation", - "padding": 4, - "company_id": self.company1.id, - } - ) - self.checkin_sequence = self.env["ir.sequence"].create( - { - "name": "PMS Checkin", - "code": "pms.checkin.partner", - "padding": 4, - "company_id": self.company1.id, - } - ) - self.property1 = self.env["pms.property"].create( - { - "name": "Pms_property_test1", - "company_id": self.company1.id, - "default_pricelist_id": self.env.ref("product.list0").id, - "folio_sequence_id": self.folio_sequence.id, - "reservation_sequence_id": self.reservation_sequence.id, - "checkin_sequence_id": self.checkin_sequence.id, - } - ) - self.property2 = self.env["pms.property"].create( - { - "name": "Pms_property_test2", - "company_id": self.company1.id, - "default_pricelist_id": self.env.ref("product.list0").id, - "folio_sequence_id": self.folio_sequence.id, - "reservation_sequence_id": self.reservation_sequence.id, - "checkin_sequence_id": self.checkin_sequence.id, - } - ) - self.room_type_availability = self.env["pms.availability.plan"].create( - {"name": "Availability plan for TEST"} - ) +class TestPmsBoardServiceRoomType(TestPms): - # create room type class - self.room_type_class = self.env["pms.room.type.class"].create( - {"name": "Room", "default_code": "ROOM"} - ) + # def _create_common_scenario(self): + # self.company1 = self.env["res.company"].create( + # { + # "name": "Pms_Company_Test", + # } + # ) + # self.folio_sequence = self.env["ir.sequence"].create( + # { + # "name": "PMS Folio", + # "code": "pms.folio", + # "padding": 4, + # "company_id": self.company1.id, + # } + # ) + # self.reservation_sequence = self.env["ir.sequence"].create( + # { + # "name": "PMS Reservation", + # "code": "pms.reservation", + # "padding": 4, + # "company_id": self.company1.id, + # } + # ) + # self.checkin_sequence = self.env["ir.sequence"].create( + # { + # "name": "PMS Checkin", + # "code": "pms.checkin.partner", + # "padding": 4, + # "company_id": self.company1.id, + # } + # ) + # self.property1 = self.env["pms.property"].create( + # { + # "name": "Pms_property_test1", + # "company_id": self.company1.id, + # "default_pricelist_id": self.env.ref("product.list0").id, + # "folio_sequence_id": self.folio_sequence.id, + # "reservation_sequence_id": self.reservation_sequence.id, + # "checkin_sequence_id": self.checkin_sequence.id, + # } + # ) + # self.property2 = self.env["pms.property"].create( + # { + # "name": "Pms_property_test2", + # "company_id": self.company1.id, + # "default_pricelist_id": self.env.ref("product.list0").id, + # "folio_sequence_id": self.folio_sequence.id, + # "reservation_sequence_id": self.reservation_sequence.id, + # "checkin_sequence_id": self.checkin_sequence.id, + # } + # ) + # self.room_type_availability = self.env["pms.availability.plan"].create( + # {"name": "Availability plan for TEST"} + # ) + # + # # create room type class + # self.room_type_class = self.env["pms.room.type.class"].create( + # {"name": "Room", "default_code": "ROOM"} + # ) def test_create_rt_props_gt_bs_props(self): - # TEST CASE - # Create board service for a room type and the room type - # have MORE properties than the board service. - # Record of board_service_room_type should contain the - # board service properties. - + """ + Create board service for a room type and the room type + have MORE properties than the board service. + Record of board_service_room_type should contain the + board service properties. + """ # ARRANGE - self._create_common_scenario() + pms_property2 = self.env["pms.property"].create( + { + "name": "Property 2", + "company_id": self.company1.id, + "default_pricelist_id": self.pricelist1.id, + } + ) + room_type_double = self.env["pms.room.type"].create( { - "pms_property_ids": [self.property1.id, self.property2.id], + "pms_property_ids": [self.pms_property1.id, pms_property2.id], "name": "Double Test", "default_code": "DBL_Test", - "class_id": self.room_type_class.id, + "class_id": self.room_type_class1.id, "price": 25, } ) @@ -83,7 +91,7 @@ class TestPmsBoardServiceRoomType(common.SavepointCase): { "name": "Test Board Service", "default_code": "TPS", - "pms_property_ids": [self.property1.id], + "pms_property_ids": [self.pms_property1.id], } ) # ACT @@ -102,20 +110,26 @@ class TestPmsBoardServiceRoomType(common.SavepointCase): ) def test_create_rt_props_lt_bs_props(self): - # TEST CASE - # Create board service for a room type and the room type - # have LESS properties than the board service. - # Record of board_service_room_type should contain the - # room types properties. - + """ + Create board service for a room type and the room type + have LESS properties than the board service. + Record of board_service_room_type should contain the + room types properties. + """ # ARRANGE - self._create_common_scenario() + pms_property2 = self.env["pms.property"].create( + { + "name": "Property 2", + "company_id": self.company1.id, + "default_pricelist_id": self.pricelist1.id, + } + ) room_type_double = self.env["pms.room.type"].create( { - "pms_property_ids": [self.property1.id], + "pms_property_ids": [self.pms_property1.id], "name": "Double Test", "default_code": "DBL_Test", - "class_id": self.room_type_class.id, + "class_id": self.room_type_class1.id, "price": 25, } ) @@ -123,7 +137,7 @@ class TestPmsBoardServiceRoomType(common.SavepointCase): { "name": "Test Board Service", "default_code": "TPS", - "pms_property_ids": [self.property1.id, self.property2.id], + "pms_property_ids": [self.pms_property1.id, pms_property2.id], } ) # ACT @@ -142,21 +156,20 @@ class TestPmsBoardServiceRoomType(common.SavepointCase): ) def test_create_rt_props_eq_bs_props(self): - # TEST CASE - # Create board service for a room type and the room type - # have THE SAME properties than the board service. - # Record of board_service_room_type should contain the - # room types properties that matchs with the board - # service properties - + """ + Create board service for a room type and the room type + have THE SAME properties than the board service. + Record of board_service_room_type should contain the + room types properties that matchs with the board + service properties + """ # ARRANGE - self._create_common_scenario() room_type_double = self.env["pms.room.type"].create( { - "pms_property_ids": [self.property1.id], + "pms_property_ids": [self.pms_property1.id], "name": "Double Test", "default_code": "DBL_Test", - "class_id": self.room_type_class.id, + "class_id": self.room_type_class1.id, "price": 25, } ) @@ -164,7 +177,7 @@ class TestPmsBoardServiceRoomType(common.SavepointCase): { "name": "Test Board Service", "default_code": "TPS", - "pms_property_ids": [self.property1.id], + "pms_property_ids": [self.pms_property1.id], } ) # ACT @@ -184,19 +197,18 @@ class TestPmsBoardServiceRoomType(common.SavepointCase): ) def test_create_rt_no_props_and_bs_props(self): - # TEST CASE - # Create board service for a room type and the room type - # hasn't properties but the board services. - # Record of board_service_room_type should contain the - # board service properties. - + """ + Create board service for a room type and the room type + hasn't properties but the board services. + Record of board_service_room_type should contain the + board service properties. + """ # ARRANGE - self._create_common_scenario() room_type_double = self.env["pms.room.type"].create( { "name": "Double Test", "default_code": "DBL_Test", - "class_id": self.room_type_class.id, + "class_id": self.room_type_class1.id, "price": 25, } ) @@ -204,7 +216,7 @@ class TestPmsBoardServiceRoomType(common.SavepointCase): { "name": "Test Board Service", "default_code": "TPS", - "pms_property_ids": [self.property1.id], + "pms_property_ids": [self.pms_property1.id], } ) # ACT @@ -223,20 +235,26 @@ class TestPmsBoardServiceRoomType(common.SavepointCase): ) def test_create_rt_props_and_bs_no_props(self): - # TEST CASE - # Create board service for a room type and the board service - # hasn't properties but the room type. - # Record of board_service_room_type should contain the - # room type properties. - + """ + Create board service for a room type and the board service + hasn't properties but the room type. + Record of board_service_room_type should contain the + room type properties. + """ # ARRANGE - self._create_common_scenario() + pms_property2 = self.env["pms.property"].create( + { + "name": "Property 2", + "company_id": self.company1.id, + "default_pricelist_id": self.pricelist1.id, + } + ) room_type_double = self.env["pms.room.type"].create( { - "pms_property_ids": [self.property1.id, self.property2.id], + "pms_property_ids": [self.pms_property1.id, pms_property2.id], "name": "Double Test", "default_code": "DBL_Test", - "class_id": self.room_type_class.id, + "class_id": self.room_type_class1.id, "price": 25, } ) @@ -262,18 +280,18 @@ class TestPmsBoardServiceRoomType(common.SavepointCase): ) def test_create_rt_no_props_and_bs_no_props(self): - # TEST CASE - # Create board service for a room type and the board service - # has no properties and neither does the room type - # Record of board_service_room_type shouldnt contain properties. - + """ + Create board service for a room type and the board service + has no properties and neither does the room type + Record of board_service_room_type shouldnt contain properties. + """ # ARRANGE - self._create_common_scenario() + room_type_double = self.env["pms.room.type"].create( { "name": "Double Test", "default_code": "DBL_Test", - "class_id": self.room_type_class.id, + "class_id": self.room_type_class1.id, "price": 25, } ) From 8893ba47c56c011a16fe9ff4ec3149b0c2d348d6 Mon Sep 17 00:00:00 2001 From: miguelpadin Date: Fri, 11 Jun 2021 01:14:26 +0200 Subject: [PATCH 6/9] [REF] pms: refactor board service room type line tests --- pms/tests/test_pms_board_service_line.py | 6 +- .../test_pms_board_service_room_type_line.py | 146 +++++++++--------- 2 files changed, 76 insertions(+), 76 deletions(-) diff --git a/pms/tests/test_pms_board_service_line.py b/pms/tests/test_pms_board_service_line.py index 1cb062dde..21e3d6d4b 100644 --- a/pms/tests/test_pms_board_service_line.py +++ b/pms/tests/test_pms_board_service_line.py @@ -4,7 +4,7 @@ from .common import TestPms class TestPmsBoardService(TestPms): - def test_pms_board_service_line_product_property_integrity(self): + def test_pms_bsl_product_property_integrity(self): """ Creation of a board service line without property, of a product only available for a specific property. @@ -30,7 +30,7 @@ class TestPmsBoardService(TestPms): } ) - def test_pms_board_service_line_board_service_integrity(self): + def test_pms_bsl_board_service_property_integrity(self): """ Creation of a board service line without property, of board service only available for a specific property. @@ -65,7 +65,7 @@ class TestPmsBoardService(TestPms): } ) - def test_pms_board_service_line_board_service_line_integrity(self): + def test_pms_bsl_board_service_line_prop_integrity(self): """ Creation of a board service line with a specific property, of board service without property. diff --git a/pms/tests/test_pms_board_service_room_type_line.py b/pms/tests/test_pms_board_service_room_type_line.py index 6311c8cc7..62b44feb3 100644 --- a/pms/tests/test_pms_board_service_room_type_line.py +++ b/pms/tests/test_pms_board_service_room_type_line.py @@ -1,95 +1,95 @@ from odoo.exceptions import UserError -from odoo.tests import common + +from .common import TestPms -class TestPmsBoardServiceRoomTypeLine(common.SavepointCase): - def test_check_product_property_integrity(self): - self.company1 = self.env["res.company"].create( - { - "name": "Pms_Company_Test", - } +class TestPmsBoardServiceRoomTypeLine(TestPms): + def test_pms_bsrtl_product_property_integrity(self): + """ + Creation of a board service room type line without property, of a product + only available for a specific property. + """ + # ARRANGE + + product = self.env["product.product"].create( + {"name": "Product", "pms_property_ids": self.pms_property1} ) - self.folio_sequence = self.env["ir.sequence"].create( - { - "name": "PMS Folio", - "code": "pms.folio", - "padding": 4, - "company_id": self.company1.id, - } - ) - self.reservation_sequence = self.env["ir.sequence"].create( - { - "name": "PMS Reservation", - "code": "pms.reservation", - "padding": 4, - "company_id": self.company1.id, - } - ) - self.checkin_sequence = self.env["ir.sequence"].create( - { - "name": "PMS Checkin", - "code": "pms.checkin.partner", - "padding": 4, - "company_id": self.company1.id, - } - ) - self.property1 = self.env["pms.property"].create( - { - "name": "Pms_property_test1", - "company_id": self.company1.id, - "default_pricelist_id": self.env.ref("product.list0").id, - "folio_sequence_id": self.folio_sequence.id, - "reservation_sequence_id": self.reservation_sequence.id, - "checkin_sequence_id": self.checkin_sequence.id, - } - ) - self.property2 = self.env["pms.property"].create( - { - "name": "Pms_property_test2", - "company_id": self.company1.id, - "default_pricelist_id": self.env.ref("product.list0").id, - "folio_sequence_id": self.folio_sequence.id, - "reservation_sequence_id": self.reservation_sequence.id, - "checkin_sequence_id": self.checkin_sequence.id, - } - ) - self.board_service = self.env["pms.board.service"].create( + board_service = self.env["pms.board.service"].create( { "name": "Board Service", "default_code": "CB", - "pms_property_ids": self.property1, } ) - self.room_type_class = self.env["pms.room.type.class"].create( - { - "name": "Room Type Class", - "default_code": "SIN1", - "pms_property_ids": self.property1, - } - ) - self.room_type = self.env["pms.room.type"].create( + room_type = self.env["pms.room.type"].create( { "name": "Room Type", "default_code": "Type1", - "pms_property_ids": self.property1, - "class_id": self.room_type_class.id, + "class_id": self.room_type_class1.id, } ) - self.board_service_room_type = self.env["pms.board.service.room.type"].create( + board_service_room_type = self.env["pms.board.service.room.type"].create( { - "pms_board_service_id": self.board_service.id, - "pms_room_type_id": self.room_type.id, - "pms_property_ids": self.property1, + "pms_board_service_id": board_service.id, + "pms_room_type_id": room_type.id, } ) - self.product = self.env["product.product"].create( - {"name": "Product", "pms_property_ids": self.property2} - ) - with self.assertRaises(UserError): + # ACT & ASSERT + with self.assertRaises( + UserError, msg="Board service room type line shouldnt be created." + ): self.env["pms.board.service.room.type.line"].create( { - "pms_board_service_room_type_id": self.board_service_room_type.id, - "product_id": self.product.id, + "pms_board_service_room_type_id": board_service_room_type.id, + "product_id": product.id, + } + ) + + def test_pms_bsrtl_board_service_line_prop_integrity(self): + """ + Creation of a board service room type line with a specific property, + of board service without property. + """ + # ARRANGE + pms_property2 = self.env["pms.property"].create( + { + "name": "Property 1", + "company_id": self.company1.id, + "default_pricelist_id": self.pricelist1.id, + } + ) + product = self.env["product.product"].create( + {"name": "Product", "pms_property_ids": [self.pms_property1.id]} + ) + board_service = self.env["pms.board.service"].create( + { + "name": "Board Service", + "default_code": "CB", + } + ) + + room_type = self.env["pms.room.type"].create( + { + "name": "Room Type", + "default_code": "Type1", + "class_id": self.room_type_class1.id, + } + ) + board_service_room_type = self.env["pms.board.service.room.type"].create( + { + "pms_board_service_id": board_service.id, + "pms_room_type_id": room_type.id, + } + ) + + # ACT & ASSERT + with self.assertRaises( + UserError, msg="Board service line shouldnt be created." + ): + self.env["pms.board.service.room.type.line"].create( + { + "product_id": product.id, + "pms_property_ids": [pms_property2.id], + "pms_board_service_room_type_id": board_service_room_type.id, } ) From 8c50359f961dab9c3dd00372183de510c36ddd2f Mon Sep 17 00:00:00 2001 From: miguelpadin Date: Fri, 11 Jun 2021 11:01:43 +0200 Subject: [PATCH 7/9] [REF] pms: refactor board service tests --- pms/tests/test_pms_board_service.py | 107 ++++++++-------------------- 1 file changed, 29 insertions(+), 78 deletions(-) diff --git a/pms/tests/test_pms_board_service.py b/pms/tests/test_pms_board_service.py index 93bb10c7b..800301c84 100644 --- a/pms/tests/test_pms_board_service.py +++ b/pms/tests/test_pms_board_service.py @@ -22,8 +22,7 @@ class TestBoardService(TestPms): } ) - # external integrity - def test_external_case_01(self): + def test_create_bs_one_company_inconsistent_code(self): """ Creation of board service with the same code as an existing one belonging to the same property should fail. @@ -48,7 +47,6 @@ class TestBoardService(TestPms): "pms_property_ids": [(6, 0, [self.pms_property1.id])], } ) - # ACT & ASSERT with self.assertRaises( ValidationError, msg="The board service has been created and it shouldn't" @@ -62,7 +60,7 @@ class TestBoardService(TestPms): } ) - def test_external_case_02(self): + def test_create_bs_several_companies_inconsistent_code(self): """ Creation of board service with properties and one of its properties has the same code on its board services should fail. @@ -96,7 +94,6 @@ class TestBoardService(TestPms): "pms_property_ids": [(6, 0, [self.pms_property1.id])], } ) - # ACT & ASSERT with self.assertRaises( ValidationError, msg="The board service has been created and it shouldn't" @@ -120,9 +117,11 @@ class TestBoardService(TestPms): } ) - # TODO: REVIEW. THE NEXT 2 TESTS CHECK THE SAME - def test_single_case_01(self): + def test_search_bs_code_same_company_several_properties(self): """ + Checks the search for a board service by code when the board service + belongs to properties of the same company + PRE: - board service bs1 exists - board_service1 has code c1 - board_service1 has 2 properties pms_property1 and pms_property2 @@ -132,21 +131,26 @@ class TestBoardService(TestPms): POST: - only board_service1 board service found """ # ARRANGE + self.pms_property2 = self.env["pms.property"].create( + { + "name": "Property 2", + "company_id": self.company1.id, + "default_pricelist_id": self.pricelist1.id, + } + ) board_service1 = self.env["pms.board.service"].create( { "name": "Board service 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]) ], } ) - # ACT board_services = self.env["pms.board.service"].get_unique_by_property_code( self.pms_property1.id, "c1" ) - # ASSERT self.assertEqual( board_services.id, @@ -154,12 +158,15 @@ class TestBoardService(TestPms): "Expected board service not found", ) - def test_single_case_02(self): + def test_search_bs_code_several_companies_several_properties_not_found(self): """ + Checks the search for a board service by code when the board service + belongs to properties with different companies + PRE: - board service bs1 exists - board_service1 has code c1 - board_service1 has 2 properties pms_property1 and pms_property3 - - pms_property1 and pms_property2 have different companies + - pms_property1 and pms_property3 have different companies - pms_property1 have company company1 and pms_property3 have company2 ACT: - search board service with code c1 and property pms_property1 - pms_property1 has company company1 @@ -175,16 +182,14 @@ class TestBoardService(TestPms): ], } ) - # ACT board_services = self.env["pms.board.service"].get_unique_by_property_code( self.pms_property1.id, "c1" ) - # ASSERT self.assertEqual(board_services.id, bs1.id, "Expected board service not found") - def test_single_case_03(self): + def test_search_bs_code_no_result(self): """ Search for a specific board service code and its property. The board service exists but not in the property given. @@ -215,18 +220,16 @@ class TestBoardService(TestPms): ], } ) - # ACT board_services = self.env["pms.board.service"].get_unique_by_property_code( self.pms_property3.id, "c1" ) - # ASSERT self.assertFalse( board_services, "Board service found but it should not have found any" ) - def test_single_case_04(self): + def test_search_bs_code_present_all_companies_and_properties(self): """ Search for a specific board service and its property. The board service exists without property, then @@ -247,12 +250,10 @@ class TestBoardService(TestPms): "pms_property_ids": False, } ) - # ACT board_services = self.env["pms.board.service"].get_unique_by_property_code( self.pms_property1.id, "c1" ) - # ASSERT self.assertEqual( board_services.id, @@ -260,18 +261,18 @@ class TestBoardService(TestPms): "Expected board service not found", ) - # TODO: REVIEW. THE NEXT 2 TESTS CHECK THE SAME - def test_multiple_case_01(self): + def test_search_bs_code_several_companies_several_properties(self): """ Search for a specific board service and its property. There is one board service without properties and - another one with the same code that belongs to 2 properties. + another one with the same code that belongs to 2 properties + (from different companies) The search founds only the board service that match the property given. PRE: - board_service1 exists - board_service1 has code c1 - - board_service1 has 2 properties pms_property1 and pms_property2 + - board_service1 has 2 properties pms_property1 and pms_property3 - pms_property1 and pms_property2 have the same company company1 - board service board_service2 exists - board_service2 has code c1 @@ -309,11 +310,12 @@ class TestBoardService(TestPms): "Expected board service not found", ) - def test_multiple_case_02(self): + def test_search_bs_code_same_companies_several_properties(self): """ Search for a specific board service and its property. There is one board service without properties and - another one with the same code that belongs to 2 properties. + another one with the same code that belongs to 2 properties + (same company). The search founds only the board service that match the property given. @@ -350,12 +352,10 @@ class TestBoardService(TestPms): "pms_property_ids": False, } ) - # ACT board_services = self.env["pms.board.service"].get_unique_by_property_code( self.pms_property2.id, "c1" ) - # ASSERT self.assertEqual( board_services.id, @@ -363,8 +363,7 @@ class TestBoardService(TestPms): "Expected board service not found", ) - # TODO: REVIEW. THE NEXT 2 TESTS CHECK THE SAME - def test_multiple_case_03(self): + def test_search_bs_code_no_properties(self): """ Search for a specific board service and its property. There is one board service without properties and @@ -399,61 +398,13 @@ class TestBoardService(TestPms): "pms_property_ids": False, } ) - # ACT board_services = self.env["pms.board.service"].get_unique_by_property_code( self.pms_property3.id, "c1" ) - # ASSERT self.assertEqual( board_services.id, board_service2.id, "Expected board service not found", ) - - def test_multiple_case_04(self): - """ - Search for a specific board service and its property. - There is one board service without properties and - another one with the same code that belongs to 2 properties. - The search founds only the board service that match the - property given. - - PRE: - board_service1 exists - - board_service1 has code c1 - - board_service1 has property pms_property1 - - pms_property1 have the company company1 - - room type board_service2 exists - - board_service2 has code c1 - - board_service2 has no properties - ACT: - search board service with code c1 and property pms_property3 - - pms_property3 have company company2 - POST: - r2 board service found - """ - # ARRANGE - # board_service1 - self.env["pms.board.service"].create( - { - "name": "Board service 1", - "default_code": "c1", - "pms_property_ids": [(6, 0, [self.pms_property1.id])], - } - ) - board_service2 = self.env["pms.board.service"].create( - { - "name": "Board service bs2", - "default_code": "c1", - "pms_property_ids": False, - } - ) - - # ACT - board_services = self.env["pms.board.service"].get_unique_by_property_code( - self.pms_property3.id, "c1" - ) - - # ASSERT - self.assertEqual( - board_services.id, board_service2.id, "Expected room type not found" - ) From 0afeba30c8899e0d0858c9e457553c24918b5f1d Mon Sep 17 00:00:00 2001 From: miguelpadin Date: Tue, 15 Jun 2021 02:34:49 +0200 Subject: [PATCH 8/9] [REF] pms: refactor room type tests --- pms/tests/test_pms_board_service_room_type.py | 60 ---- pms/tests/test_pms_room_type.py | 331 +++++++++++------- 2 files changed, 214 insertions(+), 177 deletions(-) diff --git a/pms/tests/test_pms_board_service_room_type.py b/pms/tests/test_pms_board_service_room_type.py index 46fd71a7c..17790289f 100644 --- a/pms/tests/test_pms_board_service_room_type.py +++ b/pms/tests/test_pms_board_service_room_type.py @@ -2,66 +2,6 @@ from .common import TestPms class TestPmsBoardServiceRoomType(TestPms): - - # def _create_common_scenario(self): - # self.company1 = self.env["res.company"].create( - # { - # "name": "Pms_Company_Test", - # } - # ) - # self.folio_sequence = self.env["ir.sequence"].create( - # { - # "name": "PMS Folio", - # "code": "pms.folio", - # "padding": 4, - # "company_id": self.company1.id, - # } - # ) - # self.reservation_sequence = self.env["ir.sequence"].create( - # { - # "name": "PMS Reservation", - # "code": "pms.reservation", - # "padding": 4, - # "company_id": self.company1.id, - # } - # ) - # self.checkin_sequence = self.env["ir.sequence"].create( - # { - # "name": "PMS Checkin", - # "code": "pms.checkin.partner", - # "padding": 4, - # "company_id": self.company1.id, - # } - # ) - # self.property1 = self.env["pms.property"].create( - # { - # "name": "Pms_property_test1", - # "company_id": self.company1.id, - # "default_pricelist_id": self.env.ref("product.list0").id, - # "folio_sequence_id": self.folio_sequence.id, - # "reservation_sequence_id": self.reservation_sequence.id, - # "checkin_sequence_id": self.checkin_sequence.id, - # } - # ) - # self.property2 = self.env["pms.property"].create( - # { - # "name": "Pms_property_test2", - # "company_id": self.company1.id, - # "default_pricelist_id": self.env.ref("product.list0").id, - # "folio_sequence_id": self.folio_sequence.id, - # "reservation_sequence_id": self.reservation_sequence.id, - # "checkin_sequence_id": self.checkin_sequence.id, - # } - # ) - # self.room_type_availability = self.env["pms.availability.plan"].create( - # {"name": "Availability plan for TEST"} - # ) - # - # # create room type class - # self.room_type_class = self.env["pms.room.type.class"].create( - # {"name": "Room", "default_code": "ROOM"} - # ) - def test_create_rt_props_gt_bs_props(self): """ Create board service for a room type and the room type diff --git a/pms/tests/test_pms_room_type.py b/pms/tests/test_pms_room_type.py index 997d6c669..3ae81a86e 100644 --- a/pms/tests/test_pms_room_type.py +++ b/pms/tests/test_pms_room_type.py @@ -30,8 +30,11 @@ class TestRoomType(TestPms): } ) - def test_internal_case_01(self): + def test_create_room_type_consistency_company(self): """ + Create a room type with a company (1) consistent with the company property (1). + Creation should be successful. + PRE: - room_type1 does not exists ACT: - create a new room_type1 room - room_type1 has code c1 @@ -40,23 +43,25 @@ class TestRoomType(TestPms): - room_type1 has company company1 POST: - room_type1 created """ - # ARRANGE & ACT & ASSERT - try: - # room_type1 - self.env["pms.room.type"].create( - { - "name": "Room type 1", - "default_code": "c1", - "pms_property_ids": [(6, 0, [self.pms_property1.id])], - "company_id": self.company1.id, - "class_id": self.room_type_class1.id, - } - ) - except ValidationError: - self.fail("Room type not created when it should") + # ARRANGE & ACT + new_room_type = self.env["pms.room.type"].create( + { + "name": "Room type 1", + "default_code": "c1", + "pms_property_ids": [(6, 0, [self.pms_property1.id])], + "company_id": self.company1.id, + "class_id": self.room_type_class1.id, + } + ) + # ASSERT + self.assertTrue(new_room_type.id, "Room type not created when it should") - def test_internal_case_02(self): + def test_create_room_type_inconsistency_company(self): """ + Create a room type with inconsistency between company (1) + and company property (1). + The creation should fail. + PRE: - room_type1 does not exists ACT: - create a new room_type1 room - room_type1 has code c1 @@ -81,8 +86,12 @@ class TestRoomType(TestPms): } ) - def test_internal_case_03(self): + def test_create_room_type_inconsistency_companies(self): """ + Create a room type with inconsistency between company (1) + and company properties (several). + The creation should fail. + PRE: - room_type1 does not exists ACT: - create a new room_type1 room - room_type1 has code c1 @@ -110,10 +119,14 @@ class TestRoomType(TestPms): } ) - def test_internal_case_04(self): + def test_create_room_type_consistency_companies(self): """ + Create a room type with consistency between companies (all) + and company properties (2). + Creation should be successful. + PRE: - room_type1 does not exists - ACT: - create a new room_type1 room + ACT: - create a new room_type1 - room_type1 has code c1 - room_type1 has property pms_property1 and pms_property3 - pms_property1 has company company1 @@ -121,26 +134,28 @@ class TestRoomType(TestPms): - room_type1 has no company POST: - room_type1 created """ - # ARRANGE & ACT & ASSERT - try: - # room_type1 - self.env["pms.room.type"].create( - { - "name": "Room type 1", - "default_code": "c1", - "pms_property_ids": [ - (6, 0, [self.pms_property1.id, self.pms_property3.id]) - ], - "company_id": False, - "class_id": self.room_type_class1.id, - } - ) - except ValidationError: - self.fail("Room type not created when it should") + # ARRANGE & ACT + new_room_type = self.env["pms.room.type"].create( + { + "name": "Room type 1", + "default_code": "c1", + "pms_property_ids": [ + (6, 0, [self.pms_property1.id, self.pms_property3.id]) + ], + "company_id": False, + "class_id": self.room_type_class1.id, + } + ) + # ASSERT + self.assertTrue(new_room_type.id, "Room type not created when it should") # external integrity - def test_external_case_01(self): + def test_create_room_type_inconsistency_all_companies(self): """ + Create a room type for 1 company and 1 property. + Try to create a room type for all the companies. + The creation should fail. + PRE: - room type room_type1 exists - room_type1 has code c1 - room_type1 has property pms_property1 @@ -165,7 +180,6 @@ class TestRoomType(TestPms): "class_id": self.room_type_class1.id, } ) - # ACT & ASSERT with self.assertRaises( ValidationError, msg="The room type has been created and it shouldn't" @@ -181,8 +195,13 @@ class TestRoomType(TestPms): } ) - def test_external_case_02(self): + def test_create_room_type_inconsistency_code_company(self): """ + Create a room type for all the companies and for one property. + Try to create a room type with same code and same property but + for all companies. + The creation should fail. + PRE: - room type room_type1 exists - room_type1 has code c1 - room_type1 has property pms_property1 @@ -223,8 +242,13 @@ class TestRoomType(TestPms): } ) - def test_external_case_03(self): + def test_create_room_type_inconsistency_code_companies(self): """ + Create a room type for 1 property and 1 company. + Try to create a room type with same code and 3 propertys + belonging to 2 different companies. + The creation should fail. + PRE: - room type room_type1 exists - room_type1 has code c1 - room_type1 has property pms_property1 @@ -250,7 +274,6 @@ class TestRoomType(TestPms): "class_id": self.room_type_class1.id, } ) - # ACT & ASSERT with self.assertRaises( ValidationError, msg="The room type has been created and it shouldn't" @@ -276,8 +299,12 @@ class TestRoomType(TestPms): } ) - def test_single_case_01(self): + def test_get_room_type_by_property_first(self): """ + Room type exists for all the companies and 2 properties. + Search for property of existing room type. + The method should return the existing room type. + PRE: - room type room_type1 exists - room_type1 has code c1 - room_type1 with 2 properties pms_property1 and pms_property2 @@ -299,50 +326,19 @@ class TestRoomType(TestPms): "class_id": self.room_type_class1.id, } ) - # ACT room_types = self.env["pms.room.type"].get_room_types_by_property( self.pms_property1.id, "c1" ) - # ASSERT self.assertEqual(room_types.id, room_type1.id, "Expected room type not found") - def test_single_case_02(self): + def test_get_room_type_by_property_second(self): """ - PRE: - room type room_type1 exists - - room_type1 has code c1 - - room_type1 with 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 - - room_type1 has no company - ACT: - search room type with code c1 and property pms_property1 - - pms_property1 has company company1 - POST: - only room_type1 room type found - """ - # ARRANGE - room_type1 = self.env["pms.room.type"].create( - { - "name": "Room type 1", - "default_code": "c1", - "pms_property_ids": [ - (6, 0, [self.pms_property1.id, self.pms_property3.id]) - ], - "company_id": False, - "class_id": self.room_type_class1.id, - } - ) + Room type exists for all the companies and 2 properties. + Search for 2nd property of existing room type. + The method should return existing room type. - # ACT - room_types = self.env["pms.room.type"].get_room_types_by_property( - self.pms_property1.id, "c1" - ) - - # ASSERT - self.assertEqual(room_types.id, room_type1.id, "Expected room type not found") - - def test_single_case_03(self): - """ PRE: - room type room_type1 exists - room_type1 has code c1 - room_type1 with 2 properties pms_property1 and pms_property2 @@ -374,8 +370,13 @@ class TestRoomType(TestPms): # ASSERT self.assertFalse(room_types, "Room type found but it should have not found any") - def test_single_case_04(self): + def test_get_room_type_by_property_existing_all_same_company(self): """ + Room type exists for 1 company and for all properties. + Search for one specific property belonging to same company + as the existing room type. + The method should return existing room type. + PRE: - room type r1 exists - room_type1 has code c1 - room_type1 properties are null @@ -394,17 +395,19 @@ class TestRoomType(TestPms): "class_id": self.room_type_class1.id, } ) - # ACT room_types = self.env["pms.room.type"].get_room_types_by_property( self.pms_property1.id, "c1" ) - # ASSERT self.assertEqual(room_types.id, room_type1.id, "Expected room type not found") - def test_single_case_05(self): + def test_get_room_type_by_property_existing_all_diff_company(self): """ + Room type exists for 1 company and all the properties. + Search for property different than existing room type. + The method shouldn't return results. + PRE: - room type room_type1 exists - room_type1 has code c1 - room_type1 properties are null @@ -434,8 +437,13 @@ class TestRoomType(TestPms): self.assertFalse(room_types, "Room type found but it should have not found any") # tests with more than one room type - def test_multiple_case_01(self): + def test_get_room_type_by_property_existing_several_match_prop(self): """ + Room type 1 exists for all companies and 2 properties. + Room type 2 exists for all companies and properties. + Search for same property as one of the 1st room type created. + The method should return the 1st room type created. + PRE: - room type room_type1 exists - room_type1 has code c1 - room_type1 with 2 properties pms_property1 and pms_property2 @@ -480,8 +488,14 @@ class TestRoomType(TestPms): # ASSERT self.assertEqual(room_types.id, room_type1.id, "Expected room type not found") - def test_multiple_case_02(self): + def test_get_room_type_by_property_diff_company(self): """ + Room type 1 exists for all companies and one property. + Room type 2 exists for all companies and properties. + Search for property different than the 1st room type created + and belonging to different company. + The method should return the 2nd room type created. + PRE: - room type r1 exists - room_type1 has code c1 - room_type1 has property pms_property1 @@ -524,8 +538,14 @@ class TestRoomType(TestPms): # ASSERT self.assertEqual(room_types.id, room_type2.id, "Expected room type not found") - def test_multiple_case_03(self): + def test_get_room_type_by_property_same_company(self): """ + Room type 1 exists for all companies and one property. + Room type 2 exists for all companies and properties. + Search for property different than the 1st room type created + and belonging to same company. + The method should return the 2nd room type created. + PRE: - room type room_type1 exists - room_type1 has code c1 - room_type1 has property pms_property1 @@ -568,8 +588,14 @@ class TestRoomType(TestPms): # ASSERT self.assertEqual(room_types.id, room_type2.id, "Expected room type not found") - def test_multiple_case_04(self): + def test_get_room_type_by_property_same_company_prop_not_found(self): """ + Room type 1 exists for all companies and one property. + Room type 2 exists for one company and for all properties. + Search for property different than the + 1st room type created but belonging to same company. + The method shouldn't return results. + PRE: - room_type1 exists - room_type1 has code c1 - room_type1 has property pms_property1 @@ -613,8 +639,14 @@ class TestRoomType(TestPms): # ASSERT self.assertFalse(room_types, "Room type found but it should have not found any") - def test_multiple_case_05(self): + def test_get_room_type_by_property_same_company_prop(self): """ + Room type 1 exists for all companies and for one property. + Room type 2 exists for one company and for all properties. + Search for property belonging to the same company as + 2nd room type created. + The method should return 2nd existing room type. + PRE: - room_type1 exists - room_type1 has code c1 - room_type1 has property pms_property1 @@ -648,7 +680,6 @@ class TestRoomType(TestPms): "class_id": self.room_type_class1.id, } ) - # ACT room_types = self.env["pms.room.type"].get_room_types_by_property( self.pms_property3.id, "c1" @@ -657,8 +688,15 @@ class TestRoomType(TestPms): # ASSERT self.assertEqual(room_types.id, room_type2.id, "Expected room type not found") - def test_multiple_case_06(self): + def test_get_room_type_by_property_diff_company_prop(self): """ + Room type 1 exists for all companies and for one property. + Room type 2 exists for one company and for all properties. + Room type 3 exists for all companies and for all properties. + Search for property belonging to a different company than + the 2nd room type created. + The method should return 3rd room type. + PRE: - room type r1 exists - room_type1 has code c1 - room_type1 has property pms_property1 @@ -715,7 +753,12 @@ class TestRoomType(TestPms): # ASSERT self.assertEqual(room_types.id, room_type3.id, "Expected room type not found") - def test_check_property_room_type_class(self): + def test_rooom_type_creation_inconsistency_class(self): + """ + Create a rooom type class belonging to one property. + Create a room type belonging to another property. + Room type creation should fail. + """ # ARRANGE room_type_class = self.env["pms.room.type.class"].create( { @@ -742,41 +785,72 @@ class TestRoomType(TestPms): ) room_type1.pms_property_ids = [(4, self.pms_property1.id)] - # TODO: pending multi property PR + def test_rooom_type_creation_consistency_class(self): + """ + Create a rooom type class belonging to one property. + Create a room type belonging to same property. + Room type creation should be successful. + """ + # ARRANGE + room_type_class = self.env["pms.room.type.class"].create( + { + "name": "Room Type Class", + "default_code": "ROOM", + "pms_property_ids": [ + (4, self.pms_property2.id), + ], + }, + ) + # ACT + new_room_type = self.env["pms.room.type"].create( + { + "name": "Room Type", + "default_code": "c1", + "class_id": room_type_class.id, + "pms_property_ids": [ + (4, self.pms_property2.id), + ], + } + ) + # ASSERT + self.assertTrue(new_room_type.id, "Room type creation should be successful.") - # def test_check_board_service_property_integrity(self): - # - # self.room_type_class = self.env["pms.room.type.class"].create( - # {"name": "Room Type Class", "default_code": "SIN1"} - # ) - # self.room_type = self.env["pms.room.type"].create( - # { - # "name": "Room Type", - # "default_code": "Type1", - # "pms_property_ids": self.p3, - # "class_id": self.room_type_class.id, - # } - # ) - # self.board_service = self.env["pms.board.service"].create( - # { - # "name": "Board Service", - # } - # ) - # with self.assertRaises(ValidationError): - # self.env["pms.board.service.room.type"].create( - # { - # "pms_board_service_id": self.board_service.id, - # "pms_room_type_id": self.room_type.id, - # "pricelist_id": self.env.ref("product.list0").id, - # "pms_property_ids": self.p4, - # } - # ) + def test_check_board_service_property_integrity(self): + # ARRANGE + room_type = self.env["pms.room.type"].create( + { + "name": "Room Type", + "default_code": "Type1", + "pms_property_ids": self.pms_property1, + "class_id": self.room_type_class1.id, + } + ) + board_service = self.env["pms.board.service"].create( + { + "name": "Board service 1", + "default_code": "c1", + "pms_property_ids": self.pms_property1, + } + ) + # ACT & ASSERT + with self.assertRaises(UserError, msg="Board service created and shouldn't."): + self.env["pms.board.service.room.type"].create( + { + "pms_board_service_id": board_service.id, + "pms_room_type_id": room_type.id, + "pms_property_ids": self.pms_property2, + } + ) def test_check_amenities_property_integrity(self): self.amenity1 = self.env["pms.amenity"].create( {"name": "Amenity", "pms_property_ids": self.pms_property1} ) - with self.assertRaises(UserError): + # ACT & ASSERT + with self.assertRaises( + UserError, + msg="Shouldn't create room type with amenities belonging to other properties", + ): self.env["pms.room.type"].create( { "name": "Room Type", @@ -786,3 +860,26 @@ class TestRoomType(TestPms): "room_amenity_ids": [self.amenity1.id], } ) + + def test_rooom_type_creation_consistency_amenity(self): + """ + Create an amenity belonging to one property. + Create a room type belonging to same property. + Room type creation should be successful. + """ + # ARRANGE + self.amenity1 = self.env["pms.amenity"].create( + {"name": "Amenity", "pms_property_ids": self.pms_property1} + ) + # ACT + new_room_type = self.env["pms.room.type"].create( + { + "name": "Room Type", + "default_code": "Type1", + "class_id": self.room_type_class1.id, + "pms_property_ids": [self.pms_property1.id], + "room_amenity_ids": [self.amenity1.id], + } + ) + # ASSERT + self.assertTrue(new_room_type.id, "Room type creation should be successful.") From 86876407cf2c4c54971b607fb405d3d4097407fb Mon Sep 17 00:00:00 2001 From: miguelpadin Date: Tue, 15 Jun 2021 21:34:35 +0200 Subject: [PATCH 9/9] [ADD] pms: add product.template tests --- pms/tests/__init__.py | 1 + pms/tests/test_product_template.py | 304 +++++++++++++++++++++++++++++ 2 files changed, 305 insertions(+) create mode 100644 pms/tests/test_product_template.py diff --git a/pms/tests/__init__.py b/pms/tests/__init__.py index 48c50bbb2..bc18e0a7a 100644 --- a/pms/tests/__init__.py +++ b/pms/tests/__init__.py @@ -40,3 +40,4 @@ from . import test_pms_board_service_room_type_line from . import test_pms_folio_invoice from . import test_pms_folio_sale_line from . import test_pms_wizard_split_join_swap_reservation +from . import test_product_template diff --git a/pms/tests/test_product_template.py b/pms/tests/test_product_template.py new file mode 100644 index 000000000..b0f49aaf8 --- /dev/null +++ b/pms/tests/test_product_template.py @@ -0,0 +1,304 @@ +import datetime + +from odoo import fields +from odoo.exceptions import ValidationError + +from .common import TestPms + + +class TestProductTemplate(TestPms): + def setUp(self): + super().setUp() + self.room_type = self.env["pms.room.type"].create( + { + "name": "Room type test", + "default_code": "DBL_Test", + "class_id": self.room_type_class1.id, + } + ) + self.room = self.env["pms.room"].create( + { + "pms_property_id": self.pms_property1.id, + "name": "Room test", + "room_type_id": self.room_type.id, + "capacity": 2, + } + ) + self.partner = self.env["res.partner"].create({"name": "partner1"}) + self.board_service = self.env["pms.board.service"].create( + { + "name": "Board service test", + "default_code": "BST", + } + ) + + def test_bs_consumed_on_after(self): + """ + Create a one day reservation with a board service configured to + consume after reservation night. + Date of service line with consumed on 'after' should match checkout date. + """ + # ARRANGE + product = self.env["product.product"].create( + { + "name": "Product test", + "per_day": True, + "consumed_on": "after", + } + ) + self.env["pms.board.service.line"].create( + { + "product_id": product.id, + "pms_board_service_id": self.board_service.id, + } + ) + board_service_room_type = self.env["pms.board.service.room.type"].create( + { + "pms_room_type_id": self.room_type.id, + "pms_board_service_id": self.board_service.id, + } + ) + date_checkin = fields.date.today() + date_checkout = fields.date.today() + datetime.timedelta(days=1) + # ACT + reservation = self.env["pms.reservation"].create( + { + "checkin": date_checkin, + "checkout": date_checkout, + "room_type_id": self.room_type.id, + "pms_property_id": self.pms_property1.id, + "partner_id": self.partner.id, + "board_service_room_id": board_service_room_type.id, + } + ) + # ASSERT + self.assertEqual( + reservation.service_ids.service_line_ids.date, + date_checkout, + "Date of service line with consumed on 'after' should match checkout date.", + ) + + def test_bs_consumed_on_before(self): + """ + Create a one day reservation with a board service configured to + consume before reservation night. + Date of service line with consumed on 'before' should match checkin date. + """ + # ARRANGE + product = self.env["product.product"].create( + { + "name": "Product test", + "per_day": True, + "consumed_on": "before", + } + ) + self.env["pms.board.service.line"].create( + { + "product_id": product.id, + "pms_board_service_id": self.board_service.id, + } + ) + board_service_room_type = self.env["pms.board.service.room.type"].create( + { + "pms_room_type_id": self.room_type.id, + "pms_board_service_id": self.board_service.id, + } + ) + date_checkin = fields.date.today() + date_checkout = fields.date.today() + datetime.timedelta(days=1) + # ACT + reservation = self.env["pms.reservation"].create( + { + "checkin": date_checkin, + "checkout": date_checkout, + "room_type_id": self.room_type.id, + "pms_property_id": self.pms_property1.id, + "partner_id": self.partner.id, + "board_service_room_id": board_service_room_type.id, + } + ) + # ASSERT + self.assertEqual( + reservation.service_ids.service_line_ids.date, + date_checkin, + "Date of service line with consumed on 'before' should match checkin date.", + ) + + def test_bs_daily_limit_equal(self): + """ + Create a one day reservation with a board service configured with + daily limit = 2 and capacity = 2 + Reservation should created succesfully. + """ + # ARRANGE + product = self.env["product.product"].create( + { + "name": "Product test", + "per_day": True, + "daily_limit": 2, + "per_person": True, + } + ) + self.env["pms.board.service.line"].create( + { + "product_id": product.id, + "pms_board_service_id": self.board_service.id, + } + ) + board_service_room_type = self.env["pms.board.service.room.type"].create( + { + "pms_room_type_id": self.room_type.id, + "pms_board_service_id": self.board_service.id, + } + ) + date_checkin = fields.date.today() + date_checkout = fields.date.today() + datetime.timedelta(days=1) + # ACT + reservation = self.env["pms.reservation"].create( + { + "checkin": date_checkin, + "checkout": date_checkout, + "room_type_id": self.room_type.id, + "pms_property_id": self.pms_property1.id, + "partner_id": self.partner.id, + "board_service_room_id": board_service_room_type.id, + } + ) + # ASSERT + self.assertEqual( + reservation.service_ids.service_line_ids.day_qty, + self.room.capacity, + "The reservation should have been created.", + ) + + def test_bs_daily_limit_lower(self): + """ + Create a one day reservation with a board service configured with + daily limit = 2 and capacity = 1 + Reservation should created succesfully. + """ + # ARRANGE + self.room.capacity = 1 + product = self.env["product.product"].create( + { + "name": "Product test", + "per_day": True, + "daily_limit": 2, + "per_person": True, + } + ) + self.env["pms.board.service.line"].create( + { + "product_id": product.id, + "pms_board_service_id": self.board_service.id, + } + ) + board_service_room_type = self.env["pms.board.service.room.type"].create( + { + "pms_room_type_id": self.room_type.id, + "pms_board_service_id": self.board_service.id, + } + ) + date_checkin = fields.date.today() + date_checkout = fields.date.today() + datetime.timedelta(days=1) + # ACT + reservation = self.env["pms.reservation"].create( + { + "checkin": date_checkin, + "checkout": date_checkout, + "room_type_id": self.room_type.id, + "pms_property_id": self.pms_property1.id, + "partner_id": self.partner.id, + "board_service_room_id": board_service_room_type.id, + } + ) + # ASSERT + # self.assertTrue(reservation, "The reservation should have been created.") + # ASSERT + self.assertEqual( + reservation.service_ids.service_line_ids.day_qty, + self.room.capacity, + "The reservation should have been created.", + ) + + def test_bs_daily_limit_greater(self): + """ + Create a one day reservation with a board service configured with + daily limit = 1 and capacity = 2 + Reservation creation should fail. + """ + # ARRANGE + product = self.env["product.product"].create( + { + "name": "Product test", + "per_day": True, + "type": "service", + "daily_limit": 1, + "list_price": 15.0, + "per_person": True, + } + ) + self.env["pms.board.service.line"].create( + { + "product_id": product.id, + "pms_board_service_id": self.board_service.id, + } + ) + board_service_room_type = self.env["pms.board.service.room.type"].create( + { + "pms_room_type_id": self.room_type.id, + "pms_board_service_id": self.board_service.id, + } + ) + date_checkin = fields.date.today() + date_checkout = fields.date.today() + datetime.timedelta(days=1) + # ACT & ASSERT + with self.assertRaises( + ValidationError, msg="Reservation created but it shouldn't" + ): + self.env["pms.reservation"].create( + { + "checkin": date_checkin, + "checkout": date_checkout, + "room_type_id": self.room_type.id, + "pms_property_id": self.pms_property1.id, + "partner_id": self.partner.id, + "board_service_room_id": board_service_room_type.id, + "adults": 2, + } + ) + + # TODO: Review this test + def _test_bs_is_extra_bed(self): + # ARRANGE + product = self.env["product.product"].create( + { + "name": "Product test", + "per_day": True, + "consumed_on": "after", + "is_extra_bed": True, + } + ) + self.room.capacity = 1 + extra_bed_service = self.env["pms.service"].create( + { + "is_board_service": False, + "product_id": product.id, + } + ) + self.room.extra_beds_allowed = 1 + # ACT + reservation = self.env["pms.reservation"].create( + { + "checkin": fields.date.today(), + "checkout": fields.date.today() + datetime.timedelta(days=1), + "room_type_id": self.room_type.id, + "pms_property_id": self.pms_property1.id, + "partner_id": self.partner.id, + "service_ids": [extra_bed_service.id], + } + ) + reservation._check_adults() + reservation.flush() + + # TODO: pending tests (need review) -> per_day, per_person (with board service?)