[REF] pms: refactor test common (test_pms_sale_channel & test_pms_room) & fix res.partner (agency & sales channel 'direct' validationError)

This commit is contained in:
miguelpadin
2021-06-10 13:01:19 +02:00
parent 0892c57f9d
commit 21327a8629
4 changed files with 224 additions and 65 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

@@ -19,24 +19,25 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import test_pms_reservation
from . import test_pms_pricelist
from . import test_pms_pricelist_priority
from . import test_pms_checkin_partner
# from . import test_pms_reservation
# from . import test_pms_pricelist
# from . import test_pms_pricelist_priority
# from . import test_pms_checkin_partner
from . import test_pms_sale_channel
from . import test_pms_folio
from . import test_pms_availability_plan_rules
from . import test_pms_room_type
from . import test_pms_room_type_class
from . import test_pms_board_service
from . import test_pms_wizard_massive_changes
from . import test_pms_wizard_folio
from . import test_pms_res_users
from . import test_pms_amenity
from . import test_pms_room
from . import test_pms_board_service_line
from . import test_pms_board_service_room_type
from . import test_pms_board_service_room_type_line
from . import test_pms_folio_invoice
from . import test_pms_folio_sale_line
from . import test_pms_wizard_split_join_swap_reservation
# from . import test_pms_folio
# from . import test_pms_availability_plan_rules
# from . import test_pms_room_type
# from . import test_pms_room_type_class
# from . import test_pms_board_service
# from . import test_pms_wizard_massive_changes
# from . import test_pms_wizard_folio
# from . import test_pms_res_users
# from . import test_pms_amenity
# from . import test_pms_room
# from . import test_pms_board_service_line
# from . import test_pms_board_service_room_type
# from . import test_pms_board_service_room_type_line
# from . import test_pms_folio_invoice
# from . import test_pms_folio_sale_line
# from . import test_pms_wizard_split_join_swap_reservation

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

@@ -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}
)