Merge PR #14 into 14.0

Signed-off-by DarioLodeiros
This commit is contained in:
OCA-git-bot
2021-06-15 22:28:17 +00:00
11 changed files with 1549 additions and 913 deletions

View File

@@ -113,6 +113,10 @@ class ResPartner(models.Model):
for record in self:
if record.is_agency and not record.sale_channel_id:
raise models.ValidationError(_("Sale Channel must be entered"))
if record.is_agency and record.sale_channel_id.channel_type != "indirect":
raise models.ValidationError(
_("Sale Channel for an agency must be indirect")
)
if not record.is_agency and record.sale_channel_id:
record.sale_channel_id = None

View File

@@ -40,3 +40,4 @@ from . import test_pms_board_service_room_type_line
from . import test_pms_folio_invoice
from . import test_pms_folio_sale_line
from . import test_pms_wizard_split_join_swap_reservation
from . import test_product_template

View File

@@ -22,9 +22,11 @@ class TestBoardService(TestPms):
}
)
# external integrity
def test_external_case_01(self):
def test_create_bs_one_company_inconsistent_code(self):
"""
Creation of board service with the same code as an existing one
belonging to the same property should fail.
PRE: - board service bs1 exists
- board_service1 has code c1
- board_service1 has pms_property1
@@ -45,7 +47,6 @@ class TestBoardService(TestPms):
"pms_property_ids": [(6, 0, [self.pms_property1.id])],
}
)
# ACT & ASSERT
with self.assertRaises(
ValidationError, msg="The board service has been created and it shouldn't"
@@ -59,8 +60,11 @@ class TestBoardService(TestPms):
}
)
def test_external_case_02(self):
def test_create_bs_several_companies_inconsistent_code(self):
"""
Creation of board service with properties and one of its
properties has the same code on its board services should fail.
PRE: - board service bs1 exists
- board_service1 has code c1
- board_service1 has property pms_property1
@@ -90,7 +94,6 @@ class TestBoardService(TestPms):
"pms_property_ids": [(6, 0, [self.pms_property1.id])],
}
)
# ACT & ASSERT
with self.assertRaises(
ValidationError, msg="The board service has been created and it shouldn't"
@@ -114,8 +117,11 @@ class TestBoardService(TestPms):
}
)
def test_single_case_01(self):
def test_search_bs_code_same_company_several_properties(self):
"""
Checks the search for a board service by code when the board service
belongs to properties of the same company
PRE: - board service bs1 exists
- board_service1 has code c1
- board_service1 has 2 properties pms_property1 and pms_property2
@@ -125,21 +131,26 @@ class TestBoardService(TestPms):
POST: - only board_service1 board service found
"""
# ARRANGE
self.pms_property2 = self.env["pms.property"].create(
{
"name": "Property 2",
"company_id": self.company1.id,
"default_pricelist_id": self.pricelist1.id,
}
)
board_service1 = self.env["pms.board.service"].create(
{
"name": "Board service 1",
"default_code": "c1",
"pms_property_ids": [
(6, 0, [self.pms_property1.id, self.pms_property3.id])
(6, 0, [self.pms_property1.id, self.pms_property2.id])
],
}
)
# ACT
board_services = self.env["pms.board.service"].get_unique_by_property_code(
self.pms_property1.id, "c1"
)
# ASSERT
self.assertEqual(
board_services.id,
@@ -147,12 +158,15 @@ class TestBoardService(TestPms):
"Expected board service not found",
)
def test_single_case_02(self):
def test_search_bs_code_several_companies_several_properties_not_found(self):
"""
Checks the search for a board service by code when the board service
belongs to properties with different companies
PRE: - board service bs1 exists
- board_service1 has code c1
- board_service1 has 2 properties pms_property1 and pms_property3
- pms_property1 and pms_property2 have different companies
- pms_property1 and pms_property3 have different companies
- pms_property1 have company company1 and pms_property3 have company2
ACT: - search board service with code c1 and property pms_property1
- pms_property1 has company company1
@@ -168,17 +182,18 @@ class TestBoardService(TestPms):
],
}
)
# ACT
board_services = self.env["pms.board.service"].get_unique_by_property_code(
self.pms_property1.id, "c1"
)
# ASSERT
self.assertEqual(board_services.id, bs1.id, "Expected board service not found")
def test_single_case_03(self):
def test_search_bs_code_no_result(self):
"""
Search for a specific board service code and its property.
The board service exists but not in the property given.
PRE: - board_service1 exists
- board_service1 has code c1
- board_service1 with 2 properties pms_property1 and pms_property2
@@ -205,19 +220,21 @@ class TestBoardService(TestPms):
],
}
)
# ACT
board_services = self.env["pms.board.service"].get_unique_by_property_code(
self.pms_property3.id, "c1"
)
# ASSERT
self.assertFalse(
board_services, "Board service found but it should not have found any"
)
def test_single_case_04(self):
def test_search_bs_code_present_all_companies_and_properties(self):
"""
Search for a specific board service and its property.
The board service exists without property, then
the search foundS the result.
PRE: - board_service1 exists
- board_service1 has code c1
- board_service1 properties are null
@@ -233,12 +250,10 @@ class TestBoardService(TestPms):
"pms_property_ids": False,
}
)
# ACT
board_services = self.env["pms.board.service"].get_unique_by_property_code(
self.pms_property1.id, "c1"
)
# ASSERT
self.assertEqual(
board_services.id,
@@ -246,12 +261,18 @@ class TestBoardService(TestPms):
"Expected board service not found",
)
# tests with more than one board service
def test_multiple_case_01(self):
def test_search_bs_code_several_companies_several_properties(self):
"""
Search for a specific board service and its property.
There is one board service without properties and
another one with the same code that belongs to 2 properties
(from different companies)
The search founds only the board service that match the
property given.
PRE: - board_service1 exists
- board_service1 has code c1
- board_service1 has 2 properties pms_property1 and pms_property2
- board_service1 has 2 properties pms_property1 and pms_property3
- pms_property1 and pms_property2 have the same company company1
- board service board_service2 exists
- board_service2 has code c1
@@ -278,12 +299,10 @@ class TestBoardService(TestPms):
"pms_property_ids": False,
}
)
# ACT
board_services = self.env["pms.board.service"].get_unique_by_property_code(
self.pms_property1.id, "c1"
)
# ASSERT
self.assertEqual(
board_services.id,
@@ -291,8 +310,15 @@ class TestBoardService(TestPms):
"Expected board service not found",
)
def test_multiple_case_02(self):
def test_search_bs_code_same_companies_several_properties(self):
"""
Search for a specific board service and its property.
There is one board service without properties and
another one with the same code that belongs to 2 properties
(same company).
The search founds only the board service that match the
property given.
PRE: - board_service1 exists
- board_service1 has code c1
- board_service1 has property pms_property1
@@ -302,7 +328,7 @@ class TestBoardService(TestPms):
- board_service2 has no properties
ACT: - search board service with code c1 and pms_property2
- pms_property2 have company company1
POST: - only board_service1 board service found
POST: - only board_service2 board service found
"""
# ARRANGE
self.pms_property2 = self.env["pms.property"].create(
@@ -312,7 +338,6 @@ class TestBoardService(TestPms):
"default_pricelist_id": self.pricelist1.id,
}
)
# board_service1
self.env["pms.board.service"].create(
{
"name": "Board service 1",
@@ -327,12 +352,10 @@ class TestBoardService(TestPms):
"pms_property_ids": False,
}
)
# ACT
board_services = self.env["pms.board.service"].get_unique_by_property_code(
self.pms_property2.id, "c1"
)
# ASSERT
self.assertEqual(
board_services.id,
@@ -340,8 +363,14 @@ class TestBoardService(TestPms):
"Expected board service not found",
)
def test_multiple_case_03(self):
def test_search_bs_code_no_properties(self):
"""
Search for a specific board service and its property.
There is one board service without properties and
another one with the same code that belongs to one property.
The search founds only the board service that match the
property given that it's not the same as the 2nd one.
PRE: - board_service1 exists
- board_service1 has code c1
- board_service1 has property pms_property1
@@ -369,55 +398,13 @@ class TestBoardService(TestPms):
"pms_property_ids": False,
}
)
# ACT
board_services = self.env["pms.board.service"].get_unique_by_property_code(
self.pms_property3.id, "c1"
)
# ASSERT
self.assertEqual(
board_services.id,
board_service2.id,
"Expected board service not found",
)
def test_multiple_case_04(self):
"""
PRE: - board_service1 exists
- board_service1 has code c1
- board_service1 has property pms_property1
- pms_property1 have the company company1
- room type board_service2 exists
- board_service2 has code c1
- board_service2 has no properties
ACT: - search board service with code c1 and property pms_property3
- pms_property3 have company company2
POST: - r2 board service found
"""
# ARRANGE
# board_service1
self.env["pms.board.service"].create(
{
"name": "Board service 1",
"default_code": "c1",
"pms_property_ids": [(6, 0, [self.pms_property1.id])],
}
)
board_service2 = self.env["pms.board.service"].create(
{
"name": "Board service bs2",
"default_code": "c1",
"pms_property_ids": False,
}
)
# ACT
board_services = self.env["pms.board.service"].get_unique_by_property_code(
self.pms_property3.id, "c1"
)
# ASSERT
self.assertEqual(
board_services.id, board_service2.id, "Expected room type not found"
)

View File

@@ -1,75 +1,100 @@
from odoo.exceptions import UserError
from odoo.tests import common
from .common import TestPms
class TestPmsBoardService(common.SavepointCase):
def test_property_integrity(self):
self.company1 = self.env["res.company"].create(
{
"name": "Pms_Company_Test",
}
class TestPmsBoardService(TestPms):
def test_pms_bsl_product_property_integrity(self):
"""
Creation of a board service line without property, of a product
only available for a specific property.
"""
# ARRANGE
product = self.env["product.product"].create(
{"name": "Product", "pms_property_ids": [self.pms_property1.id]}
)
self.folio_sequence = self.env["ir.sequence"].create(
{
"name": "PMS Folio",
"code": "pms.folio",
"padding": 4,
"company_id": self.company1.id,
}
)
self.reservation_sequence = self.env["ir.sequence"].create(
{
"name": "PMS Reservation",
"code": "pms.reservation",
"padding": 4,
"company_id": self.company1.id,
}
)
self.checkin_sequence = self.env["ir.sequence"].create(
{
"name": "PMS Checkin",
"code": "pms.checkin.partner",
"padding": 4,
"company_id": self.company1.id,
}
)
self.property1 = self.env["pms.property"].create(
{
"name": "Pms_property_test1",
"company_id": self.company1.id,
"default_pricelist_id": self.env.ref("product.list0").id,
"folio_sequence_id": self.folio_sequence.id,
"reservation_sequence_id": self.reservation_sequence.id,
"checkin_sequence_id": self.checkin_sequence.id,
}
)
self.property2 = self.env["pms.property"].create(
{
"name": "Pms_property_test2",
"company_id": self.company1.id,
"default_pricelist_id": self.env.ref("product.list0").id,
"folio_sequence_id": self.folio_sequence.id,
"reservation_sequence_id": self.reservation_sequence.id,
"checkin_sequence_id": self.checkin_sequence.id,
}
)
self.product = self.env["product.product"].create(
{"name": "Product", "pms_property_ids": self.property1}
)
self.board_service = self.env["pms.board.service"].create(
board_service = self.env["pms.board.service"].create(
{
"name": "Board Service",
"default_code": "CB",
}
)
with self.assertRaises(UserError):
board_service_line = self.board_service_line = self.env[
"pms.board.service.line"
].create(
# ACT & ASSERT
with self.assertRaises(
UserError, msg="Board service line shouldnt be created."
):
self.env["pms.board.service.line"].create(
{
"product_id": self.product.id,
"pms_board_service_id": self.board_service.id,
"product_id": product.id,
"pms_board_service_id": board_service.id,
}
)
def test_pms_bsl_board_service_property_integrity(self):
"""
Creation of a board service line without property, of board service
only available for a specific property.
"""
# ARRANGE
pms_property2 = self.env["pms.property"].create(
{
"name": "Property 1",
"company_id": self.company1.id,
"default_pricelist_id": self.pricelist1.id,
}
)
product = self.env["product.product"].create(
{"name": "Product", "pms_property_ids": [self.pms_property1.id]}
)
board_service = self.env["pms.board.service"].create(
{
"name": "Board Service",
"default_code": "CB",
"pms_property_ids": [pms_property2.id],
}
)
# ACT & ASSERT
with self.assertRaises(
UserError, msg="Board service line shouldnt be created."
):
self.env["pms.board.service.line"].create(
{
"product_id": product.id,
"pms_board_service_id": board_service.id,
}
)
def test_pms_bsl_board_service_line_prop_integrity(self):
"""
Creation of a board service line with a specific property,
of board service without property.
"""
# ARRANGE
pms_property2 = self.env["pms.property"].create(
{
"name": "Property 1",
"company_id": self.company1.id,
"default_pricelist_id": self.pricelist1.id,
}
)
product = self.env["product.product"].create(
{"name": "Product", "pms_property_ids": [self.pms_property1.id]}
)
board_service = self.env["pms.board.service"].create(
{
"name": "Board Service",
"default_code": "CB",
}
)
# ACT & ASSERT
with self.assertRaises(
UserError, msg="Board service line shouldnt be created."
):
self.env["pms.board.service.line"].create(
{
"product_id": product.id,
"pms_board_service_id": board_service.id,
"pms_property_ids": [pms_property2.id],
}
)
board_service_line.pms_property_ids = [self.property2.id]

View File

@@ -1,81 +1,29 @@
from odoo.tests import common
from .common import TestPms
class TestPmsBoardServiceRoomType(common.SavepointCase):
def _create_common_scenario(self):
self.company1 = self.env["res.company"].create(
{
"name": "Pms_Company_Test",
}
)
self.folio_sequence = self.env["ir.sequence"].create(
{
"name": "PMS Folio",
"code": "pms.folio",
"padding": 4,
"company_id": self.company1.id,
}
)
self.reservation_sequence = self.env["ir.sequence"].create(
{
"name": "PMS Reservation",
"code": "pms.reservation",
"padding": 4,
"company_id": self.company1.id,
}
)
self.checkin_sequence = self.env["ir.sequence"].create(
{
"name": "PMS Checkin",
"code": "pms.checkin.partner",
"padding": 4,
"company_id": self.company1.id,
}
)
self.property1 = self.env["pms.property"].create(
{
"name": "Pms_property_test1",
"company_id": self.company1.id,
"default_pricelist_id": self.env.ref("product.list0").id,
"folio_sequence_id": self.folio_sequence.id,
"reservation_sequence_id": self.reservation_sequence.id,
"checkin_sequence_id": self.checkin_sequence.id,
}
)
self.property2 = self.env["pms.property"].create(
{
"name": "Pms_property_test2",
"company_id": self.company1.id,
"default_pricelist_id": self.env.ref("product.list0").id,
"folio_sequence_id": self.folio_sequence.id,
"reservation_sequence_id": self.reservation_sequence.id,
"checkin_sequence_id": self.checkin_sequence.id,
}
)
self.room_type_availability = self.env["pms.availability.plan"].create(
{"name": "Availability plan for TEST"}
)
# create room type class
self.room_type_class = self.env["pms.room.type.class"].create(
{"name": "Room", "default_code": "ROOM"}
)
class TestPmsBoardServiceRoomType(TestPms):
def test_create_rt_props_gt_bs_props(self):
# TEST CASE
# Create board service for a room type and the room type
# have MORE properties than the board service.
# Record of board_service_room_type should contain the
# board service properties.
"""
Create board service for a room type and the room type
have MORE properties than the board service.
Record of board_service_room_type should contain the
board service properties.
"""
# ARRANGE
self._create_common_scenario()
pms_property2 = self.env["pms.property"].create(
{
"name": "Property 2",
"company_id": self.company1.id,
"default_pricelist_id": self.pricelist1.id,
}
)
room_type_double = self.env["pms.room.type"].create(
{
"pms_property_ids": [self.property1.id, self.property2.id],
"pms_property_ids": [self.pms_property1.id, pms_property2.id],
"name": "Double Test",
"default_code": "DBL_Test",
"class_id": self.room_type_class.id,
"class_id": self.room_type_class1.id,
"price": 25,
}
)
@@ -83,7 +31,7 @@ class TestPmsBoardServiceRoomType(common.SavepointCase):
{
"name": "Test Board Service",
"default_code": "TPS",
"pms_property_ids": [self.property1.id],
"pms_property_ids": [self.pms_property1.id],
}
)
# ACT
@@ -102,20 +50,26 @@ class TestPmsBoardServiceRoomType(common.SavepointCase):
)
def test_create_rt_props_lt_bs_props(self):
# TEST CASE
# Create board service for a room type and the room type
# have LESS properties than the board service.
# Record of board_service_room_type should contain the
# room types properties.
"""
Create board service for a room type and the room type
have LESS properties than the board service.
Record of board_service_room_type should contain the
room types properties.
"""
# ARRANGE
self._create_common_scenario()
pms_property2 = self.env["pms.property"].create(
{
"name": "Property 2",
"company_id": self.company1.id,
"default_pricelist_id": self.pricelist1.id,
}
)
room_type_double = self.env["pms.room.type"].create(
{
"pms_property_ids": [self.property1.id],
"pms_property_ids": [self.pms_property1.id],
"name": "Double Test",
"default_code": "DBL_Test",
"class_id": self.room_type_class.id,
"class_id": self.room_type_class1.id,
"price": 25,
}
)
@@ -123,7 +77,7 @@ class TestPmsBoardServiceRoomType(common.SavepointCase):
{
"name": "Test Board Service",
"default_code": "TPS",
"pms_property_ids": [self.property1.id, self.property2.id],
"pms_property_ids": [self.pms_property1.id, pms_property2.id],
}
)
# ACT
@@ -142,21 +96,20 @@ class TestPmsBoardServiceRoomType(common.SavepointCase):
)
def test_create_rt_props_eq_bs_props(self):
# TEST CASE
# Create board service for a room type and the room type
# have THE SAME properties than the board service.
# Record of board_service_room_type should contain the
# room types properties that matchs with the board
# service properties
"""
Create board service for a room type and the room type
have THE SAME properties than the board service.
Record of board_service_room_type should contain the
room types properties that matchs with the board
service properties
"""
# ARRANGE
self._create_common_scenario()
room_type_double = self.env["pms.room.type"].create(
{
"pms_property_ids": [self.property1.id],
"pms_property_ids": [self.pms_property1.id],
"name": "Double Test",
"default_code": "DBL_Test",
"class_id": self.room_type_class.id,
"class_id": self.room_type_class1.id,
"price": 25,
}
)
@@ -164,7 +117,7 @@ class TestPmsBoardServiceRoomType(common.SavepointCase):
{
"name": "Test Board Service",
"default_code": "TPS",
"pms_property_ids": [self.property1.id],
"pms_property_ids": [self.pms_property1.id],
}
)
# ACT
@@ -184,19 +137,18 @@ class TestPmsBoardServiceRoomType(common.SavepointCase):
)
def test_create_rt_no_props_and_bs_props(self):
# TEST CASE
# Create board service for a room type and the room type
# hasn't properties but the board services.
# Record of board_service_room_type should contain the
# board service properties.
"""
Create board service for a room type and the room type
hasn't properties but the board services.
Record of board_service_room_type should contain the
board service properties.
"""
# ARRANGE
self._create_common_scenario()
room_type_double = self.env["pms.room.type"].create(
{
"name": "Double Test",
"default_code": "DBL_Test",
"class_id": self.room_type_class.id,
"class_id": self.room_type_class1.id,
"price": 25,
}
)
@@ -204,7 +156,7 @@ class TestPmsBoardServiceRoomType(common.SavepointCase):
{
"name": "Test Board Service",
"default_code": "TPS",
"pms_property_ids": [self.property1.id],
"pms_property_ids": [self.pms_property1.id],
}
)
# ACT
@@ -223,20 +175,26 @@ class TestPmsBoardServiceRoomType(common.SavepointCase):
)
def test_create_rt_props_and_bs_no_props(self):
# TEST CASE
# Create board service for a room type and the board service
# hasn't properties but the room type.
# Record of board_service_room_type should contain the
# room type properties.
"""
Create board service for a room type and the board service
hasn't properties but the room type.
Record of board_service_room_type should contain the
room type properties.
"""
# ARRANGE
self._create_common_scenario()
pms_property2 = self.env["pms.property"].create(
{
"name": "Property 2",
"company_id": self.company1.id,
"default_pricelist_id": self.pricelist1.id,
}
)
room_type_double = self.env["pms.room.type"].create(
{
"pms_property_ids": [self.property1.id, self.property2.id],
"pms_property_ids": [self.pms_property1.id, pms_property2.id],
"name": "Double Test",
"default_code": "DBL_Test",
"class_id": self.room_type_class.id,
"class_id": self.room_type_class1.id,
"price": 25,
}
)
@@ -262,18 +220,18 @@ class TestPmsBoardServiceRoomType(common.SavepointCase):
)
def test_create_rt_no_props_and_bs_no_props(self):
# TEST CASE
# Create board service for a room type and the board service
# has no properties and neither does the room type
# Record of board_service_room_type shouldnt contain properties.
"""
Create board service for a room type and the board service
has no properties and neither does the room type
Record of board_service_room_type shouldnt contain properties.
"""
# ARRANGE
self._create_common_scenario()
room_type_double = self.env["pms.room.type"].create(
{
"name": "Double Test",
"default_code": "DBL_Test",
"class_id": self.room_type_class.id,
"class_id": self.room_type_class1.id,
"price": 25,
}
)

View File

@@ -1,95 +1,95 @@
from odoo.exceptions import UserError
from odoo.tests import common
from .common import TestPms
class TestPmsBoardServiceRoomTypeLine(common.SavepointCase):
def test_check_product_property_integrity(self):
self.company1 = self.env["res.company"].create(
{
"name": "Pms_Company_Test",
}
class TestPmsBoardServiceRoomTypeLine(TestPms):
def test_pms_bsrtl_product_property_integrity(self):
"""
Creation of a board service room type line without property, of a product
only available for a specific property.
"""
# ARRANGE
product = self.env["product.product"].create(
{"name": "Product", "pms_property_ids": self.pms_property1}
)
self.folio_sequence = self.env["ir.sequence"].create(
{
"name": "PMS Folio",
"code": "pms.folio",
"padding": 4,
"company_id": self.company1.id,
}
)
self.reservation_sequence = self.env["ir.sequence"].create(
{
"name": "PMS Reservation",
"code": "pms.reservation",
"padding": 4,
"company_id": self.company1.id,
}
)
self.checkin_sequence = self.env["ir.sequence"].create(
{
"name": "PMS Checkin",
"code": "pms.checkin.partner",
"padding": 4,
"company_id": self.company1.id,
}
)
self.property1 = self.env["pms.property"].create(
{
"name": "Pms_property_test1",
"company_id": self.company1.id,
"default_pricelist_id": self.env.ref("product.list0").id,
"folio_sequence_id": self.folio_sequence.id,
"reservation_sequence_id": self.reservation_sequence.id,
"checkin_sequence_id": self.checkin_sequence.id,
}
)
self.property2 = self.env["pms.property"].create(
{
"name": "Pms_property_test2",
"company_id": self.company1.id,
"default_pricelist_id": self.env.ref("product.list0").id,
"folio_sequence_id": self.folio_sequence.id,
"reservation_sequence_id": self.reservation_sequence.id,
"checkin_sequence_id": self.checkin_sequence.id,
}
)
self.board_service = self.env["pms.board.service"].create(
board_service = self.env["pms.board.service"].create(
{
"name": "Board Service",
"default_code": "CB",
"pms_property_ids": self.property1,
}
)
self.room_type_class = self.env["pms.room.type.class"].create(
{
"name": "Room Type Class",
"default_code": "SIN1",
"pms_property_ids": self.property1,
}
)
self.room_type = self.env["pms.room.type"].create(
room_type = self.env["pms.room.type"].create(
{
"name": "Room Type",
"default_code": "Type1",
"pms_property_ids": self.property1,
"class_id": self.room_type_class.id,
"class_id": self.room_type_class1.id,
}
)
self.board_service_room_type = self.env["pms.board.service.room.type"].create(
board_service_room_type = self.env["pms.board.service.room.type"].create(
{
"pms_board_service_id": self.board_service.id,
"pms_room_type_id": self.room_type.id,
"pms_property_ids": self.property1,
"pms_board_service_id": board_service.id,
"pms_room_type_id": room_type.id,
}
)
self.product = self.env["product.product"].create(
{"name": "Product", "pms_property_ids": self.property2}
)
with self.assertRaises(UserError):
# ACT & ASSERT
with self.assertRaises(
UserError, msg="Board service room type line shouldnt be created."
):
self.env["pms.board.service.room.type.line"].create(
{
"pms_board_service_room_type_id": self.board_service_room_type.id,
"product_id": self.product.id,
"pms_board_service_room_type_id": board_service_room_type.id,
"product_id": product.id,
}
)
def test_pms_bsrtl_board_service_line_prop_integrity(self):
"""
Creation of a board service room type line with a specific property,
of board service without property.
"""
# ARRANGE
pms_property2 = self.env["pms.property"].create(
{
"name": "Property 1",
"company_id": self.company1.id,
"default_pricelist_id": self.pricelist1.id,
}
)
product = self.env["product.product"].create(
{"name": "Product", "pms_property_ids": [self.pms_property1.id]}
)
board_service = self.env["pms.board.service"].create(
{
"name": "Board Service",
"default_code": "CB",
}
)
room_type = self.env["pms.room.type"].create(
{
"name": "Room Type",
"default_code": "Type1",
"class_id": self.room_type_class1.id,
}
)
board_service_room_type = self.env["pms.board.service.room.type"].create(
{
"pms_board_service_id": board_service.id,
"pms_room_type_id": room_type.id,
}
)
# ACT & ASSERT
with self.assertRaises(
UserError, msg="Board service line shouldnt be created."
):
self.env["pms.board.service.room.type.line"].create(
{
"product_id": product.id,
"pms_property_ids": [pms_property2.id],
"pms_board_service_room_type_id": board_service_room_type.id,
}
)

View File

@@ -27,7 +27,12 @@ class TestPmsRoom(TestPms):
}
)
def test_check_property_ubication(self):
def test_inconsistency_room_ubication_property(self):
"""
Room property and its ubication properties are inconsistent.
A Room with property that is not included in available properties
for its ubication cannot be created.
"""
# ARRANGE
ubication1 = self.env["pms.ubication"].create(
{
@@ -37,8 +42,12 @@ class TestPmsRoom(TestPms):
],
}
)
# ACT & ARRANGE
with self.assertRaises(UserError, msg="Room has been created and it should't"):
# ACT & ASSERT
with self.assertRaises(
UserError,
msg="The room should not be created if its property is not included "
"in the available properties for its ubication.",
):
self.env["pms.room"].create(
{
"name": "Room 101",
@@ -48,7 +57,44 @@ class TestPmsRoom(TestPms):
}
)
def test_check_property_room_type(self):
def test_consistency_room_ubication_property(self):
"""
Room property and its ubication properties are consistent.
A Room with property included in available properties
for its ubication can be created.
"""
# ARRANGE
ubication1 = self.env["pms.ubication"].create(
{
"name": "UbicationTest",
"pms_property_ids": [
(4, self.pms_property1.id),
],
}
)
# ACT
new_room1 = self.env["pms.room"].create(
{
"name": "Room 101",
"pms_property_id": self.pms_property1.id,
"room_type_id": self.room_type1.id,
"ubication_id": ubication1.id,
}
)
# ASSERT
self.assertIn(
new_room1.pms_property_id,
ubication1.pms_property_ids,
"The room should be created if its property belongs to the availabe"
"properties for its ubication.",
)
def test_inconsistency_room_type_property(self):
"""
Room property and its room type properties are inconsistent.
A Room with property that is not included in available properties
for its room type cannot be created.
"""
# ARRANGE
self.pms_property3 = self.env["pms.property"].create(
{
@@ -58,7 +104,11 @@ class TestPmsRoom(TestPms):
}
)
# ACT & ARRANGE
with self.assertRaises(UserError, msg="Room has been created and it should't"):
with self.assertRaises(
UserError,
msg="The room should not be created if its property is not included "
"in the available properties for its room type.",
):
self.env["pms.room"].create(
{
"name": "Room 101",
@@ -67,9 +117,32 @@ class TestPmsRoom(TestPms):
}
)
@mute_logger("odoo.sql_db")
def test_name_property_unique_01(self):
def test_consistency_room_type_property(self):
"""
Room property and its room type properties are inconsistent.
A Room with property included in available properties
for its room type can be created.
"""
# ARRANGE & ACT
room1 = self.env["pms.room"].create(
{
"name": "Room 101",
"pms_property_id": self.pms_property1.id,
"room_type_id": self.room_type1.id,
}
)
# ASSERT
self.assertIn(
room1.pms_property_id,
self.room_type1.pms_property_ids,
"The room should be created if its property is included "
"in the available properties for its room type.",
)
@mute_logger("odoo.sql_db")
def test_room_name_uniqueness_by_property(self):
"""
Check that there are no two rooms with the same name in the same property
PRE: - room1 'Room 101' exists
- room1 has pms_property1
ACT: - create a new room2
@@ -89,7 +162,9 @@ class TestPmsRoom(TestPms):
)
# ACT & ASSERT
with self.assertRaises(
IntegrityError, msg="Room has been created and it shouldn't"
IntegrityError,
msg="The room should not be created if its name is equal "
"to another room that belongs to the same property.",
):
self.env["pms.room"].create(
{
@@ -99,8 +174,9 @@ class TestPmsRoom(TestPms):
}
)
def test_name_property_unique_02(self):
def test_room_name_duplicated_different_property(self):
"""
Check that two rooms with the same name can exist in multiple properties
PRE: - room1 'Room 101' exists
- room1 has pms_property1
ACT: - create a new room2
@@ -126,4 +202,7 @@ class TestPmsRoom(TestPms):
}
)
except IntegrityError:
self.fail("Duplicated Room found but it shouldn't")
self.fail(
"The room should be created even if its name is equal "
"to another room, but that room not belongs to the same property."
)

View File

@@ -30,8 +30,11 @@ class TestRoomType(TestPms):
}
)
def test_internal_case_01(self):
def test_create_room_type_consistency_company(self):
"""
Create a room type with a company (1) consistent with the company property (1).
Creation should be successful.
PRE: - room_type1 does not exists
ACT: - create a new room_type1 room
- room_type1 has code c1
@@ -40,23 +43,25 @@ class TestRoomType(TestPms):
- room_type1 has company company1
POST: - room_type1 created
"""
# ARRANGE & ACT & ASSERT
try:
# room_type1
self.env["pms.room.type"].create(
{
"name": "Room type 1",
"default_code": "c1",
"pms_property_ids": [(6, 0, [self.pms_property1.id])],
"company_id": self.company1.id,
"class_id": self.room_type_class1.id,
}
)
except ValidationError:
self.fail("Room type not created when it should")
# ARRANGE & ACT
new_room_type = self.env["pms.room.type"].create(
{
"name": "Room type 1",
"default_code": "c1",
"pms_property_ids": [(6, 0, [self.pms_property1.id])],
"company_id": self.company1.id,
"class_id": self.room_type_class1.id,
}
)
# ASSERT
self.assertTrue(new_room_type.id, "Room type not created when it should")
def test_internal_case_02(self):
def test_create_room_type_inconsistency_company(self):
"""
Create a room type with inconsistency between company (1)
and company property (1).
The creation should fail.
PRE: - room_type1 does not exists
ACT: - create a new room_type1 room
- room_type1 has code c1
@@ -81,8 +86,12 @@ class TestRoomType(TestPms):
}
)
def test_internal_case_03(self):
def test_create_room_type_inconsistency_companies(self):
"""
Create a room type with inconsistency between company (1)
and company properties (several).
The creation should fail.
PRE: - room_type1 does not exists
ACT: - create a new room_type1 room
- room_type1 has code c1
@@ -110,10 +119,14 @@ class TestRoomType(TestPms):
}
)
def test_internal_case_04(self):
def test_create_room_type_consistency_companies(self):
"""
Create a room type with consistency between companies (all)
and company properties (2).
Creation should be successful.
PRE: - room_type1 does not exists
ACT: - create a new room_type1 room
ACT: - create a new room_type1
- room_type1 has code c1
- room_type1 has property pms_property1 and pms_property3
- pms_property1 has company company1
@@ -121,26 +134,28 @@ class TestRoomType(TestPms):
- room_type1 has no company
POST: - room_type1 created
"""
# ARRANGE & ACT & ASSERT
try:
# room_type1
self.env["pms.room.type"].create(
{
"name": "Room type 1",
"default_code": "c1",
"pms_property_ids": [
(6, 0, [self.pms_property1.id, self.pms_property3.id])
],
"company_id": False,
"class_id": self.room_type_class1.id,
}
)
except ValidationError:
self.fail("Room type not created when it should")
# ARRANGE & ACT
new_room_type = self.env["pms.room.type"].create(
{
"name": "Room type 1",
"default_code": "c1",
"pms_property_ids": [
(6, 0, [self.pms_property1.id, self.pms_property3.id])
],
"company_id": False,
"class_id": self.room_type_class1.id,
}
)
# ASSERT
self.assertTrue(new_room_type.id, "Room type not created when it should")
# external integrity
def test_external_case_01(self):
def test_create_room_type_inconsistency_all_companies(self):
"""
Create a room type for 1 company and 1 property.
Try to create a room type for all the companies.
The creation should fail.
PRE: - room type room_type1 exists
- room_type1 has code c1
- room_type1 has property pms_property1
@@ -165,7 +180,6 @@ class TestRoomType(TestPms):
"class_id": self.room_type_class1.id,
}
)
# ACT & ASSERT
with self.assertRaises(
ValidationError, msg="The room type has been created and it shouldn't"
@@ -181,8 +195,13 @@ class TestRoomType(TestPms):
}
)
def test_external_case_02(self):
def test_create_room_type_inconsistency_code_company(self):
"""
Create a room type for all the companies and for one property.
Try to create a room type with same code and same property but
for all companies.
The creation should fail.
PRE: - room type room_type1 exists
- room_type1 has code c1
- room_type1 has property pms_property1
@@ -223,8 +242,13 @@ class TestRoomType(TestPms):
}
)
def test_external_case_03(self):
def test_create_room_type_inconsistency_code_companies(self):
"""
Create a room type for 1 property and 1 company.
Try to create a room type with same code and 3 propertys
belonging to 2 different companies.
The creation should fail.
PRE: - room type room_type1 exists
- room_type1 has code c1
- room_type1 has property pms_property1
@@ -250,7 +274,6 @@ class TestRoomType(TestPms):
"class_id": self.room_type_class1.id,
}
)
# ACT & ASSERT
with self.assertRaises(
ValidationError, msg="The room type has been created and it shouldn't"
@@ -276,8 +299,12 @@ class TestRoomType(TestPms):
}
)
def test_single_case_01(self):
def test_get_room_type_by_property_first(self):
"""
Room type exists for all the companies and 2 properties.
Search for property of existing room type.
The method should return the existing room type.
PRE: - room type room_type1 exists
- room_type1 has code c1
- room_type1 with 2 properties pms_property1 and pms_property2
@@ -299,50 +326,19 @@ class TestRoomType(TestPms):
"class_id": self.room_type_class1.id,
}
)
# ACT
room_types = self.env["pms.room.type"].get_room_types_by_property(
self.pms_property1.id, "c1"
)
# ASSERT
self.assertEqual(room_types.id, room_type1.id, "Expected room type not found")
def test_single_case_02(self):
def test_get_room_type_by_property_second(self):
"""
PRE: - room type room_type1 exists
- room_type1 has code c1
- room_type1 with 2 properties pms_property1 and pms_property3
- pms_property1 and pms_property2 have different companies
- pms_property1 have company company1 and pms_property3 have company2
- room_type1 has no company
ACT: - search room type with code c1 and property pms_property1
- pms_property1 has company company1
POST: - only room_type1 room type found
"""
# ARRANGE
room_type1 = self.env["pms.room.type"].create(
{
"name": "Room type 1",
"default_code": "c1",
"pms_property_ids": [
(6, 0, [self.pms_property1.id, self.pms_property3.id])
],
"company_id": False,
"class_id": self.room_type_class1.id,
}
)
Room type exists for all the companies and 2 properties.
Search for 2nd property of existing room type.
The method should return existing room type.
# ACT
room_types = self.env["pms.room.type"].get_room_types_by_property(
self.pms_property1.id, "c1"
)
# ASSERT
self.assertEqual(room_types.id, room_type1.id, "Expected room type not found")
def test_single_case_03(self):
"""
PRE: - room type room_type1 exists
- room_type1 has code c1
- room_type1 with 2 properties pms_property1 and pms_property2
@@ -374,8 +370,13 @@ class TestRoomType(TestPms):
# ASSERT
self.assertFalse(room_types, "Room type found but it should have not found any")
def test_single_case_04(self):
def test_get_room_type_by_property_existing_all_same_company(self):
"""
Room type exists for 1 company and for all properties.
Search for one specific property belonging to same company
as the existing room type.
The method should return existing room type.
PRE: - room type r1 exists
- room_type1 has code c1
- room_type1 properties are null
@@ -394,17 +395,19 @@ class TestRoomType(TestPms):
"class_id": self.room_type_class1.id,
}
)
# ACT
room_types = self.env["pms.room.type"].get_room_types_by_property(
self.pms_property1.id, "c1"
)
# ASSERT
self.assertEqual(room_types.id, room_type1.id, "Expected room type not found")
def test_single_case_05(self):
def test_get_room_type_by_property_existing_all_diff_company(self):
"""
Room type exists for 1 company and all the properties.
Search for property different than existing room type.
The method shouldn't return results.
PRE: - room type room_type1 exists
- room_type1 has code c1
- room_type1 properties are null
@@ -434,8 +437,13 @@ class TestRoomType(TestPms):
self.assertFalse(room_types, "Room type found but it should have not found any")
# tests with more than one room type
def test_multiple_case_01(self):
def test_get_room_type_by_property_existing_several_match_prop(self):
"""
Room type 1 exists for all companies and 2 properties.
Room type 2 exists for all companies and properties.
Search for same property as one of the 1st room type created.
The method should return the 1st room type created.
PRE: - room type room_type1 exists
- room_type1 has code c1
- room_type1 with 2 properties pms_property1 and pms_property2
@@ -480,8 +488,14 @@ class TestRoomType(TestPms):
# ASSERT
self.assertEqual(room_types.id, room_type1.id, "Expected room type not found")
def test_multiple_case_02(self):
def test_get_room_type_by_property_diff_company(self):
"""
Room type 1 exists for all companies and one property.
Room type 2 exists for all companies and properties.
Search for property different than the 1st room type created
and belonging to different company.
The method should return the 2nd room type created.
PRE: - room type r1 exists
- room_type1 has code c1
- room_type1 has property pms_property1
@@ -524,8 +538,14 @@ class TestRoomType(TestPms):
# ASSERT
self.assertEqual(room_types.id, room_type2.id, "Expected room type not found")
def test_multiple_case_03(self):
def test_get_room_type_by_property_same_company(self):
"""
Room type 1 exists for all companies and one property.
Room type 2 exists for all companies and properties.
Search for property different than the 1st room type created
and belonging to same company.
The method should return the 2nd room type created.
PRE: - room type room_type1 exists
- room_type1 has code c1
- room_type1 has property pms_property1
@@ -568,8 +588,14 @@ class TestRoomType(TestPms):
# ASSERT
self.assertEqual(room_types.id, room_type2.id, "Expected room type not found")
def test_multiple_case_04(self):
def test_get_room_type_by_property_same_company_prop_not_found(self):
"""
Room type 1 exists for all companies and one property.
Room type 2 exists for one company and for all properties.
Search for property different than the
1st room type created but belonging to same company.
The method shouldn't return results.
PRE: - room_type1 exists
- room_type1 has code c1
- room_type1 has property pms_property1
@@ -613,8 +639,14 @@ class TestRoomType(TestPms):
# ASSERT
self.assertFalse(room_types, "Room type found but it should have not found any")
def test_multiple_case_05(self):
def test_get_room_type_by_property_same_company_prop(self):
"""
Room type 1 exists for all companies and for one property.
Room type 2 exists for one company and for all properties.
Search for property belonging to the same company as
2nd room type created.
The method should return 2nd existing room type.
PRE: - room_type1 exists
- room_type1 has code c1
- room_type1 has property pms_property1
@@ -648,7 +680,6 @@ class TestRoomType(TestPms):
"class_id": self.room_type_class1.id,
}
)
# ACT
room_types = self.env["pms.room.type"].get_room_types_by_property(
self.pms_property3.id, "c1"
@@ -657,8 +688,15 @@ class TestRoomType(TestPms):
# ASSERT
self.assertEqual(room_types.id, room_type2.id, "Expected room type not found")
def test_multiple_case_06(self):
def test_get_room_type_by_property_diff_company_prop(self):
"""
Room type 1 exists for all companies and for one property.
Room type 2 exists for one company and for all properties.
Room type 3 exists for all companies and for all properties.
Search for property belonging to a different company than
the 2nd room type created.
The method should return 3rd room type.
PRE: - room type r1 exists
- room_type1 has code c1
- room_type1 has property pms_property1
@@ -715,7 +753,12 @@ class TestRoomType(TestPms):
# ASSERT
self.assertEqual(room_types.id, room_type3.id, "Expected room type not found")
def test_check_property_room_type_class(self):
def test_rooom_type_creation_inconsistency_class(self):
"""
Create a rooom type class belonging to one property.
Create a room type belonging to another property.
Room type creation should fail.
"""
# ARRANGE
room_type_class = self.env["pms.room.type.class"].create(
{
@@ -742,41 +785,72 @@ class TestRoomType(TestPms):
)
room_type1.pms_property_ids = [(4, self.pms_property1.id)]
# TODO: pending multi property PR
def test_rooom_type_creation_consistency_class(self):
"""
Create a rooom type class belonging to one property.
Create a room type belonging to same property.
Room type creation should be successful.
"""
# ARRANGE
room_type_class = self.env["pms.room.type.class"].create(
{
"name": "Room Type Class",
"default_code": "ROOM",
"pms_property_ids": [
(4, self.pms_property2.id),
],
},
)
# ACT
new_room_type = self.env["pms.room.type"].create(
{
"name": "Room Type",
"default_code": "c1",
"class_id": room_type_class.id,
"pms_property_ids": [
(4, self.pms_property2.id),
],
}
)
# ASSERT
self.assertTrue(new_room_type.id, "Room type creation should be successful.")
# def test_check_board_service_property_integrity(self):
#
# self.room_type_class = self.env["pms.room.type.class"].create(
# {"name": "Room Type Class", "default_code": "SIN1"}
# )
# self.room_type = self.env["pms.room.type"].create(
# {
# "name": "Room Type",
# "default_code": "Type1",
# "pms_property_ids": self.p3,
# "class_id": self.room_type_class.id,
# }
# )
# self.board_service = self.env["pms.board.service"].create(
# {
# "name": "Board Service",
# }
# )
# with self.assertRaises(ValidationError):
# self.env["pms.board.service.room.type"].create(
# {
# "pms_board_service_id": self.board_service.id,
# "pms_room_type_id": self.room_type.id,
# "pricelist_id": self.env.ref("product.list0").id,
# "pms_property_ids": self.p4,
# }
# )
def test_check_board_service_property_integrity(self):
# ARRANGE
room_type = self.env["pms.room.type"].create(
{
"name": "Room Type",
"default_code": "Type1",
"pms_property_ids": self.pms_property1,
"class_id": self.room_type_class1.id,
}
)
board_service = self.env["pms.board.service"].create(
{
"name": "Board service 1",
"default_code": "c1",
"pms_property_ids": self.pms_property1,
}
)
# ACT & ASSERT
with self.assertRaises(UserError, msg="Board service created and shouldn't."):
self.env["pms.board.service.room.type"].create(
{
"pms_board_service_id": board_service.id,
"pms_room_type_id": room_type.id,
"pms_property_ids": self.pms_property2,
}
)
def test_check_amenities_property_integrity(self):
self.amenity1 = self.env["pms.amenity"].create(
{"name": "Amenity", "pms_property_ids": self.pms_property1}
)
with self.assertRaises(UserError):
# ACT & ASSERT
with self.assertRaises(
UserError,
msg="Shouldn't create room type with amenities belonging to other properties",
):
self.env["pms.room.type"].create(
{
"name": "Room Type",
@@ -786,3 +860,26 @@ class TestRoomType(TestPms):
"room_amenity_ids": [self.amenity1.id],
}
)
def test_rooom_type_creation_consistency_amenity(self):
"""
Create an amenity belonging to one property.
Create a room type belonging to same property.
Room type creation should be successful.
"""
# ARRANGE
self.amenity1 = self.env["pms.amenity"].create(
{"name": "Amenity", "pms_property_ids": self.pms_property1}
)
# ACT
new_room_type = self.env["pms.room.type"].create(
{
"name": "Room Type",
"default_code": "Type1",
"class_id": self.room_type_class1.id,
"pms_property_ids": [self.pms_property1.id],
"room_amenity_ids": [self.amenity1.id],
}
)
# ASSERT
self.assertTrue(new_room_type.id, "Room type creation should be successful.")

View File

@@ -1,23 +1,26 @@
import datetime
from freezegun import freeze_time
from odoo.exceptions import ValidationError
from .common import TestPms
@freeze_time("2010-01-01")
class TestPmsSaleChannel(TestPms):
def test_not_agency_as_agency(self):
def test_reservation_with_invalid_agency(self):
"""
Reservation with an invalid agency cannot be created.
Create a partner that is not an agency and create
a reservation with that partner as an agency.
"""
# ARRANGE
PmsReservation = self.env["pms.reservation"]
not_agency = self.env["res.partner"].create(
{"name": "partner1", "is_agency": False}
)
# ACT & ASSERT
with self.assertRaises(ValidationError), self.cr.savepoint():
with self.assertRaises(
ValidationError, msg="Reservation with an invalid agency cannot be created."
):
PmsReservation.create(
{
"checkin": datetime.datetime.now(),
@@ -27,30 +30,12 @@ class TestPmsSaleChannel(TestPms):
}
)
def test_channel_type_id_only_directs(self):
# ARRANGE
PmsReservation = self.env["pms.reservation"]
PmsSaleChannel = self.env["pms.sale.channel"]
# ACT
sale_channel1 = PmsSaleChannel.create({"channel_type": "direct"})
partner1 = self.env["res.partner"].create({"name": "partner1"})
reservation1 = PmsReservation.create(
{
"checkin": datetime.datetime.now(),
"checkout": datetime.datetime.now() + datetime.timedelta(days=3),
"channel_type_id": sale_channel1.id,
"partner_id": partner1.id,
"pms_property_id": self.pms_property1.id,
}
)
# ASSERT
self.assertEqual(
reservation1.channel_type_id.channel_type,
"direct",
"Sale channel is not direct",
)
def test_agency_id_is_agency(self):
def test_reservation_with_valid_agency(self):
"""
Reservation with a valid agency must be created.
Create a partner that is an agency and create
a reservation with that partner as an agency can be created.
"""
# ARRANGE
PmsReservation = self.env["pms.reservation"]
PmsSaleChannel = self.env["pms.sale.channel"]
@@ -73,18 +58,83 @@ class TestPmsSaleChannel(TestPms):
"pms_property_id": self.pms_property1.id,
}
)
# ASSERT
self.assertEqual(
reservation1.agency_id.is_agency,
True,
"Agency_id doesn't correspond to an agency",
"Reservation with a valid agency should be created.",
)
def test_sale_channel_id_only_indirect(self):
def test_reservation_with_partner_direct(self):
"""
Reservation create with partner (no agency) and sale channel
'direct' must be set reservation sale channel to 'direct'.
A reservation with partner and sale channel as 'direct'
should be created.
"""
# ARRANGE
PmsReservation = self.env["pms.reservation"]
PmsSaleChannel = self.env["pms.sale.channel"]
# ACT
sale_channel1 = PmsSaleChannel.create({"channel_type": "direct"})
partner1 = self.env["res.partner"].create({"name": "partner1"})
reservation1 = PmsReservation.create(
{
"checkin": datetime.datetime.now(),
"checkout": datetime.datetime.now() + datetime.timedelta(days=3),
"channel_type_id": sale_channel1.id,
"partner_id": partner1.id,
"pms_property_id": self.pms_property1.id,
}
)
# ASSERT
self.assertEqual(
reservation1.channel_type_id.channel_type,
"direct",
"A reservation with partner and sale channel as 'direct'"
"should be created a 'direct' reservation.",
)
def test_reservation_with_partner_indirect(self):
"""
Reservation create with partner (no agency) and sale channel
'indirect' must be set reservation sale channel to 'direct'.
A reservation with partner and sale channel as 'direct'
should be created.
"""
# ARRANGE
PmsReservation = self.env["pms.reservation"]
PmsSaleChannel = self.env["pms.sale.channel"]
# ACT
sale_channel1 = PmsSaleChannel.create({"channel_type": "indirect"})
partner1 = self.env["res.partner"].create({"name": "partner1"})
reservation1 = PmsReservation.create(
{
"checkin": datetime.datetime.now(),
"checkout": datetime.datetime.now() + datetime.timedelta(days=3),
"channel_type_id": sale_channel1.id,
"partner_id": partner1.id,
"pms_property_id": self.pms_property1.id,
}
)
# ASSERT
self.assertEqual(
reservation1.channel_type_id.channel_type,
"indirect",
"A reservation with partner and sale channel as 'direct'"
"should be created a 'indirect' reservation.",
)
def test_create_agency_with_sale_channel_indirect(self):
"""
Agency should be created as partner setted as 'agency'
and its sale channel as 'indirect'.
"""
# ARRANGE
PmsSaleChannel = self.env["pms.sale.channel"]
saleChannel1 = PmsSaleChannel.create({"channel_type": "indirect"})
# ACT
agency1 = self.env["res.partner"].create(
{"name": "example", "is_agency": True, "sale_channel_id": saleChannel1.id}
)
@@ -92,12 +142,37 @@ class TestPmsSaleChannel(TestPms):
self.assertEqual(
agency1.sale_channel_id.channel_type,
"indirect",
"An agency should be a indirect channel",
"An agency should be an indirect channel.",
)
def test_agency_without_sale_channel_id(self):
def test_create_agency_with_sale_channel_direct(self):
"""
Agency shouldnt be created as partner setted as 'agency'
and its sale channel as 'direct'.
"""
# ARRANGE
PmsSaleChannel = self.env["pms.sale.channel"]
saleChannel1 = PmsSaleChannel.create({"channel_type": "direct"})
# ACT & ASSERT
with self.assertRaises(
ValidationError, msg="An agency should be an indirect channel."
):
self.env["res.partner"].create(
{
"name": "example",
"is_agency": True,
"sale_channel_id": saleChannel1.id,
}
)
def test_create_agency_without_sale_channel(self):
"""
Agency creation should fails if there's no sale channel.
"""
# ARRANGE & ACT & ASSERT
with self.assertRaises(ValidationError), self.cr.savepoint():
with self.assertRaises(
ValidationError, msg="Agency should not be created without sale channel."
):
self.env["res.partner"].create(
{"name": "example", "is_agency": True, "sale_channel_id": None}
)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,304 @@
import datetime
from odoo import fields
from odoo.exceptions import ValidationError
from .common import TestPms
class TestProductTemplate(TestPms):
def setUp(self):
super().setUp()
self.room_type = self.env["pms.room.type"].create(
{
"name": "Room type test",
"default_code": "DBL_Test",
"class_id": self.room_type_class1.id,
}
)
self.room = self.env["pms.room"].create(
{
"pms_property_id": self.pms_property1.id,
"name": "Room test",
"room_type_id": self.room_type.id,
"capacity": 2,
}
)
self.partner = self.env["res.partner"].create({"name": "partner1"})
self.board_service = self.env["pms.board.service"].create(
{
"name": "Board service test",
"default_code": "BST",
}
)
def test_bs_consumed_on_after(self):
"""
Create a one day reservation with a board service configured to
consume after reservation night.
Date of service line with consumed on 'after' should match checkout date.
"""
# ARRANGE
product = self.env["product.product"].create(
{
"name": "Product test",
"per_day": True,
"consumed_on": "after",
}
)
self.env["pms.board.service.line"].create(
{
"product_id": product.id,
"pms_board_service_id": self.board_service.id,
}
)
board_service_room_type = self.env["pms.board.service.room.type"].create(
{
"pms_room_type_id": self.room_type.id,
"pms_board_service_id": self.board_service.id,
}
)
date_checkin = fields.date.today()
date_checkout = fields.date.today() + datetime.timedelta(days=1)
# ACT
reservation = self.env["pms.reservation"].create(
{
"checkin": date_checkin,
"checkout": date_checkout,
"room_type_id": self.room_type.id,
"pms_property_id": self.pms_property1.id,
"partner_id": self.partner.id,
"board_service_room_id": board_service_room_type.id,
}
)
# ASSERT
self.assertEqual(
reservation.service_ids.service_line_ids.date,
date_checkout,
"Date of service line with consumed on 'after' should match checkout date.",
)
def test_bs_consumed_on_before(self):
"""
Create a one day reservation with a board service configured to
consume before reservation night.
Date of service line with consumed on 'before' should match checkin date.
"""
# ARRANGE
product = self.env["product.product"].create(
{
"name": "Product test",
"per_day": True,
"consumed_on": "before",
}
)
self.env["pms.board.service.line"].create(
{
"product_id": product.id,
"pms_board_service_id": self.board_service.id,
}
)
board_service_room_type = self.env["pms.board.service.room.type"].create(
{
"pms_room_type_id": self.room_type.id,
"pms_board_service_id": self.board_service.id,
}
)
date_checkin = fields.date.today()
date_checkout = fields.date.today() + datetime.timedelta(days=1)
# ACT
reservation = self.env["pms.reservation"].create(
{
"checkin": date_checkin,
"checkout": date_checkout,
"room_type_id": self.room_type.id,
"pms_property_id": self.pms_property1.id,
"partner_id": self.partner.id,
"board_service_room_id": board_service_room_type.id,
}
)
# ASSERT
self.assertEqual(
reservation.service_ids.service_line_ids.date,
date_checkin,
"Date of service line with consumed on 'before' should match checkin date.",
)
def test_bs_daily_limit_equal(self):
"""
Create a one day reservation with a board service configured with
daily limit = 2 and capacity = 2
Reservation should created succesfully.
"""
# ARRANGE
product = self.env["product.product"].create(
{
"name": "Product test",
"per_day": True,
"daily_limit": 2,
"per_person": True,
}
)
self.env["pms.board.service.line"].create(
{
"product_id": product.id,
"pms_board_service_id": self.board_service.id,
}
)
board_service_room_type = self.env["pms.board.service.room.type"].create(
{
"pms_room_type_id": self.room_type.id,
"pms_board_service_id": self.board_service.id,
}
)
date_checkin = fields.date.today()
date_checkout = fields.date.today() + datetime.timedelta(days=1)
# ACT
reservation = self.env["pms.reservation"].create(
{
"checkin": date_checkin,
"checkout": date_checkout,
"room_type_id": self.room_type.id,
"pms_property_id": self.pms_property1.id,
"partner_id": self.partner.id,
"board_service_room_id": board_service_room_type.id,
}
)
# ASSERT
self.assertEqual(
reservation.service_ids.service_line_ids.day_qty,
self.room.capacity,
"The reservation should have been created.",
)
def test_bs_daily_limit_lower(self):
"""
Create a one day reservation with a board service configured with
daily limit = 2 and capacity = 1
Reservation should created succesfully.
"""
# ARRANGE
self.room.capacity = 1
product = self.env["product.product"].create(
{
"name": "Product test",
"per_day": True,
"daily_limit": 2,
"per_person": True,
}
)
self.env["pms.board.service.line"].create(
{
"product_id": product.id,
"pms_board_service_id": self.board_service.id,
}
)
board_service_room_type = self.env["pms.board.service.room.type"].create(
{
"pms_room_type_id": self.room_type.id,
"pms_board_service_id": self.board_service.id,
}
)
date_checkin = fields.date.today()
date_checkout = fields.date.today() + datetime.timedelta(days=1)
# ACT
reservation = self.env["pms.reservation"].create(
{
"checkin": date_checkin,
"checkout": date_checkout,
"room_type_id": self.room_type.id,
"pms_property_id": self.pms_property1.id,
"partner_id": self.partner.id,
"board_service_room_id": board_service_room_type.id,
}
)
# ASSERT
# self.assertTrue(reservation, "The reservation should have been created.")
# ASSERT
self.assertEqual(
reservation.service_ids.service_line_ids.day_qty,
self.room.capacity,
"The reservation should have been created.",
)
def test_bs_daily_limit_greater(self):
"""
Create a one day reservation with a board service configured with
daily limit = 1 and capacity = 2
Reservation creation should fail.
"""
# ARRANGE
product = self.env["product.product"].create(
{
"name": "Product test",
"per_day": True,
"type": "service",
"daily_limit": 1,
"list_price": 15.0,
"per_person": True,
}
)
self.env["pms.board.service.line"].create(
{
"product_id": product.id,
"pms_board_service_id": self.board_service.id,
}
)
board_service_room_type = self.env["pms.board.service.room.type"].create(
{
"pms_room_type_id": self.room_type.id,
"pms_board_service_id": self.board_service.id,
}
)
date_checkin = fields.date.today()
date_checkout = fields.date.today() + datetime.timedelta(days=1)
# ACT & ASSERT
with self.assertRaises(
ValidationError, msg="Reservation created but it shouldn't"
):
self.env["pms.reservation"].create(
{
"checkin": date_checkin,
"checkout": date_checkout,
"room_type_id": self.room_type.id,
"pms_property_id": self.pms_property1.id,
"partner_id": self.partner.id,
"board_service_room_id": board_service_room_type.id,
"adults": 2,
}
)
# TODO: Review this test
def _test_bs_is_extra_bed(self):
# ARRANGE
product = self.env["product.product"].create(
{
"name": "Product test",
"per_day": True,
"consumed_on": "after",
"is_extra_bed": True,
}
)
self.room.capacity = 1
extra_bed_service = self.env["pms.service"].create(
{
"is_board_service": False,
"product_id": product.id,
}
)
self.room.extra_beds_allowed = 1
# ACT
reservation = self.env["pms.reservation"].create(
{
"checkin": fields.date.today(),
"checkout": fields.date.today() + datetime.timedelta(days=1),
"room_type_id": self.room_type.id,
"pms_property_id": self.pms_property1.id,
"partner_id": self.partner.id,
"service_ids": [extra_bed_service.id],
}
)
reservation._check_adults()
reservation.flush()
# TODO: pending tests (need review) -> per_day, per_person (with board service?)