mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP] pms: refactoring and adding checkin flow tests
This commit is contained in:
@@ -1,49 +1,98 @@
|
||||
import datetime
|
||||
import logging
|
||||
|
||||
from freezegun import freeze_time
|
||||
|
||||
from odoo import fields
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.tests import common
|
||||
|
||||
from .common import TestPms
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@freeze_time("2012-01-14")
|
||||
class TestPmsCheckinPartner(common.SavepointCase):
|
||||
@classmethod
|
||||
def arrange_single_checkin(cls):
|
||||
# Arrange for one checkin on one reservation
|
||||
cls.host1 = cls.env["res.partner"].create(
|
||||
class TestPmsCheckinPartner(TestPms):
|
||||
@freeze_time("2012-01-14")
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.room_type1 = self.env["pms.room.type"].create(
|
||||
{
|
||||
"pms_property_ids": [self.pms_property1.id],
|
||||
"name": "Triple",
|
||||
"default_code": "TRP",
|
||||
"class_id": self.room_type_class1.id,
|
||||
}
|
||||
)
|
||||
self.room1 = self.env["pms.room"].create(
|
||||
{
|
||||
"pms_property_id": self.pms_property1.id,
|
||||
"name": "Triple 101",
|
||||
"room_type_id": self.room_type1.id,
|
||||
"capacity": 3,
|
||||
}
|
||||
)
|
||||
self.room1_2 = self.env["pms.room"].create(
|
||||
{
|
||||
"pms_property_id": self.pms_property1.id,
|
||||
"name": "Triple 111",
|
||||
"room_type_id": self.room_type1.id,
|
||||
"capacity": 3,
|
||||
}
|
||||
)
|
||||
self.room1_3 = self.env["pms.room"].create(
|
||||
{
|
||||
"pms_property_id": self.pms_property1.id,
|
||||
"name": "Triple 222",
|
||||
"room_type_id": self.room_type1.id,
|
||||
"capacity": 3,
|
||||
}
|
||||
)
|
||||
|
||||
self.host1 = self.env["res.partner"].create(
|
||||
{
|
||||
"name": "Miguel",
|
||||
"phone": "654667733",
|
||||
"email": "miguel@example.com",
|
||||
"birthdate_date": "1995-12-10",
|
||||
"gender": "male",
|
||||
}
|
||||
)
|
||||
self.id_category = self.env["res.partner.id_category"].create(
|
||||
{"name": "DNI", "code": "D"}
|
||||
)
|
||||
self.env["res.partner.id_number"].create(
|
||||
{
|
||||
"category_id": self.id_category.id,
|
||||
"name": "30065089H",
|
||||
"valid_from": datetime.date.today(),
|
||||
"partner_id": self.host1.id,
|
||||
}
|
||||
)
|
||||
reservation_vals = {
|
||||
"checkin": "2012-01-14",
|
||||
"checkout": "2012-01-17",
|
||||
"room_type_id": cls.env.ref("pms.pms_room_type_3").id,
|
||||
"partner_id": cls.host1.id,
|
||||
"checkin": datetime.date.today(),
|
||||
"checkout": datetime.date.today() + datetime.timedelta(days=3),
|
||||
"room_type_id": self.room_type1.id,
|
||||
"partner_id": self.host1.id,
|
||||
"adults": 3,
|
||||
"pms_property_id": cls.env.ref("pms.main_pms_property").id,
|
||||
"pms_property_id": self.pms_property1.id,
|
||||
}
|
||||
demo_user = cls.env.ref("base.user_demo")
|
||||
cls.reservation_1 = (
|
||||
cls.env["pms.reservation"].with_user(demo_user).create(reservation_vals)
|
||||
)
|
||||
cls.checkin1 = cls.env["pms.checkin.partner"].create(
|
||||
self.reservation_1 = self.env["pms.reservation"].create(reservation_vals)
|
||||
self.checkin1 = self.env["pms.checkin.partner"].create(
|
||||
{
|
||||
"partner_id": cls.host1.id,
|
||||
"reservation_id": cls.reservation_1.id,
|
||||
"partner_id": self.host1.id,
|
||||
"reservation_id": self.reservation_1.id,
|
||||
}
|
||||
)
|
||||
|
||||
def test_auto_create_checkins(self):
|
||||
"""
|
||||
Check that as many checkin_partners are created as there
|
||||
adults on the reservation
|
||||
|
||||
Reservation has three adults
|
||||
"""
|
||||
|
||||
# ACTION
|
||||
self.arrange_single_checkin()
|
||||
checkins_count = len(self.reservation_1.checkin_partner_ids)
|
||||
# ASSERT
|
||||
self.assertEqual(
|
||||
@@ -52,17 +101,24 @@ class TestPmsCheckinPartner(common.SavepointCase):
|
||||
"the automatic partner checkin was not created successful",
|
||||
)
|
||||
|
||||
@freeze_time("2012-01-14")
|
||||
def test_auto_unlink_checkins(self):
|
||||
|
||||
# ARRANGE
|
||||
self.arrange_single_checkin()
|
||||
|
||||
# ACTION
|
||||
host2 = self.env["res.partner"].create(
|
||||
{
|
||||
"name": "Carlos",
|
||||
"phone": "654667733",
|
||||
"email": "carlos@example.com",
|
||||
"birthdate_date": "1995-12-10",
|
||||
"gender": "male",
|
||||
}
|
||||
)
|
||||
self.env["res.partner.id_number"].create(
|
||||
{
|
||||
"category_id": self.id_category.id,
|
||||
"name": "30065089H",
|
||||
"valid_from": datetime.date.today(),
|
||||
"partner_id": host2.id,
|
||||
}
|
||||
)
|
||||
self.reservation_1.checkin_partner_ids = [
|
||||
@@ -85,19 +141,23 @@ class TestPmsCheckinPartner(common.SavepointCase):
|
||||
)
|
||||
|
||||
def test_onboard_checkin(self):
|
||||
|
||||
# ARRANGE
|
||||
self.arrange_single_checkin()
|
||||
"""
|
||||
Check that the reservation cannot be onboard because
|
||||
checkin_partner data are incomplete and not have onboard status
|
||||
"""
|
||||
|
||||
# ACT & ASSERT
|
||||
with self.assertRaises(ValidationError), self.cr.savepoint():
|
||||
with self.assertRaises(
|
||||
ValidationError, msg="Reservation state cannot be 'onboard'"
|
||||
):
|
||||
self.reservation_1.state = "onboard"
|
||||
|
||||
@freeze_time("2012-01-14")
|
||||
def test_onboard_reservation(self):
|
||||
|
||||
# ARRANGE
|
||||
self.arrange_single_checkin()
|
||||
|
||||
"""
|
||||
Check that reservation state is onboard as the checkin day is
|
||||
today and checkin_partners data are complete
|
||||
"""
|
||||
# ACT
|
||||
self.checkin1.action_on_board()
|
||||
|
||||
@@ -108,24 +168,38 @@ class TestPmsCheckinPartner(common.SavepointCase):
|
||||
"the reservation checkin was not successful",
|
||||
)
|
||||
|
||||
def test_premature_checkin(self):
|
||||
@freeze_time("2012-01-14")
|
||||
def test_late_checkin(self):
|
||||
"""
|
||||
Check that cannot change checkin_partner state to onboard if
|
||||
it's not yet checkin day
|
||||
"""
|
||||
|
||||
# ARRANGE
|
||||
self.arrange_single_checkin()
|
||||
self.reservation_1.write(
|
||||
{
|
||||
"checkin": "2012-01-15",
|
||||
"checkin": datetime.date.today() + datetime.timedelta(days=1),
|
||||
}
|
||||
)
|
||||
# ACT & ASSERT
|
||||
with self.assertRaises(ValidationError), self.cr.savepoint():
|
||||
with self.assertRaises(ValidationError, msg="Cannot do checkin onboard"):
|
||||
self.checkin1.action_on_board()
|
||||
|
||||
def test_late_checkin(self):
|
||||
@freeze_time("2012-01-13")
|
||||
def test_premature_checkin(self):
|
||||
"""
|
||||
When host arrives late anad has already passed the checkin day,
|
||||
the arrival date is updated up to that time.
|
||||
|
||||
In this case checkin day was 2012-01-14 and the host arrived a day later
|
||||
so the arrival date is updated to that time
|
||||
|
||||
"""
|
||||
|
||||
# ARRANGE
|
||||
self.arrange_single_checkin()
|
||||
self.reservation_1.write(
|
||||
{
|
||||
"checkin": "2012-01-13",
|
||||
"checkin": datetime.date.today(),
|
||||
}
|
||||
)
|
||||
|
||||
@@ -139,14 +213,29 @@ class TestPmsCheckinPartner(common.SavepointCase):
|
||||
"the late checkin has problems",
|
||||
)
|
||||
|
||||
@freeze_time("2012-01-14")
|
||||
def test_too_many_people_checkin(self):
|
||||
"""
|
||||
Reservation cannot have more checkin_partners than adults who have
|
||||
Reservation has three adults and cannot have four checkin_partner
|
||||
"""
|
||||
|
||||
# ARRANGE
|
||||
self.arrange_single_checkin()
|
||||
host2 = self.env["res.partner"].create(
|
||||
{
|
||||
"name": "Carlos",
|
||||
"phone": "654667733",
|
||||
"email": "carlos@example.com",
|
||||
"birthdate_date": "1995-12-10",
|
||||
"gender": "male",
|
||||
}
|
||||
)
|
||||
self.env["res.partner.id_number"].create(
|
||||
{
|
||||
"category_id": self.id_category.id,
|
||||
"name": "30065089H",
|
||||
"valid_from": datetime.date.today(),
|
||||
"partner_id": host2.id,
|
||||
}
|
||||
)
|
||||
host3 = self.env["res.partner"].create(
|
||||
@@ -154,6 +243,16 @@ class TestPmsCheckinPartner(common.SavepointCase):
|
||||
"name": "Enmanuel",
|
||||
"phone": "654667733",
|
||||
"email": "enmanuel@example.com",
|
||||
"birthdate_date": "1995-12-10",
|
||||
"gender": "male",
|
||||
}
|
||||
)
|
||||
self.env["res.partner.id_number"].create(
|
||||
{
|
||||
"category_id": self.id_category.id,
|
||||
"name": "30065089H",
|
||||
"valid_from": datetime.date.today(),
|
||||
"partner_id": host3.id,
|
||||
}
|
||||
)
|
||||
host4 = self.env["res.partner"].create(
|
||||
@@ -161,6 +260,16 @@ class TestPmsCheckinPartner(common.SavepointCase):
|
||||
"name": "Enrique",
|
||||
"phone": "654667733",
|
||||
"email": "enrique@example.com",
|
||||
"birthdate_date": "1995-12-10",
|
||||
"gender": "male",
|
||||
}
|
||||
)
|
||||
self.env["res.partner.id_number"].create(
|
||||
{
|
||||
"category_id": self.id_category.id,
|
||||
"name": "30065089H",
|
||||
"valid_from": datetime.date.today(),
|
||||
"partner_id": host4.id,
|
||||
}
|
||||
)
|
||||
self.env["pms.checkin.partner"].create(
|
||||
@@ -176,7 +285,10 @@ class TestPmsCheckinPartner(common.SavepointCase):
|
||||
}
|
||||
)
|
||||
# ACT & ASSERT
|
||||
with self.assertRaises(ValidationError), self.cr.savepoint():
|
||||
with self.assertRaises(
|
||||
ValidationError,
|
||||
msg="Reservation cannot have more checkin_partner than adults who have",
|
||||
):
|
||||
self.reservation_1.write(
|
||||
{
|
||||
"checkin_partner_ids": [
|
||||
@@ -191,89 +303,49 @@ class TestPmsCheckinPartner(common.SavepointCase):
|
||||
}
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def arrange_folio_reservations(cls):
|
||||
# Arrange on one folio with 3 reservations
|
||||
demo_user = cls.env.ref("base.user_demo")
|
||||
cls.host1 = cls.env["res.partner"].create(
|
||||
{
|
||||
"name": "Miguel",
|
||||
"phone": "654667733",
|
||||
"email": "miguel@example.com",
|
||||
}
|
||||
)
|
||||
cls.host2 = cls.env["res.partner"].create(
|
||||
@freeze_time("2012-01-14")
|
||||
def test_count_pending_arrival_persons(self):
|
||||
"""
|
||||
After making onboard of two of the three checkin_partners,
|
||||
one must remain pending arrival, that is a ratio of two thirds
|
||||
"""
|
||||
|
||||
# ARRANGE
|
||||
self.host2 = self.env["res.partner"].create(
|
||||
{
|
||||
"name": "Carlos",
|
||||
"phone": "654667733",
|
||||
"email": "carlos@example.com",
|
||||
"birthdate_date": "1995-12-10",
|
||||
"gender": "male",
|
||||
}
|
||||
)
|
||||
cls.host3 = cls.env["res.partner"].create(
|
||||
self.env["res.partner.id_number"].create(
|
||||
{
|
||||
"category_id": self.id_category.id,
|
||||
"name": "30065089H",
|
||||
"valid_from": datetime.date.today(),
|
||||
"partner_id": self.host2.id,
|
||||
}
|
||||
)
|
||||
self.host3 = self.env["res.partner"].create(
|
||||
{
|
||||
"name": "Enmanuel",
|
||||
"phone": "654667733",
|
||||
"email": "enmanuel@example.com",
|
||||
"birthdate_date": "1995-12-10",
|
||||
"gender": "male",
|
||||
}
|
||||
)
|
||||
cls.host4 = cls.env["res.partner"].create(
|
||||
self.env["res.partner.id_number"].create(
|
||||
{
|
||||
"name": "Enrique",
|
||||
"phone": "654667733",
|
||||
"email": "enrique@example.com",
|
||||
"category_id": self.id_category.id,
|
||||
"name": "30065089H",
|
||||
"valid_from": datetime.date.today(),
|
||||
"partner_id": self.host3.id,
|
||||
}
|
||||
)
|
||||
folio_vals = {
|
||||
"partner_id": cls.host1.id,
|
||||
}
|
||||
cls.folio_1 = cls.env["pms.folio"].with_user(demo_user).create(folio_vals)
|
||||
reservation1_vals = {
|
||||
"checkin": "2012-01-14",
|
||||
"checkout": "2012-01-17",
|
||||
"room_type_id": cls.env.ref("pms.pms_room_type_3").id,
|
||||
"partner_id": cls.host1.id,
|
||||
"adults": 3,
|
||||
"pms_property_id": cls.env.ref("pms.main_pms_property").id,
|
||||
"folio_id": cls.folio_1.id,
|
||||
}
|
||||
reservation2_vals = {
|
||||
"checkin": "2012-01-14",
|
||||
"checkout": "2012-01-17",
|
||||
"room_type_id": cls.env.ref("pms.pms_room_type_2").id,
|
||||
"partner_id": cls.host1.id,
|
||||
"adults": 2,
|
||||
"pms_property_id": cls.env.ref("pms.main_pms_property").id,
|
||||
"folio_id": cls.folio_1.id,
|
||||
}
|
||||
reservation3_vals = {
|
||||
"checkin": "2012-01-14",
|
||||
"checkout": "2012-01-17",
|
||||
"room_type_id": cls.env.ref("pms.pms_room_type_2").id,
|
||||
"partner_id": cls.host1.id,
|
||||
"adults": 2,
|
||||
"pms_property_id": cls.env.ref("pms.main_pms_property").id,
|
||||
"folio_id": cls.folio_1.id,
|
||||
}
|
||||
cls.reservation_1 = (
|
||||
cls.env["pms.reservation"].with_user(demo_user).create(reservation1_vals)
|
||||
)
|
||||
cls.reservation_2 = (
|
||||
cls.env["pms.reservation"].with_user(demo_user).create(reservation2_vals)
|
||||
)
|
||||
cls.reservation_3 = (
|
||||
cls.env["pms.reservation"].with_user(demo_user).create(reservation3_vals)
|
||||
)
|
||||
|
||||
def test_count_pending_arrival_persons(self):
|
||||
|
||||
# ARRANGE
|
||||
self.arrange_folio_reservations()
|
||||
self.checkin1 = self.env["pms.checkin.partner"].create(
|
||||
{
|
||||
"partner_id": self.host1.id,
|
||||
"reservation_id": self.reservation_1.id,
|
||||
}
|
||||
)
|
||||
self.checkin2 = self.env["pms.checkin.partner"].create(
|
||||
{
|
||||
"partner_id": self.host2.id,
|
||||
@@ -304,17 +376,35 @@ class TestPmsCheckinPartner(common.SavepointCase):
|
||||
)
|
||||
|
||||
def test_complete_checkin_data(self):
|
||||
"""
|
||||
Reservation for three adults in a first place has three checkin_partners
|
||||
pending data. Check that there decrease once their data are entered.
|
||||
|
||||
Reservation has three adults, after entering data of two of them,
|
||||
check that only one remains to be checked and the ratio of data entered
|
||||
from checkin_partners is two thirds
|
||||
"""
|
||||
|
||||
# ARRANGE
|
||||
self.arrange_folio_reservations()
|
||||
|
||||
# ACT
|
||||
self.checkin1 = self.env["pms.checkin.partner"].create(
|
||||
self.host2 = self.env["res.partner"].create(
|
||||
{
|
||||
"partner_id": self.host1.id,
|
||||
"reservation_id": self.reservation_1.id,
|
||||
"name": "Carlos",
|
||||
"phone": "654667733",
|
||||
"email": "carlos@example.com",
|
||||
"birthdate_date": "1995-12-10",
|
||||
"gender": "male",
|
||||
}
|
||||
)
|
||||
self.env["res.partner.id_number"].create(
|
||||
{
|
||||
"category_id": self.id_category.id,
|
||||
"name": "30065089H",
|
||||
"valid_from": datetime.date.today(),
|
||||
"partner_id": self.host2.id,
|
||||
}
|
||||
)
|
||||
# ACT
|
||||
|
||||
self.checkin2 = self.env["pms.checkin.partner"].create(
|
||||
{
|
||||
"partner_id": self.host2.id,
|
||||
@@ -335,18 +425,107 @@ class TestPmsCheckinPartner(common.SavepointCase):
|
||||
"Fail the checkins data ratio on reservation",
|
||||
)
|
||||
|
||||
@freeze_time("2012-01-14")
|
||||
def test_auto_arrival_delayed(self):
|
||||
"""
|
||||
The state of reservation 'arrival_delayed' happen when the checkin day
|
||||
has already passed and the resrvation had not yet changed its state to onboard.
|
||||
|
||||
The date that was previously set was 2012-01-14,
|
||||
it was advanced one day (to 2012-01-15).
|
||||
There are three reservations with checkin day on 2012-01-14,
|
||||
after invoking the method auto_arrival_delayed
|
||||
those reservation change their state to 'auto_arrival_delayed'
|
||||
"""
|
||||
|
||||
# ARRANGE
|
||||
self.arrange_folio_reservations()
|
||||
self.host2 = self.env["res.partner"].create(
|
||||
{
|
||||
"name": "Carlos",
|
||||
"phone": "654667733",
|
||||
"email": "carlos@example.com",
|
||||
"birthdate_date": "1995-12-10",
|
||||
"gender": "male",
|
||||
}
|
||||
)
|
||||
self.env["res.partner.id_number"].create(
|
||||
{
|
||||
"category_id": self.id_category.id,
|
||||
"name": "30065089H",
|
||||
"valid_from": datetime.date.today(),
|
||||
"partner_id": self.host2.id,
|
||||
}
|
||||
)
|
||||
self.host3 = self.env["res.partner"].create(
|
||||
{
|
||||
"name": "Enmanuel",
|
||||
"phone": "654667733",
|
||||
"email": "enmanuel@example.com",
|
||||
"birthdate_date": "1995-12-10",
|
||||
"gender": "male",
|
||||
}
|
||||
)
|
||||
self.env["res.partner.id_number"].create(
|
||||
{
|
||||
"category_id": self.id_category.id,
|
||||
"name": "30065089H",
|
||||
"valid_from": datetime.date.today(),
|
||||
"partner_id": self.host3.id,
|
||||
}
|
||||
)
|
||||
self.host4 = self.env["res.partner"].create(
|
||||
{
|
||||
"name": "Enrique",
|
||||
"phone": "654667733",
|
||||
"email": "enrique@example.com",
|
||||
"birthdate_date": "1995-12-10",
|
||||
"gender": "male",
|
||||
}
|
||||
)
|
||||
self.env["res.partner.id_number"].create(
|
||||
{
|
||||
"category_id": self.id_category.id,
|
||||
"name": "30065089H",
|
||||
"valid_from": datetime.date.today(),
|
||||
"partner_id": self.host4.id,
|
||||
}
|
||||
)
|
||||
self.reservation_1.write(
|
||||
{
|
||||
"checkin": datetime.date.today() + datetime.timedelta(days=4),
|
||||
"checkout": datetime.date.today() + datetime.timedelta(days=6),
|
||||
"adults": 1,
|
||||
}
|
||||
)
|
||||
reservation2_vals = {
|
||||
"checkin": datetime.date.today() + datetime.timedelta(days=4),
|
||||
"checkout": datetime.date.today() + datetime.timedelta(days=6),
|
||||
"adults": 1,
|
||||
"room_type_id": self.room_type1.id,
|
||||
"partner_id": self.host1.id,
|
||||
"pms_property_id": self.pms_property1.id,
|
||||
"folio_id": self.reservation_1.folio_id.id,
|
||||
}
|
||||
reservation3_vals = {
|
||||
"checkin": datetime.date.today() + datetime.timedelta(days=4),
|
||||
"checkout": datetime.date.today() + datetime.timedelta(days=6),
|
||||
"adults": 1,
|
||||
"room_type_id": self.room_type1.id,
|
||||
"partner_id": self.host1.id,
|
||||
"pms_property_id": self.pms_property1.id,
|
||||
"folio_id": self.reservation_1.folio_id.id,
|
||||
}
|
||||
self.reservation_2 = self.env["pms.reservation"].create(reservation2_vals)
|
||||
self.reservation_3 = self.env["pms.reservation"].create(reservation3_vals)
|
||||
folio_1 = self.reservation_1.folio_id
|
||||
PmsReservation = self.env["pms.reservation"]
|
||||
|
||||
# ACTION
|
||||
freezer = freeze_time("2012-01-15 10:00:00")
|
||||
freezer = freeze_time("2012-01-19 10:00:00")
|
||||
freezer.start()
|
||||
PmsReservation.auto_arrival_delayed()
|
||||
|
||||
arrival_delayed_reservations = self.folio_1.reservation_ids.filtered(
|
||||
arrival_delayed_reservations = folio_1.reservation_ids.filtered(
|
||||
lambda r: r.state == "arrival_delayed"
|
||||
)
|
||||
|
||||
@@ -358,10 +537,28 @@ class TestPmsCheckinPartner(common.SavepointCase):
|
||||
)
|
||||
freezer.stop()
|
||||
|
||||
@freeze_time("2012-01-14")
|
||||
def test_auto_departure_delayed(self):
|
||||
"""
|
||||
When it's checkout dat and the reservation
|
||||
was in 'onboard' state, that state change to
|
||||
'departure_delayed' if the manual checkout wasn't performed.
|
||||
|
||||
The date that was previously set was 2012-01-14,
|
||||
it was advanced two days (to 2012-01-17).
|
||||
Reservation1 has checkout day on 2012-01-17,
|
||||
after invoking the method auto_departure_delayed
|
||||
this reservation change their state to 'auto_departure_delayed'
|
||||
"""
|
||||
|
||||
# ARRANGE
|
||||
self.arrange_single_checkin()
|
||||
self.reservation_1.write(
|
||||
{
|
||||
"checkin": datetime.date.today(),
|
||||
"checkout": datetime.date.today() + datetime.timedelta(days=3),
|
||||
"adults": 1,
|
||||
}
|
||||
)
|
||||
PmsReservation = self.env["pms.reservation"]
|
||||
self.checkin1.action_on_board()
|
||||
|
||||
@@ -378,19 +575,20 @@ class TestPmsCheckinPartner(common.SavepointCase):
|
||||
"Reservations not set like Departure delayed",
|
||||
)
|
||||
|
||||
@freeze_time("2010-12-10")
|
||||
def test_not_valid_emails(self):
|
||||
# TEST CASES
|
||||
# emails that should be detected as incorrect
|
||||
# Check that the email format is incorrect
|
||||
|
||||
# ARRANGE
|
||||
reservation = self.env["pms.reservation"].create(
|
||||
{
|
||||
"checkin": "2012-01-14",
|
||||
"checkout": "2012-01-17",
|
||||
"room_type_id": self.env.ref("pms.pms_room_type_3").id,
|
||||
"checkin": datetime.date.today(),
|
||||
"checkout": datetime.date.today() + datetime.timedelta(days=3),
|
||||
"room_type_id": self.room_type1.id,
|
||||
"partner_id": self.env.ref("base.res_partner_12").id,
|
||||
"adults": 3,
|
||||
"pms_property_id": self.env.ref("pms.main_pms_property").id,
|
||||
"pms_property_id": self.pms_property1.id,
|
||||
}
|
||||
)
|
||||
test_cases = [
|
||||
@@ -404,7 +602,9 @@ class TestPmsCheckinPartner(common.SavepointCase):
|
||||
]
|
||||
for mail in test_cases:
|
||||
with self.subTest(i=mail):
|
||||
with self.assertRaises(ValidationError):
|
||||
with self.assertRaises(
|
||||
ValidationError, msg="Email format is correct and shouldn't"
|
||||
):
|
||||
reservation.write(
|
||||
{
|
||||
"checkin_partner_ids": [
|
||||
@@ -420,19 +620,20 @@ class TestPmsCheckinPartner(common.SavepointCase):
|
||||
}
|
||||
)
|
||||
|
||||
@freeze_time("2014-12-10")
|
||||
def test_valid_emails(self):
|
||||
# TEST CASES
|
||||
# emails that should be detected as correct
|
||||
# Check that the email format is correct
|
||||
|
||||
# ARRANGE
|
||||
reservation = self.env["pms.reservation"].create(
|
||||
{
|
||||
"checkin": "2012-01-14",
|
||||
"checkout": "2012-01-17",
|
||||
"room_type_id": self.env.ref("pms.pms_room_type_3").id,
|
||||
"checkin": datetime.date.today(),
|
||||
"checkout": datetime.date.today() + datetime.timedelta(days=4),
|
||||
"room_type_id": self.room_type1.id,
|
||||
"partner_id": self.env.ref("base.res_partner_12").id,
|
||||
"adults": 3,
|
||||
"pms_property_id": self.env.ref("pms.main_pms_property").id,
|
||||
"pms_property_id": self.pms_property1.id,
|
||||
}
|
||||
)
|
||||
test_cases = [
|
||||
@@ -457,19 +658,20 @@ class TestPmsCheckinPartner(common.SavepointCase):
|
||||
)
|
||||
guest.unlink()
|
||||
|
||||
@freeze_time("2016-12-10")
|
||||
def test_not_valid_phone(self):
|
||||
# TEST CASES
|
||||
# phones that should be detected as incorrect
|
||||
# Check that the phone format is incorrect
|
||||
|
||||
# ARRANGE
|
||||
reservation = self.env["pms.reservation"].create(
|
||||
{
|
||||
"checkin": "2012-01-14",
|
||||
"checkout": "2012-01-17",
|
||||
"room_type_id": self.env.ref("pms.pms_room_type_3").id,
|
||||
"checkin": datetime.date.today(),
|
||||
"checkout": datetime.date.today() + datetime.timedelta(days=1),
|
||||
"room_type_id": self.room_type1.id,
|
||||
"partner_id": self.env.ref("base.res_partner_12").id,
|
||||
"adults": 3,
|
||||
"pms_property_id": self.env.ref("pms.main_pms_property").id,
|
||||
"pms_property_id": self.pms_property1.id,
|
||||
}
|
||||
)
|
||||
test_cases = [
|
||||
@@ -481,7 +683,9 @@ class TestPmsCheckinPartner(common.SavepointCase):
|
||||
]
|
||||
for phone in test_cases:
|
||||
with self.subTest(i=phone):
|
||||
with self.assertRaises(ValidationError):
|
||||
with self.assertRaises(
|
||||
ValidationError, msg="Phone format is correct and shouldn't"
|
||||
):
|
||||
self.env["pms.checkin.partner"].create(
|
||||
{
|
||||
"name": "Carlos",
|
||||
@@ -490,19 +694,20 @@ class TestPmsCheckinPartner(common.SavepointCase):
|
||||
}
|
||||
)
|
||||
|
||||
@freeze_time("2018-12-10")
|
||||
def test_valid_phones(self):
|
||||
# TEST CASES
|
||||
# emails that should be detected as incorrect
|
||||
# Check that the phone format is correct
|
||||
|
||||
# ARRANGE
|
||||
reservation = self.env["pms.reservation"].create(
|
||||
{
|
||||
"checkin": "2012-01-14",
|
||||
"checkout": "2012-01-17",
|
||||
"room_type_id": self.env.ref("pms.pms_room_type_3").id,
|
||||
"checkin": datetime.date.today(),
|
||||
"checkout": datetime.date.today() + datetime.timedelta(days=5),
|
||||
"room_type_id": self.room_type1.id,
|
||||
"partner_id": self.env.ref("base.res_partner_12").id,
|
||||
"adults": 3,
|
||||
"pms_property_id": self.env.ref("pms.main_pms_property").id,
|
||||
"pms_property_id": self.pms_property1.id,
|
||||
}
|
||||
)
|
||||
test_cases = [
|
||||
@@ -523,3 +728,194 @@ class TestPmsCheckinPartner(common.SavepointCase):
|
||||
mobile,
|
||||
guest.mobile,
|
||||
)
|
||||
|
||||
def test_complete_checkin_data_with_partner_data(self):
|
||||
"""
|
||||
When a partner is asociated with a checkin, checkin data
|
||||
will be equal to the partner data
|
||||
|
||||
Host1:
|
||||
"email": "miguel@example.com",
|
||||
"birthdate_date": "1995-12-10",
|
||||
"gender": "male",
|
||||
|
||||
Checkin1:
|
||||
"partner_id": host1.id
|
||||
|
||||
So after this:
|
||||
Checkin1:
|
||||
"email": "miguel@example.com",
|
||||
"birthdate_date": "1995-12-10",
|
||||
"gender": "male",
|
||||
"""
|
||||
# ARRANGE
|
||||
partner_data = [self.host1.birthdate_date, self.host1.email, self.host1.gender]
|
||||
checkin_data = [
|
||||
self.checkin1.birthdate_date,
|
||||
self.checkin1.email,
|
||||
self.checkin1.gender,
|
||||
]
|
||||
|
||||
# ASSERT
|
||||
for i in [0, 1, 2]:
|
||||
self.assertEqual(
|
||||
partner_data[i],
|
||||
checkin_data[i],
|
||||
"Checkin data must be the same as partner data ",
|
||||
)
|
||||
|
||||
def test_create_partner_when_checkin_has_enought_data(self):
|
||||
"""
|
||||
Check that partner is created when the necessary minimum data is entered
|
||||
into checkin_partner data
|
||||
"""
|
||||
# ACT & ASSERT
|
||||
checkin = self.env["pms.checkin.partner"].create(
|
||||
{
|
||||
"firstname": "Pepe",
|
||||
"lastname": "Paz",
|
||||
"document_type": self.id_category.id,
|
||||
"document_number": "77156490T",
|
||||
"reservation_id": self.reservation_1.id,
|
||||
}
|
||||
)
|
||||
|
||||
# ASSERT
|
||||
self.assertTrue(
|
||||
checkin.partner_id,
|
||||
"Partner should have been created and associated with the checkin",
|
||||
)
|
||||
|
||||
def test_not_create_partner_checkin_hasnt_enought_data(self):
|
||||
"""
|
||||
Check that partner is not created when the necessary minimum data isn't entered
|
||||
into checkin_partner data, in this case document_id and document_number
|
||||
"""
|
||||
# ACT & ASSERT
|
||||
checkin = self.env["pms.checkin.partner"].create(
|
||||
{
|
||||
"firstname": "Pepe",
|
||||
"lastname": "Paz",
|
||||
"email": "pepepaz@gmail.com",
|
||||
"mobile": "666777777",
|
||||
"reservation_id": self.reservation_1.id,
|
||||
}
|
||||
)
|
||||
|
||||
# ASSERT
|
||||
self.assertFalse(
|
||||
checkin.partner_id,
|
||||
"Partner mustn't have been created and associated with the checkin",
|
||||
)
|
||||
|
||||
def test_add_partner_data_from_checkin(self):
|
||||
"""
|
||||
If the checkin_partner has some data that the partner doesn't have,
|
||||
these are saved in the partner
|
||||
|
||||
In this case, host1 hasn't mobile but the checkin_partner associated with it does,
|
||||
so the mobile of checkin_partner is added to the partner data
|
||||
|
||||
Note that if the mobile is entered before partnee was associated, this or other fields
|
||||
are overwritten by the partner's fields. In this case it is entered once the partner has
|
||||
already been associated
|
||||
"""
|
||||
# ARRANGE
|
||||
self.checkin1.mobile = "666777888"
|
||||
# ASSERT
|
||||
self.assertTrue(self.host1.mobile, "Partner mobile must be added")
|
||||
|
||||
def _test_partner_id_numbers_created_from_checkin(self):
|
||||
"""
|
||||
Some of the required data of the checkin_partner to create the partner are document_type
|
||||
and document_number, with them an id_number is created associated with the partner that
|
||||
has just been created.
|
||||
In this test it is verified that this document has been created correctly
|
||||
"""
|
||||
# ACT & ARRANGE
|
||||
checkin = self.env["pms.checkin.partner"].create(
|
||||
{
|
||||
"firstname": "Pepe",
|
||||
"lastname": "Paz",
|
||||
"document_type": self.id_category.id,
|
||||
"document_number": "77156490T",
|
||||
"reservation_id": self.reservation_1.id,
|
||||
}
|
||||
)
|
||||
|
||||
# ASSERT
|
||||
self.assertTrue(
|
||||
checkin.partner_id.id_numbers,
|
||||
"Partner id_number should have been created and hasn't been",
|
||||
)
|
||||
|
||||
def test_partner_not_modified_when_checkin_modified(self):
|
||||
"""
|
||||
If a partner is associated with a checkin
|
||||
and some of their data is modified in the checkin,
|
||||
they will not be modified in the partner
|
||||
"""
|
||||
# ARRANGE
|
||||
self.checkin1.email = "prueba@gmail.com"
|
||||
|
||||
# ASSERT
|
||||
self.assertNotEqual(
|
||||
self.host1.email,
|
||||
self.checkin1.email,
|
||||
"Checkin partner email and partner email shouldn't match",
|
||||
)
|
||||
|
||||
def _test_partner_modified_previous_checkin_not_modified(self):
|
||||
"""
|
||||
If a partner modifies any of its fields, these change mustn't be reflected
|
||||
in the previous checkins associated with it
|
||||
"""
|
||||
# ARRANGE
|
||||
self.host1.gender = "female"
|
||||
# ASSERT
|
||||
self.assertNotEqual(
|
||||
self.host1.gender,
|
||||
self.checkin1.gender,
|
||||
"Checkin partner gender and partner gender shouldn't match",
|
||||
)
|
||||
|
||||
def test_add_partner_if_exists_from_checkin(self):
|
||||
"""
|
||||
Check when a document_type and document_number are entered in a checkin if this
|
||||
document already existes and is associated with a partner, this partner will be
|
||||
associated with the checkin
|
||||
"""
|
||||
# ACT
|
||||
host = self.env["res.partner"].create(
|
||||
{
|
||||
"name": "Ricardo",
|
||||
"phone": "666555666",
|
||||
"email": "ricardo@example.com",
|
||||
"birthdate_date": "1995-11-14",
|
||||
"gender": "male",
|
||||
}
|
||||
)
|
||||
|
||||
self.env["res.partner.id_number"].create(
|
||||
{
|
||||
"category_id": self.id_category.id,
|
||||
"name": "55562998N",
|
||||
"partner_id": host.id,
|
||||
}
|
||||
)
|
||||
|
||||
# ARRANGE
|
||||
checkin = self.env["pms.checkin.partner"].create(
|
||||
{
|
||||
"document_type": self.id_category.id,
|
||||
"document_number": "55562998N",
|
||||
"reservation_id": self.reservation_1.id,
|
||||
}
|
||||
)
|
||||
|
||||
# ASSERT
|
||||
self.assertEqual(
|
||||
checkin.partner_id.id,
|
||||
host.id,
|
||||
"Checkin partner_id must be the same as the one who has that document",
|
||||
)
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.tests import common
|
||||
|
||||
from .common import TestPms
|
||||
|
||||
|
||||
class TestPmsResUser(common.SavepointCase):
|
||||
def create_common_scenario(self):
|
||||
# create a room type availability
|
||||
self.room_type_availability = self.env["pms.availability.plan"].create(
|
||||
{"name": "Availability plan 1"}
|
||||
)
|
||||
|
||||
class TestPmsResUser(TestPms):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
# create a company and properties
|
||||
self.company_A = self.env["res.company"].create(
|
||||
{
|
||||
@@ -20,104 +17,50 @@ class TestPmsResUser(common.SavepointCase):
|
||||
"name": "Pms_Company2",
|
||||
}
|
||||
)
|
||||
self.folio_sequenceA = self.env["ir.sequence"].create(
|
||||
{
|
||||
"name": "PMS Folio",
|
||||
"code": "pms.folio",
|
||||
"padding": 4,
|
||||
"company_id": self.company_A.id,
|
||||
}
|
||||
)
|
||||
self.reservation_sequenceA = self.env["ir.sequence"].create(
|
||||
{
|
||||
"name": "PMS Reservation",
|
||||
"code": "pms.reservation",
|
||||
"padding": 4,
|
||||
"company_id": self.company_A.id,
|
||||
}
|
||||
)
|
||||
self.checkin_sequenceA = self.env["ir.sequence"].create(
|
||||
{
|
||||
"name": "PMS Checkin",
|
||||
"code": "pms.checkin.partner",
|
||||
"padding": 4,
|
||||
"company_id": self.company_A.id,
|
||||
}
|
||||
)
|
||||
self.folio_sequenceB = self.env["ir.sequence"].create(
|
||||
{
|
||||
"name": "PMS Folio",
|
||||
"code": "pms.folio",
|
||||
"padding": 4,
|
||||
"company_id": self.company_B.id,
|
||||
}
|
||||
)
|
||||
self.reservation_sequenceB = self.env["ir.sequence"].create(
|
||||
{
|
||||
"name": "PMS Reservation",
|
||||
"code": "pms.reservation",
|
||||
"padding": 4,
|
||||
"company_id": self.company_B.id,
|
||||
}
|
||||
)
|
||||
self.checkin_sequenceB = self.env["ir.sequence"].create(
|
||||
{
|
||||
"name": "PMS Checkin",
|
||||
"code": "pms.checkin.partner",
|
||||
"padding": 4,
|
||||
"company_id": self.company_B.id,
|
||||
}
|
||||
)
|
||||
self.property_A1 = self.env["pms.property"].create(
|
||||
{
|
||||
"name": "Pms_property",
|
||||
"company_id": self.company_A.id,
|
||||
"default_pricelist_id": self.env.ref("product.list0").id,
|
||||
"folio_sequence_id": self.folio_sequenceA.id,
|
||||
"reservation_sequence_id": self.reservation_sequenceA.id,
|
||||
"checkin_sequence_id": self.checkin_sequenceA.id,
|
||||
"default_pricelist_id": self.pricelist1.id,
|
||||
}
|
||||
)
|
||||
self.property_A2 = self.env["pms.property"].create(
|
||||
{
|
||||
"name": "Pms_property2",
|
||||
"company_id": self.company_A.id,
|
||||
"default_pricelist_id": self.env.ref("product.list0").id,
|
||||
"folio_sequence_id": self.folio_sequenceA.id,
|
||||
"reservation_sequence_id": self.reservation_sequenceA.id,
|
||||
"checkin_sequence_id": self.checkin_sequenceA.id,
|
||||
"default_pricelist_id": self.pricelist1.id,
|
||||
}
|
||||
)
|
||||
self.property_B1 = self.env["pms.property"].create(
|
||||
{
|
||||
"name": "Pms_propertyB1",
|
||||
"company_id": self.company_B.id,
|
||||
"default_pricelist_id": self.env.ref("product.list0").id,
|
||||
"folio_sequence_id": self.folio_sequenceB.id,
|
||||
"reservation_sequence_id": self.reservation_sequenceB.id,
|
||||
"checkin_sequence_id": self.checkin_sequenceB.id,
|
||||
"default_pricelist_id": self.pricelist1.id,
|
||||
}
|
||||
)
|
||||
|
||||
def test_property_not_allowed(self):
|
||||
def test_property_not_in_allowed_properties(self):
|
||||
"""
|
||||
Property not allowed, it belongs to another company
|
||||
Property not allowed for the user
|
||||
Check a user cannot have an active property
|
||||
that is not in the allowed properties
|
||||
|
||||
Company_A ---> Property_A1, Property_A2
|
||||
Company_B ---> Property_B1
|
||||
|
||||
|
||||
"""
|
||||
# ARRANGE
|
||||
name = "test user"
|
||||
login = "test_user"
|
||||
self.create_common_scenario()
|
||||
Users = self.env["res.users"]
|
||||
# ACT & ASSERT
|
||||
with self.assertRaises(ValidationError), self.cr.savepoint():
|
||||
with self.assertRaises(
|
||||
ValidationError,
|
||||
msg="Some property is not included in the allowed properties",
|
||||
):
|
||||
Users.create(
|
||||
{
|
||||
"name": name,
|
||||
"login": login,
|
||||
"name": "Test User",
|
||||
"login": "test_user",
|
||||
"company_ids": [(4, self.company_A.id)],
|
||||
"company_id": self.company_A.id,
|
||||
"pms_property_ids": [(4, self.property_A1.id)],
|
||||
@@ -125,18 +68,26 @@ class TestPmsResUser(common.SavepointCase):
|
||||
}
|
||||
)
|
||||
|
||||
def test_check_allowed_property_ids(self):
|
||||
def test_property_not_in_allowed_companies(self):
|
||||
"""
|
||||
Property not allowed for the user
|
||||
Check a user cannot have a property in allowed properties
|
||||
that does not belong to their companies
|
||||
|
||||
Company_A ---> Property_A1, Property_A2
|
||||
Company_B ---> Property_B1
|
||||
|
||||
"""
|
||||
# ARRANGE
|
||||
name = "test user2"
|
||||
login = "test_user2"
|
||||
self.create_common_scenario()
|
||||
Users = self.env["res.users"]
|
||||
# ACT & ASSERT
|
||||
with self.assertRaises(ValidationError), self.cr.savepoint():
|
||||
with self.assertRaises(
|
||||
ValidationError, msg="Some property doesn't belong to the allowed companies"
|
||||
):
|
||||
Users.create(
|
||||
{
|
||||
"name": name,
|
||||
"login": login,
|
||||
"name": "Test User",
|
||||
"login": "test_user",
|
||||
"company_ids": [(4, self.company_A.id)],
|
||||
"company_id": self.company_A.id,
|
||||
"pms_property_ids": [
|
||||
@@ -146,3 +97,68 @@ class TestPmsResUser(common.SavepointCase):
|
||||
"pms_property_id": self.property_A1.id,
|
||||
}
|
||||
)
|
||||
|
||||
def test_property_in_allowed_properties(self):
|
||||
"""
|
||||
Successful user creation
|
||||
Check user creation with active property in allowed properties
|
||||
|
||||
Company_A ---> Property_A1, Property_A2
|
||||
Company_B ---> Property_B1
|
||||
|
||||
"""
|
||||
# ARRANGE
|
||||
Users = self.env["res.users"]
|
||||
# ACT
|
||||
user1 = Users.create(
|
||||
{
|
||||
"name": "Test User",
|
||||
"login": "test_user",
|
||||
"company_ids": [(4, self.company_A.id)],
|
||||
"company_id": self.company_A.id,
|
||||
"pms_property_ids": [
|
||||
(4, self.property_A1.id),
|
||||
(4, self.property_A2.id),
|
||||
],
|
||||
"pms_property_id": self.property_A1.id,
|
||||
}
|
||||
)
|
||||
# ASSERT
|
||||
self.assertIn(
|
||||
user1.pms_property_id,
|
||||
user1.pms_property_ids,
|
||||
"Active property not in allowed properties",
|
||||
)
|
||||
|
||||
def test_properties_belong_to_companies(self):
|
||||
"""
|
||||
Successful user creation
|
||||
Check user creation with active property and allowed properties
|
||||
belonging to the allowed companies
|
||||
|
||||
Company_A ---> Property_A1, Property_A2
|
||||
Company_B ---> Property_B1
|
||||
|
||||
"""
|
||||
# ARRANGE
|
||||
Users = self.env["res.users"]
|
||||
# ACT
|
||||
user1 = Users.create(
|
||||
{
|
||||
"name": "Test User",
|
||||
"login": "test_user",
|
||||
"company_ids": [(4, self.company_A.id)],
|
||||
"company_id": self.company_A.id,
|
||||
"pms_property_ids": [
|
||||
(4, self.property_A1.id),
|
||||
(4, self.property_A2.id),
|
||||
],
|
||||
"pms_property_id": self.property_A1.id,
|
||||
}
|
||||
)
|
||||
# ASSERT
|
||||
self.assertEqual(
|
||||
user1.pms_property_id.company_id,
|
||||
user1.company_id,
|
||||
"Active property doesn't belong to active company",
|
||||
)
|
||||
|
||||
@@ -104,6 +104,9 @@ class TestPmsReservations(common.SavepointCase):
|
||||
}
|
||||
)
|
||||
self.demo_user = self.env.ref("base.user_admin")
|
||||
self.id_category = self.env["res.partner.id_category"].create(
|
||||
{"name": "DNI", "code": "D"}
|
||||
)
|
||||
|
||||
def create_multiproperty_scenario(self):
|
||||
self.create_common_scenario()
|
||||
@@ -753,6 +756,16 @@ class TestPmsReservations(common.SavepointCase):
|
||||
"name": "Miguel",
|
||||
"phone": "654667733",
|
||||
"email": "miguel@example.com",
|
||||
"birthdate_date": "1995-12-10",
|
||||
"gender": "male",
|
||||
}
|
||||
)
|
||||
self.env["res.partner.id_number"].create(
|
||||
{
|
||||
"category_id": self.id_category.id,
|
||||
"name": "30065089H",
|
||||
"valid_from": datetime.date.today(),
|
||||
"partner_id": host.id,
|
||||
}
|
||||
)
|
||||
r1 = self.env["pms.reservation"].create(
|
||||
@@ -926,6 +939,16 @@ class TestPmsReservations(common.SavepointCase):
|
||||
"name": "Miguel",
|
||||
"phone": "654667733",
|
||||
"email": "miguel@example.com",
|
||||
"birthdate_date": "1995-12-10",
|
||||
"gender": "male",
|
||||
}
|
||||
)
|
||||
self.env["res.partner.id_number"].create(
|
||||
{
|
||||
"category_id": self.id_category.id,
|
||||
"name": "30065089H",
|
||||
"valid_from": datetime.date.today(),
|
||||
"partner_id": host.id,
|
||||
}
|
||||
)
|
||||
r1 = self.env["pms.reservation"].create(
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
from . import test_partner
|
||||
Reference in New Issue
Block a user