diff --git a/pms/tests/__init__.py b/pms/tests/__init__.py index bc18e0a7a..fa95794df 100644 --- a/pms/tests/__init__.py +++ b/pms/tests/__init__.py @@ -21,7 +21,6 @@ ############################################################################## 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 diff --git a/pms/tests/test_pms_pricelist.py b/pms/tests/test_pms_pricelist.py index 7e04d8386..8a1131a7a 100644 --- a/pms/tests/test_pms_pricelist.py +++ b/pms/tests/test_pms_pricelist.py @@ -4,80 +4,37 @@ from freezegun import freeze_time from odoo import fields from odoo.exceptions import UserError, ValidationError -from odoo.tests import common, tagged +from odoo.tests import tagged + +from .common import TestPms @tagged("standard", "nice") -class TestPmsPricelist(common.SavepointCase): - def create_common_scenario(self): - # 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, - } - ) - # create property - self.property1 = self.env["pms.property"].create( - { - "name": "Property_1", - "company_id": self.env.ref("base.main_company").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( +class TestPmsPricelist(TestPms): + def setUp(self): + super().setUp() + self.pms_property2 = self.env["pms.property"].create( { "name": "Property_2", "company_id": self.env.ref("base.main_company").id, "default_pricelist_id": self.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.property3 = self.env["pms.property"].create( + self.pms_property3 = self.env["pms.property"].create( { "name": "Property_3", "company_id": self.env.ref("base.main_company").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_class = self.env["pms.room.type.class"].create( - {"name": "Room Class", "default_code": "ROOM"} - ) - self.room_type = self.env["pms.room.type"].create( + self.room_type1 = self.env["pms.room.type"].create( { - "pms_property_ids": [self.property1.id, self.property2.id], + "pms_property_ids": [self.pms_property1.id, self.pms_property2.id], "name": "Single", "default_code": "SIN", - "class_id": self.room_type_class.id, + "class_id": self.room_type_class1.id, "list_price": 30, } ) @@ -85,135 +42,83 @@ class TestPmsPricelist(common.SavepointCase): # pms.room self.room1 = self.env["pms.room"].create( { - "pms_property_id": self.property1.id, + "pms_property_id": self.pms_property1.id, "name": "Single 101", - "room_type_id": self.room_type.id, + "room_type_id": self.room_type1.id, "capacity": 2, } ) - self.pricelist = self.env["product.pricelist"].create( + self.pricelist2 = self.env["product.pricelist"].create( { - "name": "pricelist_1", - "pms_property_ids": [self.property1.id, self.property2.id], + "name": "pricelist_2", + "pms_property_ids": [self.pms_property1.id, self.pms_property2.id], } ) # product.product 1 - self.test_service_breakfast = self.env["product.product"].create( - {"name": "Test Breakfast"} - ) + self.product1 = self.env["product.product"].create({"name": "Test Breakfast"}) # pms.board.service - self.test_board_service_only_breakfast = self.env["pms.board.service"].create( + self.board_service1 = self.env["pms.board.service"].create( { "name": "Test Only Breakfast", "default_code": "CB1", } ) # pms.board.service.line - self.board_service_line_single_1 = self.env["pms.board.service.line"].create( + self.board_service_line1 = 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, + "product_id": self.product1.id, + "pms_board_service_id": self.board_service1.id, } ) # pms.board.service.room.type - self.test_board_service_single = self.env["pms.board.service.room.type"].create( + self.board_service_room_type1 = self.env["pms.board.service.room.type"].create( { - "pms_room_type_id": self.room_type.id, - "pms_board_service_id": self.test_board_service_only_breakfast.id, + "pms_room_type_id": self.room_type1.id, + "pms_board_service_id": self.board_service1.id, } ) self.partner1 = self.env["res.partner"].create({"name": "Carles"}) - def test_advanced_pricelist_exists(self): - + def test_inconsistency_property_pricelist_item(self): + """ + Check a pricelist item and its pricelist are inconsistent with the property. + Create a pricelist item that belongs to a property and check if + a pricelist that belongs to a diferent one, cannot be created. + """ # ARRANGE - key = "product.product_pricelist_setting" - value = "advanced" - - # ACT - found_value = self.env["ir.config_parameter"].sudo().get_param(key) - - # ASSERT - self.assertEqual(found_value, value, "Parameter doesn't exist") - - def test_product_pricelist_setting_modified(self): - - # ARRANGE - key = "product.product_pricelist_setting" - value = "basic" - - # ACT & ASSERT - with self.assertRaises(ValidationError), self.cr.savepoint(): - self.env["ir.config_parameter"].set_param(key, value) - - def test_product_pricelist_setting_unlink(self): - - # ARRANGE - key = "product.product_pricelist_setting" - value = "advanced" - - # ACT & ASSERT - with self.assertRaises(ValidationError), self.cr.savepoint(): - self.env["ir.config_parameter"].search( - [("key", "=", key), ("value", "=", value)] - ).unlink() - - def test_check_property_pricelist(self): - # ARRANGE - self.create_common_scenario() # ACT & ASSERT with self.assertRaises(UserError): self.item1 = self.env["product.pricelist.item"].create( { "name": "item_1", "applied_on": "0_product_variant", - "product_id": self.room_type.product_id.id, + "product_id": self.room_type1.product_id.id, "date_start": datetime.datetime.today(), "date_end": datetime.datetime.today() + datetime.timedelta(days=1), "fixed_price": 40.0, - "pricelist_id": self.pricelist.id, - "pms_property_ids": [self.property3.id], + "pricelist_id": self.pricelist2.id, + "pms_property_ids": [self.pms_property3.id], } ) - def test_check_property_room_type(self): + def test_inconsistency_cancelation_rule_property(self): + """ + Check a cancelation rule and its pricelist are inconsistent with the property. + Create a cancelation rule that belongs to a two properties and check if + a pricelist that belongs to a diferent properties, cannot be created. + """ # ARRANGE - self.create_common_scenario() - # ACT - self.pricelist1 = self.env["product.pricelist"].create( - { - "name": "pricelist_1", - "pms_property_ids": [self.property1.id, self.property3.id], - } - ) - # ASSERT - with self.assertRaises(UserError): - self.item1 = self.env["product.pricelist.item"].create( - { - "name": "item_1", - "applied_on": "0_product_variant", - "product_id": self.room_type.product_id.id, - "date_start": datetime.datetime.today(), - "date_end": datetime.datetime.today() + datetime.timedelta(days=1), - "fixed_price": 40.0, - "pricelist_id": self.pricelist1.id, - "pms_property_ids": [self.property3.id], - } - ) - def test_cancelation_rule_property(self): - # ARRANGE - self.create_common_scenario() Pricelist = self.env["product.pricelist"] # ACT self.cancelation_rule = self.env["pms.cancelation.rule"].create( { "name": "Cancelation Rule Test", - "pms_property_ids": [self.property1.id, self.property3.id], + "pms_property_ids": [self.pms_property1.id, self.pms_property3.id], } ) # ASSERT @@ -221,39 +126,42 @@ class TestPmsPricelist(common.SavepointCase): Pricelist.create( { "name": "Pricelist Test", - "pms_property_ids": [self.property1.id, self.property2.id], + "pms_property_ids": [self.pms_property1.id, self.pms_property2.id], "cancelation_rule_id": self.cancelation_rule.id, } ) - def test_availability_plan_property_integrity(self): - self.create_common_scenario() + def test_inconsistency_availability_plan_property(self): + """ + Check a availability plan and its pricelist are inconsistent with the property. + Create a availability plan that belongs to a two properties and check if + a pricelist that belongs to a diferent properties, cannot be created. + """ self.availability_plan = self.env["pms.availability.plan"].create( - {"name": "Availability Plan", "pms_property_ids": [self.property1.id]} + {"name": "Availability Plan", "pms_property_ids": [self.pms_property1.id]} ) with self.assertRaises(UserError): self.env["product.pricelist"].create( { "name": "Pricelist", - "pms_property_ids": [self.property2.id], + "pms_property_ids": [self.pms_property2.id], "availability_plan_id": self.availability_plan.id, } ) - # board services pricelist items + @freeze_time("2000-01-01") def test_board_service_pricelist_item_apply_sale_dates(self): - # TEST CASE - # Pricelist item is created to apply on board services at SALE date. - # The reservation created take into account the board service - # pricelist item created previously according to the SALE date. - + """ + Pricelist item is created to apply on board services at SALE date. + The reservation created take into account the board service + pricelist item created previously according to the SALE date. + """ # ARRANGE - self.create_common_scenario() date_from = fields.date.today() date_to = fields.date.today() expected_price = 1000.0 vals = { - "pricelist_id": self.pricelist.id, + "pricelist_id": self.pricelist2.id, "date_start": datetime.datetime.combine( date_from, datetime.datetime.min.time() ), @@ -262,10 +170,10 @@ class TestPmsPricelist(common.SavepointCase): ), "compute_price": "fixed", "applied_on": "0_product_variant", - "product_id": self.test_service_breakfast.id, - "board_service_room_type_id": self.test_board_service_single.id, + "product_id": self.product1.id, + "board_service_room_type_id": self.board_service_room_type1.id, "fixed_price": expected_price, - "pms_property_ids": [self.property1.id], + "pms_property_ids": [self.pms_property1.id], } self.env["product.pricelist.item"].create(vals) # ACT @@ -275,9 +183,9 @@ class TestPmsPricelist(common.SavepointCase): "checkin": datetime.datetime.now(), "checkout": datetime.datetime.now() + datetime.timedelta(days=1), "preferred_room_id": self.room1.id, - "pms_property_id": self.property1.id, - "pricelist_id": self.pricelist.id, - "board_service_room_id": self.test_board_service_single.id, + "pms_property_id": self.pms_property1.id, + "pricelist_id": self.pricelist2.id, + "board_service_room_id": self.board_service_room_type1.id, } ) # ASSERT @@ -288,19 +196,19 @@ class TestPmsPricelist(common.SavepointCase): " pricelist item created previously according to the SALE date.", ) + @freeze_time("2000-01-01") def test_board_service_pricelist_item_not_apply_sale_dates(self): - # TEST CASE - # Pricelist item is created to apply on board services at SALE date. - # The reservation created DONT take into account the board service pricelist - # item created previously according to the SALE date. - + """ + Pricelist item is created to apply on board services at SALE date. + The reservation created DONT take into account the board service pricelist + item created previously according to the SALE date. + """ # ARRANGE - self.create_common_scenario() date_from = fields.date.today() + datetime.timedelta(days=1) date_to = fields.date.today() + datetime.timedelta(days=1) not_expected_price = 1000.0 vals = { - "pricelist_id": self.pricelist.id, + "pricelist_id": self.pricelist2.id, "date_start": datetime.datetime.combine( date_from, datetime.datetime.min.time() ), @@ -309,10 +217,10 @@ class TestPmsPricelist(common.SavepointCase): ), "compute_price": "fixed", "applied_on": "0_product_variant", - "product_id": self.test_service_breakfast.id, - "board_service_room_type_id": self.test_board_service_single.id, + "product_id": self.product1.id, + "board_service_room_type_id": self.board_service_room_type1.id, "fixed_price": not_expected_price, - "pms_property_ids": [self.property1.id], + "pms_property_ids": [self.pms_property1.id], } self.env["product.pricelist.item"].create(vals) # ACT @@ -322,9 +230,9 @@ class TestPmsPricelist(common.SavepointCase): "checkin": datetime.datetime.now(), "checkout": datetime.datetime.now() + datetime.timedelta(days=1), "preferred_room_id": self.room1.id, - "pms_property_id": self.property1.id, - "pricelist_id": self.pricelist.id, - "board_service_room_id": self.test_board_service_single.id, + "pms_property_id": self.pms_property1.id, + "pricelist_id": self.pricelist2.id, + "board_service_room_id": self.board_service_room_type1.id, } ) # ASSERT @@ -335,28 +243,28 @@ class TestPmsPricelist(common.SavepointCase): " item created previously according to the SALE date.", ) + @freeze_time("2000-01-01") def test_board_service_pricelist_item_apply_consumption_dates(self): - # TEST CASE - # Pricelist item is created to apply on board services - # at CONSUMPTION date. - # The reservation created take into account the board service - # pricelist item created previously according to the CONSUMPTION date. - + """ + Pricelist item is created to apply on board services + at CONSUMPTION date. + The reservation created take into account the board service + pricelist item created previously according to the CONSUMPTION date. + """ # ARRANGE - self.create_common_scenario() date_from = fields.date.today() + datetime.timedelta(days=1) date_to = fields.date.today() + datetime.timedelta(days=1) expected_price = 1000.0 vals = { - "pricelist_id": self.pricelist.id, + "pricelist_id": self.pricelist2.id, "date_start_consumption": date_from, "date_end_consumption": date_to, "compute_price": "fixed", "applied_on": "0_product_variant", - "product_id": self.test_service_breakfast.id, - "board_service_room_type_id": self.test_board_service_single.id, + "product_id": self.product1.id, + "board_service_room_type_id": self.board_service_room_type1.id, "fixed_price": expected_price, - "pms_property_ids": [self.property1.id], + "pms_property_ids": [self.pms_property1.id], } self.env["product.pricelist.item"].create(vals) # ACT @@ -366,9 +274,9 @@ class TestPmsPricelist(common.SavepointCase): "checkin": datetime.datetime.now() + datetime.timedelta(days=1), "checkout": datetime.datetime.now() + datetime.timedelta(days=2), "preferred_room_id": self.room1.id, - "pms_property_id": self.property1.id, - "pricelist_id": self.pricelist.id, - "board_service_room_id": self.test_board_service_single.id, + "pms_property_id": self.pms_property1.id, + "pricelist_id": self.pricelist2.id, + "board_service_room_id": self.board_service_room_type1.id, } ) # ASSERT @@ -379,20 +287,20 @@ class TestPmsPricelist(common.SavepointCase): " pricelist item created previously according to the CONSUMPTION date.", ) + @freeze_time("2000-01-01") def test_board_service_pricelist_item_not_apply_consumption_dates(self): - # TEST CASE - # Pricelist item is created to apply on board services - # at CONSUMPTION date. - # The reservation created DONT take into account the board service - # pricelist item created previously according to the CONSUMPTION date. - + """ + Pricelist item is created to apply on board services + at CONSUMPTION date. + The reservation created DONT take into account the board service + pricelist item created previously according to the CONSUMPTION date. + """ # ARRANGE - self.create_common_scenario() date_from = fields.date.today() + datetime.timedelta(days=2) date_to = fields.date.today() + datetime.timedelta(days=2) not_expected_price = 1000.0 vals = { - "pricelist_id": self.pricelist.id, + "pricelist_id": self.pricelist2.id, "date_start": datetime.datetime.combine( date_from, datetime.datetime.min.time() ), @@ -401,10 +309,10 @@ class TestPmsPricelist(common.SavepointCase): ), "compute_price": "fixed", "applied_on": "0_product_variant", - "product_id": self.test_service_breakfast.id, - "board_service_room_type_id": self.test_board_service_single.id, + "product_id": self.product1.id, + "board_service_room_type_id": self.board_service_room_type1.id, "fixed_price": not_expected_price, - "pms_property_ids": [self.property1.id], + "pms_property_ids": [self.pms_property1.id], } self.env["product.pricelist.item"].create(vals) # ACT @@ -414,9 +322,9 @@ class TestPmsPricelist(common.SavepointCase): "checkin": datetime.datetime.now(), "checkout": datetime.datetime.now() + datetime.timedelta(days=1), "preferred_room_id": self.room1.id, - "pms_property_id": self.property1.id, - "pricelist_id": self.pricelist.id, - "board_service_room_id": self.test_board_service_single.id, + "pms_property_id": self.pms_property1.id, + "pricelist_id": self.pricelist2.id, + "board_service_room_id": self.board_service_room_type1.id, } ) # ASSERT @@ -427,21 +335,20 @@ class TestPmsPricelist(common.SavepointCase): " pricelist item created previously according to the CONSUMPTION date.", ) - # room types pricelist items + @freeze_time("2000-01-01") def test_room_type_pricelist_item_apply_sale_dates(self): - # TEST CASE - # Pricelist item is created to apply on room types - # at SALE date. - # The reservation created take into account the room type - # pricelist item created previously according to the SALE date. - + """ + Pricelist item is created to apply on room types + at SALE date. + The reservation created take into account the room type + pricelist item created previously according to the SALE date. + """ # ARRANGE - self.create_common_scenario() date_from = fields.date.today() date_to = fields.date.today() expected_price = 1000.0 vals = { - "pricelist_id": self.pricelist.id, + "pricelist_id": self.pricelist2.id, "date_start": datetime.datetime.combine( date_from, datetime.datetime.min.time() ), @@ -450,9 +357,9 @@ class TestPmsPricelist(common.SavepointCase): ), "compute_price": "fixed", "applied_on": "0_product_variant", - "product_id": self.room_type.product_id.id, + "product_id": self.room_type1.product_id.id, "fixed_price": expected_price, - "pms_property_ids": [self.property1.id], + "pms_property_ids": [self.pms_property1.id], } self.env["product.pricelist.item"].create(vals) # ACT @@ -462,8 +369,8 @@ class TestPmsPricelist(common.SavepointCase): "checkin": datetime.datetime.now(), "checkout": datetime.datetime.now() + datetime.timedelta(days=1), "preferred_room_id": self.room1.id, - "pms_property_id": self.property1.id, - "pricelist_id": self.pricelist.id, + "pms_property_id": self.pms_property1.id, + "pricelist_id": self.pricelist2.id, } ) # ASSERT @@ -474,20 +381,20 @@ class TestPmsPricelist(common.SavepointCase): " pricelist item created previously according to the SALE date.", ) + @freeze_time("2000-01-01") def test_room_type_pricelist_item_not_apply_sale_dates(self): - # TEST CASE - # Pricelist item is created to apply on room types - # at SALE date. - # The reservation created DONT take into account the room type - # pricelist item created previously according to the SALE date. - + """ + Pricelist item is created to apply on room types + at SALE date. + The reservation created DONT take into account the room type + pricelist item created previously according to the SALE date. + """ # ARRANGE - self.create_common_scenario() date_from = fields.date.today() + datetime.timedelta(days=1) date_to = fields.date.today() + datetime.timedelta(days=1) not_expected_price = 1000.0 vals = { - "pricelist_id": self.pricelist.id, + "pricelist_id": self.pricelist2.id, "date_start": datetime.datetime.combine( date_from, datetime.datetime.min.time() ), @@ -496,9 +403,9 @@ class TestPmsPricelist(common.SavepointCase): ), "compute_price": "fixed", "applied_on": "0_product_variant", - "product_id": self.room_type.product_id.id, + "product_id": self.room_type1.product_id.id, "fixed_price": not_expected_price, - "pms_property_ids": [self.property1.id], + "pms_property_ids": [self.pms_property1.id], } self.env["product.pricelist.item"].create(vals) # ACT @@ -508,8 +415,8 @@ class TestPmsPricelist(common.SavepointCase): "checkin": datetime.datetime.now(), "checkout": datetime.datetime.now() + datetime.timedelta(days=1), "preferred_room_id": self.room1.id, - "pms_property_id": self.property1.id, - "pricelist_id": self.pricelist.id, + "pms_property_id": self.pms_property1.id, + "pricelist_id": self.pricelist2.id, } ) # ASSERT @@ -520,27 +427,27 @@ class TestPmsPricelist(common.SavepointCase): " pricelist item created previously according to the SALE date.", ) + @freeze_time("2000-01-01") def test_room_type_pricelist_item_apply_consumption_dates(self): - # TEST CASE - # Pricelist item is created to apply on room types - # at CONSUMPTION date. - # The reservation created take into account the room type - # pricelist item created previously according to the CONSUMPTION date. - + """ + Pricelist item is created to apply on room types + at CONSUMPTION date. + The reservation created take into account the room type + pricelist item created previously according to the CONSUMPTION date. + """ # ARRANGE - self.create_common_scenario() date_from = fields.date.today() + datetime.timedelta(days=1) date_to = fields.date.today() + datetime.timedelta(days=1) expected_price = 1000.0 vals = { - "pricelist_id": self.pricelist.id, + "pricelist_id": self.pricelist2.id, "date_start_consumption": date_from, "date_end_consumption": date_to, "compute_price": "fixed", "applied_on": "0_product_variant", - "product_id": self.room_type.product_id.id, + "product_id": self.room_type1.product_id.id, "fixed_price": expected_price, - "pms_property_ids": [self.property1.id], + "pms_property_ids": [self.pms_property1.id], } self.env["product.pricelist.item"].create(vals) # ACT @@ -550,8 +457,8 @@ class TestPmsPricelist(common.SavepointCase): "checkin": datetime.datetime.now() + datetime.timedelta(days=1), "checkout": datetime.datetime.now() + datetime.timedelta(days=2), "preferred_room_id": self.room1.id, - "pms_property_id": self.property1.id, - "pricelist_id": self.pricelist.id, + "pms_property_id": self.pms_property1.id, + "pricelist_id": self.pricelist2.id, } ) # ASSERT @@ -562,20 +469,20 @@ class TestPmsPricelist(common.SavepointCase): " pricelist item created previously according to the CONSUMPTION date.", ) + @freeze_time("2000-01-01") def test_room_type_pricelist_item_not_apply_consumption_dates(self): - # TEST CASE - # Pricelist item is created to apply on room types - # at CONSUMPTION date. - # The reservation created DONT take into account the room type - # pricelist item created previously according to the CONSUMPTION date. - + """ + Pricelist item is created to apply on room types + at CONSUMPTION date. + The reservation created DONT take into account the room type + pricelist item created previously according to the CONSUMPTION date. + """ # ARRANGE - self.create_common_scenario() date_from = fields.date.today() + datetime.timedelta(days=2) date_to = fields.date.today() + datetime.timedelta(days=2) not_expected_price = 1000.0 vals = { - "pricelist_id": self.pricelist.id, + "pricelist_id": self.pricelist2.id, "date_start": datetime.datetime.combine( date_from, datetime.datetime.min.time() ), @@ -584,9 +491,9 @@ class TestPmsPricelist(common.SavepointCase): ), "compute_price": "fixed", "applied_on": "0_product_variant", - "product_id": self.room_type.product_id.id, + "product_id": self.room_type1.product_id.id, "fixed_price": not_expected_price, - "pms_property_ids": [self.property1.id], + "pms_property_ids": [self.pms_property1.id], } self.env["product.pricelist.item"].create(vals) # ACT @@ -596,8 +503,8 @@ class TestPmsPricelist(common.SavepointCase): "checkin": datetime.datetime.now(), "checkout": datetime.datetime.now() + datetime.timedelta(days=1), "preferred_room_id": self.room1.id, - "pms_property_id": self.property1.id, - "pricelist_id": self.pricelist.id, + "pms_property_id": self.pms_property1.id, + "pricelist_id": self.pricelist2.id, } ) # ASSERT @@ -608,20 +515,19 @@ class TestPmsPricelist(common.SavepointCase): " pricelist item created previously according to the CONSUMPTION date.", ) - # services pricelist items + @freeze_time("2000-01-01") def test_service_pricelist_item_apply_sale_dates(self): - # TEST CASE - # Pricelist item is created to apply on services at SALE date. - # The reservation created take into account the service - # pricelist item created previously according to the SALE date. - + """ + Pricelist item is created to apply on services at SALE date. + The reservation created take into account the service + pricelist item created previously according to the SALE date. + """ # ARRANGE - self.create_common_scenario() date_from = fields.date.today() date_to = fields.date.today() expected_price = 1000.0 vals = { - "pricelist_id": self.pricelist.id, + "pricelist_id": self.pricelist2.id, "date_start": datetime.datetime.combine( date_from, datetime.datetime.min.time() ), @@ -630,9 +536,9 @@ class TestPmsPricelist(common.SavepointCase): ), "compute_price": "fixed", "applied_on": "0_product_variant", - "product_id": self.test_service_breakfast.id, + "product_id": self.product1.id, "fixed_price": expected_price, - "pms_property_ids": [self.property1.id], + "pms_property_ids": [self.pms_property1.id], } self.env["product.pricelist.item"].create(vals) # ACT @@ -642,9 +548,9 @@ class TestPmsPricelist(common.SavepointCase): "checkin": datetime.datetime.now(), "checkout": datetime.datetime.now() + datetime.timedelta(days=1), "preferred_room_id": self.room1.id, - "pms_property_id": self.property1.id, - "pricelist_id": self.pricelist.id, - "service_ids": [(0, 0, {"product_id": self.test_service_breakfast.id})], + "pms_property_id": self.pms_property1.id, + "pricelist_id": self.pricelist2.id, + "service_ids": [(0, 0, {"product_id": self.product1.id})], } ) # ASSERT @@ -655,19 +561,19 @@ class TestPmsPricelist(common.SavepointCase): " pricelist item created previously according to the SALE date.", ) + @freeze_time("2000-01-01") def test_service_pricelist_item_not_apply_sale_dates(self): - # TEST CASE - # Pricelist item is created to apply on services at SALE date. - # The reservation created DONT take into account the service pricelist - # item created previously according to the SALE date. - + """ + Pricelist item is created to apply on services at SALE date. + The reservation created DONT take into account the service pricelist + item created previously according to the SALE date. + """ # ARRANGE - self.create_common_scenario() date_from = fields.date.today() + datetime.timedelta(days=1) date_to = fields.date.today() + datetime.timedelta(days=1) not_expected_price = 1000.0 vals = { - "pricelist_id": self.pricelist.id, + "pricelist_id": self.pricelist2.id, "date_start": datetime.datetime.combine( date_from, datetime.datetime.min.time() ), @@ -676,9 +582,9 @@ class TestPmsPricelist(common.SavepointCase): ), "compute_price": "fixed", "applied_on": "0_product_variant", - "product_id": self.test_service_breakfast.id, + "product_id": self.product1.id, "fixed_price": not_expected_price, - "pms_property_ids": [self.property1.id], + "pms_property_ids": [self.pms_property1.id], } self.env["product.pricelist.item"].create(vals) # ACT @@ -688,9 +594,9 @@ class TestPmsPricelist(common.SavepointCase): "checkin": datetime.datetime.now(), "checkout": datetime.datetime.now() + datetime.timedelta(days=1), "preferred_room_id": self.room1.id, - "pms_property_id": self.property1.id, - "pricelist_id": self.pricelist.id, - "service_ids": [(0, 0, {"product_id": self.test_service_breakfast.id})], + "pms_property_id": self.pms_property1.id, + "pricelist_id": self.pricelist2.id, + "service_ids": [(0, 0, {"product_id": self.product1.id})], } ) # ASSERT @@ -701,26 +607,26 @@ class TestPmsPricelist(common.SavepointCase): " item created previously according to the SALE date.", ) + @freeze_time("2000-01-01") def test_service_pricelist_item_apply_consumption_dates(self): - # TEST CASE - # Pricelist item is created to apply on services at CONSUMPTION date. - # The reservation created take into account the service - # pricelist item created previously according to the CONSUMPTION date. - + """ + Pricelist item is created to apply on services at CONSUMPTION date. + The reservation created take into account the service + pricelist item created previously according to the CONSUMPTION date. + """ # ARRANGE - self.create_common_scenario() date_from = fields.date.today() + datetime.timedelta(days=1) date_to = fields.date.today() + datetime.timedelta(days=1) expected_price = 1000.0 vals = { - "pricelist_id": self.pricelist.id, + "pricelist_id": self.pricelist2.id, "date_start_consumption": date_from, "date_end_consumption": date_to, "compute_price": "fixed", "applied_on": "0_product_variant", - "product_id": self.test_service_breakfast.id, + "product_id": self.product1.id, "fixed_price": expected_price, - "pms_property_ids": [self.property1.id], + "pms_property_ids": [self.pms_property1.id], } self.env["product.pricelist.item"].create(vals) # ACT @@ -730,9 +636,9 @@ class TestPmsPricelist(common.SavepointCase): "checkin": datetime.datetime.now() + datetime.timedelta(days=1), "checkout": datetime.datetime.now() + datetime.timedelta(days=2), "preferred_room_id": self.room1.id, - "pms_property_id": self.property1.id, - "pricelist_id": self.pricelist.id, - "service_ids": [(0, 0, {"product_id": self.test_service_breakfast.id})], + "pms_property_id": self.pms_property1.id, + "pricelist_id": self.pricelist2.id, + "service_ids": [(0, 0, {"product_id": self.product1.id})], } ) # ASSERT @@ -743,19 +649,19 @@ class TestPmsPricelist(common.SavepointCase): " pricelist item created previously according to the CONSUMPTION date.", ) + @freeze_time("2000-01-01") def test_service_pricelist_item_not_apply_consumption_dates(self): - # TEST CASE - # Pricelist item is created to apply on services at CONSUMPTION date. - # The reservation created DONT take into account the service pricelist - # item created previously according to the CONSUMPTION date. - + """ + Pricelist item is created to apply on services at CONSUMPTION date. + The reservation created DONT take into account the service pricelist + item created previously according to the CONSUMPTION date. + """ # ARRANGE - self.create_common_scenario() date_from = fields.date.today() + datetime.timedelta(days=2) date_to = fields.date.today() + datetime.timedelta(days=2) not_expected_price = 1000.0 vals = { - "pricelist_id": self.pricelist.id, + "pricelist_id": self.pricelist2.id, "date_start": datetime.datetime.combine( date_from, datetime.datetime.min.time() ), @@ -764,9 +670,9 @@ class TestPmsPricelist(common.SavepointCase): ), "compute_price": "fixed", "applied_on": "0_product_variant", - "product_id": self.test_service_breakfast.id, + "product_id": self.product1.id, "fixed_price": not_expected_price, - "pms_property_ids": [self.property1.id], + "pms_property_ids": [self.pms_property1.id], } self.env["product.pricelist.item"].create(vals) # ACT @@ -776,9 +682,9 @@ class TestPmsPricelist(common.SavepointCase): "checkin": datetime.datetime.now(), "checkout": datetime.datetime.now() + datetime.timedelta(days=1), "preferred_room_id": self.room1.id, - "pms_property_id": self.property1.id, - "pricelist_id": self.pricelist.id, - "service_ids": [(0, 0, {"product_id": self.test_service_breakfast.id})], + "pms_property_id": self.pms_property1.id, + "pricelist_id": self.pricelist2.id, + "service_ids": [(0, 0, {"product_id": self.product1.id})], } ) # ASSERT @@ -790,12 +696,30 @@ class TestPmsPricelist(common.SavepointCase): ) @freeze_time("2000-01-01") - def test_pricelist_daily_failed(self): - self.create_common_scenario() + def test_inconsistencies_pricelist_daily(self): + """ + Test cases to verify that a daily pricelist cannot be created because: + (Test case1): item has two properties and a items daily pricelist only + can has a one property. + (Test case2): item has all properties(pms_property_ids = False indicates + all properties)and a items daily pricelist only can has a one property. + (Test case3): item compute_price is 'percentage' and only can be 'fixed' + for items daily pricelist. + (Test case4): item compute_price is 'percentage' and has two properties + but compute_price can only be fixed and can only have one + property for items daily pricelist. + (Test case5): item compute_price is 'percentage' and has all properties + (pms_property_ids = False indicates all properties)but + compute_pricecan only be fixed and can only have one property for + items daily pricelist. + (Test case6): The difference of days between date_start_consumption and + date_end_consumption is three and the items of a daily pricelist + can only be one. + """ test_cases = [ { "compute_price": "fixed", - "pms_property_ids": [self.property1.id, self.property2.id], + "pms_property_ids": [self.pms_property1.id, self.pms_property2.id], "date_start_consumption": datetime.datetime.now(), "date_end_consumption": datetime.datetime.today() + datetime.timedelta(days=1), @@ -809,14 +733,14 @@ class TestPmsPricelist(common.SavepointCase): }, { "compute_price": "percentage", - "pms_property_ids": [self.property1.id], + "pms_property_ids": [self.pms_property1.id], "date_start_consumption": datetime.datetime.now(), "date_end_consumption": datetime.datetime.today() + datetime.timedelta(days=1), }, { "compute_price": "percentage", - "pms_property_ids": [self.property1.id, self.property2.id], + "pms_property_ids": [self.pms_property1.id, self.pms_property2.id], "date_start_consumption": datetime.datetime.now(), "date_end_consumption": datetime.datetime.today() + datetime.timedelta(days=1), @@ -830,7 +754,7 @@ class TestPmsPricelist(common.SavepointCase): }, { "compute_price": "fixed", - "pms_property_ids": [self.property1.id], + "pms_property_ids": [self.pms_property1.id], "date_start_consumption": datetime.datetime.now(), "date_end_consumption": datetime.datetime.today() + datetime.timedelta(days=3), @@ -839,14 +763,19 @@ class TestPmsPricelist(common.SavepointCase): for tc in test_cases: with self.subTest(k=tc): - with self.assertRaises(ValidationError): - self.room_type.pms_property_ids = tc["pms_property_ids"] + with self.assertRaises( + ValidationError, + msg="Item only can has one property, the compute price only can" + "be fixed and the difference between date_start_consumption" + "and date_end_consumption only can be 1", + ): + self.room_type1.pms_property_ids = tc["pms_property_ids"] item = self.env["product.pricelist.item"].create( { "pms_property_ids": tc["pms_property_ids"], "compute_price": tc["compute_price"], "applied_on": "0_product_variant", - "product_id": self.room_type.product_id.id, + "product_id": self.room_type1.product_id.id, "date_start_consumption": tc["date_start_consumption"], "date_end_consumption": tc["date_end_consumption"], } @@ -861,15 +790,19 @@ class TestPmsPricelist(common.SavepointCase): ) @freeze_time("2020-01-01") - def test_pricelist_daily(self): - self.create_common_scenario() - self.room_type.pms_property_ids = (self.property1.id,) + def test_consistency_pricelist_daily(self): + """ + Test to verify that a daily pricelist is created. + Create a pricelist item with a property, the value of compute_price is + fixed and date_start_consumption date_end_consumption has the same value + """ + self.room_type1.pms_property_ids = (self.pms_property1.id,) item = self.env["product.pricelist.item"].create( { - "pms_property_ids": [self.property1.id], + "pms_property_ids": [self.pms_property1.id], "compute_price": "fixed", "applied_on": "0_product_variant", - "product_id": self.room_type.product_id.id, + "product_id": self.room_type1.product_id.id, "date_start_consumption": datetime.date.today(), "date_end_consumption": datetime.date.today(), } @@ -878,8 +811,496 @@ class TestPmsPricelist(common.SavepointCase): { "name": "Pricelist test", "pricelist_type": "daily", - "pms_property_ids": [self.property1.id], + "pms_property_ids": [self.pms_property1.id], "item_ids": [item.id], } ) self.assertTrue(self.pricelist_test, "Pricelist not created.") + + @freeze_time("2000-01-01") + def test_simple_price_without_items(self): + """ + Test case for no items applied in a reservation. + """ + + # ARRANGE + self.room_type = self.env["pms.room.type"].create( + { + "pms_property_ids": [self.pms_property1.id, self.pms_property2.id], + "name": "Single", + "default_code": "S", + "class_id": self.room_type_class1.id, + "list_price": 30, + } + ) + + self.room = self.env["pms.room"].create( + { + "pms_property_id": self.pms_property1.id, + "name": "Single 1", + "room_type_id": self.room_type.id, + } + ) + reservation = self.env["pms.reservation"].create( + { + "checkin": datetime.datetime.today(), + "checkout": datetime.datetime.today() + datetime.timedelta(days=3), + "preferred_room_id": self.room.id, + "pms_property_id": self.pms_property1.id, + "partner_id": self.partner1.id, + } + ) + # ACT + n_days = (reservation.checkout - reservation.checkin).days + expected_price = self.room.room_type_id.list_price * n_days + + # ASSERT + self.assertEqual( + expected_price, reservation.price_subtotal, "The price is not as expected" + ) + + @freeze_time("2022-01-01") + def test_items_sort(self): + """ + Test cases to verify the order for each field considered individually + Test cases to prioritize fields over other fields: + 1. applied_on + 2. date + 3. date consumption + 4. num. properties + 5. id + - tie + - no [date_start|date_end|date_start_consumption|date_end_consumption] + """ + # ARRANGE + self.product_category = self.env["product.category"].create( + {"name": "Category1"} + ) + self.product_template = self.env["product.template"].create( + {"name": "Template1"} + ) + self.room_type = self.env["pms.room.type"].create( + { + "pms_property_ids": [self.pms_property1.id, self.pms_property2.id], + "name": "Single", + "default_code": "SGL", + "class_id": self.room_type_class1.id, + "list_price": 30, + } + ) + + self.room = self.env["pms.room"].create( + { + "pms_property_id": self.pms_property1.id, + "name": "101", + "room_type_id": self.room_type.id, + } + ) + properties = self.room_type.product_id.pms_property_ids.ids + test_cases = [ + { + "name": "sorting applied_on", + "expected_price": 50 * 3, + "items": [ + { + "pricelist_id": self.pricelist1.id, + "applied_on": "2_product_category", + "categ_id": self.product_category.id, + "fixed_price": 60.0, + }, + { + "pricelist_id": self.pricelist1.id, + "applied_on": "0_product_variant", + "product_id": self.room_type.product_id.id, + "fixed_price": 50.0, + "pms_property_ids": properties, + }, + { + "pricelist_id": self.pricelist1.id, + "applied_on": "1_product", + "product_id": self.room_type.product_id.id, + "product_tmpl_id": self.product_template.id, + "fixed_price": 40.0, + "pms_property_ids": properties, + }, + ], + }, + { + "name": "sorting SALE date min range", + "expected_price": 50.0 * 3, + "items": [ + { + "pricelist_id": self.pricelist1.id, + "applied_on": "0_product_variant", + "product_id": self.room_type.product_id.id, + "date_start": datetime.datetime.now(), + "date_end": datetime.datetime.now() + + datetime.timedelta(days=2), + "fixed_price": 60.0, + "pms_property_ids": properties, + }, + { + "pricelist_id": self.pricelist1.id, + "applied_on": "0_product_variant", + "product_id": self.room_type.product_id.id, + "date_start": datetime.datetime.now(), + "date_end": datetime.datetime.now() + + datetime.timedelta(days=1), + "fixed_price": 50.0, + "pms_property_ids": properties, + }, + { + "pricelist_id": self.pricelist1.id, + "applied_on": "0_product_variant", + "product_id": self.room_type.product_id.id, + "date_start": datetime.datetime.now(), + "date_end": datetime.datetime.now() + + datetime.timedelta(days=3), + "fixed_price": 40.0, + "pms_property_ids": properties, + }, + ], + }, + { + "name": "sorting CONSUMPTION date min range", + "expected_price": 40.0 * 3, + "items": [ + { + "pricelist_id": self.pricelist1.id, + "applied_on": "0_product_variant", + "product_id": self.room_type.product_id.id, + "date_start_consumption": datetime.datetime.now(), + "date_end_consumption": datetime.datetime.now() + + datetime.timedelta(days=6), + "fixed_price": 60.0, + "pms_property_ids": properties, + }, + { + "pricelist_id": self.pricelist1.id, + "applied_on": "0_product_variant", + "product_id": self.room_type.product_id.id, + "date_start_consumption": datetime.datetime.now(), + "date_end_consumption": datetime.datetime.now() + + datetime.timedelta(days=10), + "fixed_price": 50.0, + "pms_property_ids": properties, + }, + { + "pricelist_id": self.pricelist1.id, + "applied_on": "0_product_variant", + "product_id": self.room_type.product_id.id, + "date_start_consumption": datetime.datetime.now(), + "date_end_consumption": datetime.datetime.now() + + datetime.timedelta(days=3), + "fixed_price": 40.0, + "pms_property_ids": properties, + }, + ], + }, + { + "name": "sorting num. properties", + "expected_price": 50.0 * 3, + "items": [ + { + "pricelist_id": self.pricelist1.id, + "applied_on": "0_product_variant", + "product_id": self.room_type.product_id.id, + "fixed_price": 60.0, + "pms_property_ids": properties, + }, + { + "pricelist_id": self.pricelist1.id, + "applied_on": "0_product_variant", + "product_id": self.room_type.product_id.id, + "pms_property_ids": [self.pms_property1.id], + "fixed_price": 50.0, + }, + { + "pricelist_id": self.pricelist1.id, + "applied_on": "0_product_variant", + "product_id": self.room_type.product_id.id, + "pms_property_ids": [ + self.pms_property1.id, + self.pms_property2.id, + ], + "fixed_price": 40.0, + }, + ], + }, + { + "name": "sorting by item id", + "expected_price": 40.0 * 3, + "items": [ + { + "pricelist_id": self.pricelist1.id, + "applied_on": "0_product_variant", + "product_id": self.room_type.product_id.id, + "fixed_price": 60.0, + "pms_property_ids": properties, + }, + { + "pricelist_id": self.pricelist1.id, + "applied_on": "0_product_variant", + "product_id": self.room_type.product_id.id, + "fixed_price": 50.0, + "pms_property_ids": properties, + }, + { + "pricelist_id": self.pricelist1.id, + "applied_on": "0_product_variant", + "product_id": self.room_type.product_id.id, + "fixed_price": 40.0, + "pms_property_ids": properties, + }, + ], + }, + { + "name": "prioritize applied_on over SALE date", + "expected_price": 60.0 * 3, + "items": [ + { + "pricelist_id": self.pricelist1.id, + "applied_on": "0_product_variant", + "product_id": self.room_type.product_id.id, + "date_start": datetime.datetime.now(), + "date_end": datetime.datetime.now() + + datetime.timedelta(days=2), + "fixed_price": 60.0, + "pms_property_ids": properties, + }, + { + "pricelist_id": self.pricelist1.id, + "product_id": self.room_type.product_id.id, + "product_tmpl_id": self.product_template.id, + "applied_on": "1_product", + "date_start": datetime.datetime.now(), + "date_end": datetime.datetime.now() + + datetime.timedelta(days=1), + "fixed_price": 50.0, + "pms_property_ids": properties, + }, + ], + }, + { + "name": "prioritize SALE date over CONSUMPTION date", + "expected_price": 120.0 * 3, + "items": [ + { + "pricelist_id": self.pricelist1.id, + "applied_on": "0_product_variant", + "product_id": self.room_type.product_id.id, + "date_start": datetime.datetime.now(), + "date_end": datetime.datetime.now() + + datetime.timedelta(days=10), + "fixed_price": 120.0, + "pms_property_ids": properties, + }, + { + "pricelist_id": self.pricelist1.id, + "applied_on": "0_product_variant", + "product_id": self.room_type.product_id.id, + "date_start_consumption": datetime.datetime.now(), + "date_end_consumption": datetime.datetime.now() + + datetime.timedelta(days=3), + "fixed_price": 50.0, + "pms_property_ids": properties, + }, + ], + }, + { + "name": "prioritize CONSUMPTION date over min. num. properties", + "expected_price": 50.0 * 3, + "items": [ + { + "pricelist_id": self.pricelist1.id, + "applied_on": "0_product_variant", + "product_id": self.room_type.product_id.id, + "date_start_consumption": datetime.datetime.now(), + "date_end_consumption": datetime.datetime.now() + + datetime.timedelta(days=3), + "fixed_price": 120.0, + "pms_property_ids": properties, + }, + { + "pricelist_id": self.pricelist1.id, + "applied_on": "0_product_variant", + "product_id": self.room_type.product_id.id, + "date_start_consumption": datetime.datetime.now(), + "date_end_consumption": datetime.datetime.now() + + datetime.timedelta(days=3), + "pms_property_ids": [ + self.pms_property1.id, + self.pms_property2.id, + ], + "fixed_price": 50.0, + }, + ], + }, + { + "name": "prioritize min. num. properties over item id", + "expected_price": 50.0 * 3, + "items": [ + { + "pricelist_id": self.pricelist1.id, + "applied_on": "0_product_variant", + "product_id": self.room_type.product_id.id, + "date_start_consumption": datetime.datetime.now(), + "date_end_consumption": datetime.datetime.now() + + datetime.timedelta(days=3), + "fixed_price": 120.0, + "pms_property_ids": properties, + }, + { + "pricelist_id": self.pricelist1.id, + "applied_on": "0_product_variant", + "product_id": self.room_type.product_id.id, + "date_start_consumption": datetime.datetime.now(), + "date_end_consumption": datetime.datetime.now() + + datetime.timedelta(days=3), + "pms_property_ids": [ + self.pms_property1.id, + self.pms_property2.id, + ], + "fixed_price": 50.0, + }, + ], + }, + { + "name": "tie => order by item id", + "expected_price": 50.0 * 3, + "items": [ + { + "pricelist_id": self.pricelist1.id, + "applied_on": "0_product_variant", + "product_id": self.room_type.product_id.id, + "date_start_consumption": datetime.datetime.now(), + "date_end_consumption": datetime.datetime.now() + + datetime.timedelta(days=3), + "date_start": datetime.datetime.now(), + "date_end": datetime.datetime.now() + + datetime.timedelta(days=3), + "pms_property_ids": [ + self.pms_property1.id, + self.pms_property2.id, + ], + "fixed_price": 120.0, + }, + { + "pricelist_id": self.pricelist1.id, + "applied_on": "0_product_variant", + "product_id": self.room_type.product_id.id, + "date_start_consumption": datetime.datetime.now(), + "date_end_consumption": datetime.datetime.now() + + datetime.timedelta(days=3), + "date_start": datetime.datetime.now(), + "date_end": datetime.datetime.now() + + datetime.timedelta(days=3), + "pms_property_ids": [ + self.pms_property1.id, + self.pms_property2.id, + ], + "fixed_price": 50.0, + }, + ], + }, + { + "name": "no SALE DATE START", + "expected_price": 40.0 * 3, + "items": [ + { + "pricelist_id": self.pricelist1.id, + "applied_on": "0_product_variant", + "product_id": self.room_type.product_id.id, + "date_end": datetime.datetime.now() + + datetime.timedelta(days=1), + "fixed_price": 40.0, + "pms_property_ids": properties, + }, + ], + }, + { + "name": "no SALE DATE END", + "expected_price": 40.0 * 3, + "items": [ + { + "pricelist_id": self.pricelist1.id, + "applied_on": "0_product_variant", + "product_id": self.room_type.product_id.id, + "date_start": datetime.datetime.now(), + "fixed_price": 40.0, + "pms_property_ids": properties, + }, + ], + }, + { + "name": "no consumption DATE START", + "expected_price": 40.0 + self.room_type.list_price * 2, + "items": [ + { + "pricelist_id": self.pricelist1.id, + "applied_on": "0_product_variant", + "product_id": self.room_type.product_id.id, + "date_end_consumption": datetime.datetime.now(), + "fixed_price": 40.0, + "pms_property_ids": properties, + }, + ], + }, + { + "name": "no consumption DATE END", + "expected_price": 40.0 * 3, + "items": [ + { + "pricelist_id": self.pricelist1.id, + "applied_on": "0_product_variant", + "product_id": self.room_type.product_id.id, + "date_start_consumption": datetime.datetime.now(), + "fixed_price": 40.0, + "pms_property_ids": properties, + }, + ], + }, + { + "name": "only applied consumption in one night", + "expected_price": 40.0 + self.room_type.list_price * 2, + "items": [ + { + "pricelist_id": self.pricelist1.id, + "applied_on": "0_product_variant", + "product_id": self.room_type.product_id.id, + "date_start_consumption": datetime.datetime.now(), + "date_end_consumption": datetime.datetime.now(), + "fixed_price": 40.0, + "pms_property_ids": properties, + }, + ], + }, + ] + + for tc in test_cases: + with self.subTest(k=tc): + + # ARRANGE + items = [] + for item in tc["items"]: + item = self.env["product.pricelist.item"].create(item) + items.append(item.id) + + # ACT + reservation = self.env["pms.reservation"].create( + { + "partner_id": self.partner1.id, + "checkin": datetime.datetime.now(), + "checkout": datetime.datetime.now() + + datetime.timedelta(days=3), + "preferred_room_id": self.room.id, + "pms_property_id": self.pms_property1.id, + "pricelist_id": self.pricelist1.id, + } + ) + reservation_price = reservation.price_subtotal + self.env["pms.reservation"].browse(reservation.id).unlink() + self.env["product.pricelist.item"].browse(items).unlink() + + # ASSERT + self.assertEqual(tc["expected_price"], reservation_price, tc["name"]) diff --git a/pms/tests/test_pms_pricelist_priority.py b/pms/tests/test_pms_pricelist_priority.py deleted file mode 100644 index 94011c18b..000000000 --- a/pms/tests/test_pms_pricelist_priority.py +++ /dev/null @@ -1,541 +0,0 @@ -import datetime - -from freezegun import freeze_time - -from odoo.tests import common - - -class TestPmsPricelistRules(common.SavepointCase): - def create_common_scenario(self): - self.product_template = self.env["product.template"].create( - {"name": "Template1"} - ) - self.product_category = self.env["product.category"].create( - {"name": "Category1"} - ) - - self.availability_plan1 = self.env["pms.availability.plan"].create( - {"name": "Availability 1"} - ) - - self.availability_plan2 = self.env["pms.availability.plan"].create( - {"name": "Availability"} - ) - # 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, - } - ) - self.property1 = self.env["pms.property"].create( - { - "name": "Property_1", - "company_id": self.env.ref("base.main_company").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": "Property_2", - "company_id": self.env.ref("base.main_company").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_class = self.env["pms.room.type.class"].create( - {"name": "Room Class", "default_code": "ROOM"} - ) - - self.room_type = self.env["pms.room.type"].create( - { - "pms_property_ids": [self.property1.id, self.property2.id], - "name": "Single", - "default_code": "SIN", - "class_id": self.room_type_class.id, - "list_price": 30, - } - ) - - self.room = self.env["pms.room"].create( - { - "pms_property_id": self.property1.id, - "name": "Single 101", - "room_type_id": self.room_type.id, - } - ) - - self.room2 = self.env["pms.room"].create( - { - "pms_property_id": self.property2.id, - "name": "Single 102", - "room_type_id": self.room_type.id, - } - ) - - self.pricelist = self.env["product.pricelist"].create( - { - "name": "pricelist_1", - } - ) - - self.partner1 = self.env["res.partner"].create({"name": "Carles"}) - - @freeze_time("2000-01-01") - def test_simple_price_without_items(self): - # TEST CASE : no items applied - - # ARRANGE - self.create_common_scenario() - - reservation = self.env["pms.reservation"].create( - { - "checkin": datetime.datetime.today(), - "checkout": datetime.datetime.today() + datetime.timedelta(days=3), - "preferred_room_id": self.room.id, - "pms_property_id": self.property1.id, - "partner_id": self.partner1.id, - } - ) - # ACT - n_days = (reservation.checkout - reservation.checkin).days - expected_price = self.room.room_type_id.list_price * n_days - - # ASSERT - self.assertEqual( - expected_price, reservation.price_subtotal, "The price is not as expected" - ) - - @freeze_time("2022-01-01") - def test_items_sort(self): - - # ARRANGE - self.create_common_scenario() - - # - test cases to verify the order for each field considered individually - # - test cases to prioritize fields over other fields: - # 1. applied_on - # 2. date - # 3. date consumption - # 4. num. properties - # 5. id - # - tie - # - no [date_start|date_end|date_start_consumption|date_end_consumption] - properties = self.room_type.product_id.pms_property_ids.ids - test_cases = [ - { - "name": "sorting applied_on", - "expected_price": 50 * 3, - "items": [ - { - "pricelist_id": self.pricelist.id, - "applied_on": "2_product_category", - "categ_id": self.product_category.id, - "fixed_price": 60.0, - }, - { - "pricelist_id": self.pricelist.id, - "applied_on": "0_product_variant", - "product_id": self.room_type.product_id.id, - "fixed_price": 50.0, - "pms_property_ids": properties, - }, - { - "pricelist_id": self.pricelist.id, - "applied_on": "1_product", - "product_id": self.room_type.product_id.id, - "product_tmpl_id": self.product_template.id, - "fixed_price": 40.0, - "pms_property_ids": properties, - }, - ], - }, - { - "name": "sorting SALE date min range", - "expected_price": 50.0 * 3, - "items": [ - { - "pricelist_id": self.pricelist.id, - "applied_on": "0_product_variant", - "product_id": self.room_type.product_id.id, - "date_start": datetime.datetime.now(), - "date_end": datetime.datetime.now() - + datetime.timedelta(days=2), - "fixed_price": 60.0, - "pms_property_ids": properties, - }, - { - "pricelist_id": self.pricelist.id, - "applied_on": "0_product_variant", - "product_id": self.room_type.product_id.id, - "date_start": datetime.datetime.now(), - "date_end": datetime.datetime.now() - + datetime.timedelta(days=1), - "fixed_price": 50.0, - "pms_property_ids": properties, - }, - { - "pricelist_id": self.pricelist.id, - "applied_on": "0_product_variant", - "product_id": self.room_type.product_id.id, - "date_start": datetime.datetime.now(), - "date_end": datetime.datetime.now() - + datetime.timedelta(days=3), - "fixed_price": 40.0, - "pms_property_ids": properties, - }, - ], - }, - { - "name": "sorting CONSUMPTION date min range", - "expected_price": 40.0 * 3, - "items": [ - { - "pricelist_id": self.pricelist.id, - "applied_on": "0_product_variant", - "product_id": self.room_type.product_id.id, - "date_start_consumption": datetime.datetime.now(), - "date_end_consumption": datetime.datetime.now() - + datetime.timedelta(days=6), - "fixed_price": 60.0, - "pms_property_ids": properties, - }, - { - "pricelist_id": self.pricelist.id, - "applied_on": "0_product_variant", - "product_id": self.room_type.product_id.id, - "date_start_consumption": datetime.datetime.now(), - "date_end_consumption": datetime.datetime.now() - + datetime.timedelta(days=10), - "fixed_price": 50.0, - "pms_property_ids": properties, - }, - { - "pricelist_id": self.pricelist.id, - "applied_on": "0_product_variant", - "product_id": self.room_type.product_id.id, - "date_start_consumption": datetime.datetime.now(), - "date_end_consumption": datetime.datetime.now() - + datetime.timedelta(days=3), - "fixed_price": 40.0, - "pms_property_ids": properties, - }, - ], - }, - { - "name": "sorting num. properties", - "expected_price": 50.0 * 3, - "items": [ - { - "pricelist_id": self.pricelist.id, - "applied_on": "0_product_variant", - "product_id": self.room_type.product_id.id, - "fixed_price": 60.0, - "pms_property_ids": properties, - }, - { - "pricelist_id": self.pricelist.id, - "applied_on": "0_product_variant", - "product_id": self.room_type.product_id.id, - "pms_property_ids": [self.property1.id], - "fixed_price": 50.0, - }, - { - "pricelist_id": self.pricelist.id, - "applied_on": "0_product_variant", - "product_id": self.room_type.product_id.id, - "pms_property_ids": [self.property1.id, self.property2.id], - "fixed_price": 40.0, - }, - ], - }, - { - "name": "sorting by item id", - "expected_price": 40.0 * 3, - "items": [ - { - "pricelist_id": self.pricelist.id, - "applied_on": "0_product_variant", - "product_id": self.room_type.product_id.id, - "fixed_price": 60.0, - "pms_property_ids": properties, - }, - { - "pricelist_id": self.pricelist.id, - "applied_on": "0_product_variant", - "product_id": self.room_type.product_id.id, - "fixed_price": 50.0, - "pms_property_ids": properties, - }, - { - "pricelist_id": self.pricelist.id, - "applied_on": "0_product_variant", - "product_id": self.room_type.product_id.id, - "fixed_price": 40.0, - "pms_property_ids": properties, - }, - ], - }, - { - "name": "prioritize applied_on over SALE date", - "expected_price": 60.0 * 3, - "items": [ - { - "pricelist_id": self.pricelist.id, - "applied_on": "0_product_variant", - "product_id": self.room_type.product_id.id, - "date_start": datetime.datetime.now(), - "date_end": datetime.datetime.now() - + datetime.timedelta(days=2), - "fixed_price": 60.0, - "pms_property_ids": properties, - }, - { - "pricelist_id": self.pricelist.id, - "product_id": self.room_type.product_id.id, - "product_tmpl_id": self.product_template.id, - "applied_on": "1_product", - "date_start": datetime.datetime.now(), - "date_end": datetime.datetime.now() - + datetime.timedelta(days=1), - "fixed_price": 50.0, - "pms_property_ids": properties, - }, - ], - }, - { - "name": "prioritize SALE date over CONSUMPTION date", - "expected_price": 120.0 * 3, - "items": [ - { - "pricelist_id": self.pricelist.id, - "applied_on": "0_product_variant", - "product_id": self.room_type.product_id.id, - "date_start": datetime.datetime.now(), - "date_end": datetime.datetime.now() - + datetime.timedelta(days=10), - "fixed_price": 120.0, - "pms_property_ids": properties, - }, - { - "pricelist_id": self.pricelist.id, - "applied_on": "0_product_variant", - "product_id": self.room_type.product_id.id, - "date_start_consumption": datetime.datetime.now(), - "date_end_consumption": datetime.datetime.now() - + datetime.timedelta(days=3), - "fixed_price": 50.0, - "pms_property_ids": properties, - }, - ], - }, - { - "name": "prioritize CONSUMPTION date over min. num. properties", - "expected_price": 50.0 * 3, - "items": [ - { - "pricelist_id": self.pricelist.id, - "applied_on": "0_product_variant", - "product_id": self.room_type.product_id.id, - "date_start_consumption": datetime.datetime.now(), - "date_end_consumption": datetime.datetime.now() - + datetime.timedelta(days=3), - "fixed_price": 120.0, - "pms_property_ids": properties, - }, - { - "pricelist_id": self.pricelist.id, - "applied_on": "0_product_variant", - "product_id": self.room_type.product_id.id, - "date_start_consumption": datetime.datetime.now(), - "date_end_consumption": datetime.datetime.now() - + datetime.timedelta(days=3), - "pms_property_ids": [self.property1.id, self.property2.id], - "fixed_price": 50.0, - }, - ], - }, - { - "name": "prioritize min. num. properties over item id", - "expected_price": 50.0 * 3, - "items": [ - { - "pricelist_id": self.pricelist.id, - "applied_on": "0_product_variant", - "product_id": self.room_type.product_id.id, - "date_start_consumption": datetime.datetime.now(), - "date_end_consumption": datetime.datetime.now() - + datetime.timedelta(days=3), - "fixed_price": 120.0, - "pms_property_ids": properties, - }, - { - "pricelist_id": self.pricelist.id, - "applied_on": "0_product_variant", - "product_id": self.room_type.product_id.id, - "date_start_consumption": datetime.datetime.now(), - "date_end_consumption": datetime.datetime.now() - + datetime.timedelta(days=3), - "pms_property_ids": [self.property1.id, self.property2.id], - "fixed_price": 50.0, - }, - ], - }, - { - "name": "tie => order by item id", - "expected_price": 50.0 * 3, - "items": [ - { - "pricelist_id": self.pricelist.id, - "applied_on": "0_product_variant", - "product_id": self.room_type.product_id.id, - "date_start_consumption": datetime.datetime.now(), - "date_end_consumption": datetime.datetime.now() - + datetime.timedelta(days=3), - "date_start": datetime.datetime.now(), - "date_end": datetime.datetime.now() - + datetime.timedelta(days=3), - "pms_property_ids": [self.property1.id, self.property2.id], - "fixed_price": 120.0, - }, - { - "pricelist_id": self.pricelist.id, - "applied_on": "0_product_variant", - "product_id": self.room_type.product_id.id, - "date_start_consumption": datetime.datetime.now(), - "date_end_consumption": datetime.datetime.now() - + datetime.timedelta(days=3), - "date_start": datetime.datetime.now(), - "date_end": datetime.datetime.now() - + datetime.timedelta(days=3), - "pms_property_ids": [self.property1.id, self.property2.id], - "fixed_price": 50.0, - }, - ], - }, - { - "name": "no SALE DATE START", - "expected_price": 40.0 * 3, - "items": [ - { - "pricelist_id": self.pricelist.id, - "applied_on": "0_product_variant", - "product_id": self.room_type.product_id.id, - "date_end": datetime.datetime.now() - + datetime.timedelta(days=1), - "fixed_price": 40.0, - "pms_property_ids": properties, - }, - ], - }, - { - "name": "no SALE DATE END", - "expected_price": 40.0 * 3, - "items": [ - { - "pricelist_id": self.pricelist.id, - "applied_on": "0_product_variant", - "product_id": self.room_type.product_id.id, - "date_start": datetime.datetime.now(), - "fixed_price": 40.0, - "pms_property_ids": properties, - }, - ], - }, - { - "name": "no consumption DATE START", - "expected_price": 40.0 + self.room_type.list_price * 2, - "items": [ - { - "pricelist_id": self.pricelist.id, - "applied_on": "0_product_variant", - "product_id": self.room_type.product_id.id, - "date_end_consumption": datetime.datetime.now(), - "fixed_price": 40.0, - "pms_property_ids": properties, - }, - ], - }, - { - "name": "no consumption DATE END", - "expected_price": 40.0 * 3, - "items": [ - { - "pricelist_id": self.pricelist.id, - "applied_on": "0_product_variant", - "product_id": self.room_type.product_id.id, - "date_start_consumption": datetime.datetime.now(), - "fixed_price": 40.0, - "pms_property_ids": properties, - }, - ], - }, - { - "name": "only applied consumption in one night", - "expected_price": 40.0 + self.room_type.list_price * 2, - "items": [ - { - "pricelist_id": self.pricelist.id, - "applied_on": "0_product_variant", - "product_id": self.room_type.product_id.id, - "date_start_consumption": datetime.datetime.now(), - "date_end_consumption": datetime.datetime.now(), - "fixed_price": 40.0, - "pms_property_ids": properties, - }, - ], - }, - ] - - for tc in test_cases: - with self.subTest(k=tc): - - # ARRANGE - items = [] - for item in tc["items"]: - item = self.env["product.pricelist.item"].create(item) - items.append(item.id) - - # ACT - reservation = self.env["pms.reservation"].create( - { - "partner_id": self.partner1.id, - "checkin": datetime.datetime.now(), - "checkout": datetime.datetime.now() - + datetime.timedelta(days=3), - "preferred_room_id": self.room.id, - "pms_property_id": self.property1.id, - "pricelist_id": self.pricelist.id, - } - ) - reservation_price = reservation.price_subtotal - self.env["pms.reservation"].browse(reservation.id).unlink() - self.env["product.pricelist.item"].browse(items).unlink() - - # ASSERT - self.assertEqual(tc["expected_price"], reservation_price, tc["name"]) diff --git a/pms/tests/test_pms_pricelist_settings.py b/pms/tests/test_pms_pricelist_settings.py new file mode 100644 index 000000000..7b04ebc96 --- /dev/null +++ b/pms/tests/test_pms_pricelist_settings.py @@ -0,0 +1,55 @@ +from odoo.exceptions import ValidationError + +from .common import TestPms + + +class TestPmsPricelistSettings(TestPms): + def test_advanced_pricelist_exists(self): + """ + Check if value of Pricelist parameter in sales settings is Advanced Price Rules. + Find the value of Pricelist parameter + with the key product.product_pricelist_setting and check if is equal to "advanced". + """ + # ARRANGE + key = "product.product_pricelist_setting" + value = "advanced" + + # ACT + found_value = self.env["ir.config_parameter"].sudo().get_param(key) + + # ASSERT + self.assertEqual( + found_value, value, "Parameter of Pricelist in setting is not 'advanced'" + ) + + def test_product_pricelist_setting_not_modified(self): + """ + Check that Pricelist parameter 'advanced' cannot be modified. + Set the value of product.product_pricelist_setting to 'basic' + but is not possible because this only can be 'advanced'. + """ + # ARRANGE + key = "product.product_pricelist_setting" + value = "basic" + + # ACT & ASSERT + with self.assertRaises( + ValidationError, msg="The Pricelist parameter 'advanced' was modified." + ): + self.env["ir.config_parameter"].set_param(key, value) + + def test_product_pricelist_setting_not_unlink(self): + """ + Check that Pricelist parameter 'advanced' cannot be unlink. + Try to unlink the parameter product_pricelist with value 'advanced' + but this should be impossible. + """ + # ARRANGE + key = "product.product_pricelist_setting" + value = "advanced" + + # ACT & ASSERT + with self.assertRaises(ValidationError), self.cr.savepoint(): + self.env["ir.config_parameter"].search( + [("key", "=", key), ("value", "=", value)] + ).unlink() diff --git a/pms/tests/test_pms_reservation_prices.py b/pms/tests/test_pms_reservation_prices.py deleted file mode 100644 index 91907f7d0..000000000 --- a/pms/tests/test_pms_reservation_prices.py +++ /dev/null @@ -1,12 +0,0 @@ -from odoo.tests.common import SavepointCase - - -class TestPmsFolioInvoice(SavepointCase): - def setUp(self): - super(TestPmsFolioInvoice, self).setUp() - - def test_price_reservation(self): - """Test create a reservation, and check price and discounts""" - - def test_general_discount_reservation(self): - """Test a discount in reservation head, and check lines"""