From 9d2579021c74462aae52b0adac3a930718230078 Mon Sep 17 00:00:00 2001 From: miguelpadin Date: Thu, 10 Jun 2021 20:29:52 +0200 Subject: [PATCH] [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 ),