mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[ADD] Test basic case
This commit is contained in:
@@ -19,11 +19,4 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
# from . import test_reservation
|
||||
# from . import test_folio
|
||||
from . import test_inherited_ir_http
|
||||
from . import test_inherited_product_pricelist
|
||||
from . import test_hotel_property
|
||||
from . import test_hotel_room_type
|
||||
from . import test_hotel_room
|
||||
from . import test_massive_changes
|
||||
from . import test_pms_reservation
|
||||
|
||||
@@ -34,47 +34,6 @@ class TestHotel(common.SavepointCase):
|
||||
def _init_mock_hotel(cls):
|
||||
return True
|
||||
|
||||
def create_folio(self, creator, partner):
|
||||
# Create Folio
|
||||
folio = (
|
||||
self.env["hotel.folio"].sudo(creator).create({"partner_id": partner.id,})
|
||||
)
|
||||
self.assertTrue(folio, "Can't create folio")
|
||||
return folio
|
||||
|
||||
def create_reservation(
|
||||
self, creator, folio, checkin, checkout, room, resname, adults=1, children=0
|
||||
):
|
||||
# Create Reservation (Special Room)
|
||||
reservation = (
|
||||
self.env["hotel.reservation"]
|
||||
.sudo(creator)
|
||||
.create(
|
||||
{
|
||||
"name": resname,
|
||||
"adults": adults,
|
||||
"children": children,
|
||||
"checkin": checkin.strftime(DEFAULT_SERVER_DATETIME_FORMAT),
|
||||
"checkout": checkout.strftime(DEFAULT_SERVER_DATETIME_FORMAT),
|
||||
"folio_id": folio.id,
|
||||
"room_type_id": room.price_room_type.id,
|
||||
"product_id": room.product_id.id,
|
||||
}
|
||||
)
|
||||
)
|
||||
self.assertTrue(reservation, "Hotel Calendar can't create a new reservation!")
|
||||
|
||||
# Create Reservation Lines + Update Reservation Price
|
||||
# days_diff = date_utils.date_diff(checkin, checkout, hours=False)
|
||||
# res = reservation.sudo(creator).prepare_reservation_lines(
|
||||
# checkin.strftime(DEFAULT_SERVER_DATETIME_FORMAT), days_diff)
|
||||
# reservation.sudo(creator).write({
|
||||
# 'reservation_lines': res['commands'],
|
||||
# 'price_unit': res['total_price'],
|
||||
# })
|
||||
|
||||
return reservation
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestHotel, cls).setUpClass()
|
||||
@@ -82,24 +41,24 @@ class TestHotel(common.SavepointCase):
|
||||
cls._init_mock_hotel()
|
||||
|
||||
# Create Tests Records
|
||||
cls.main_hotel_property = cls.env.ref("hotel.main_hotel_property")
|
||||
cls.demo_hotel_property = cls.env.ref("hotel.demo_hotel_property")
|
||||
cls.main_hotel_property = cls.env.ref("pms.main_pms_property")
|
||||
cls.demo_hotel_property = cls.env.ref("pms.demo_pms_property")
|
||||
|
||||
cls.room_type_0 = cls.env.ref("hotel.hotel_room_type_0")
|
||||
cls.room_type_1 = cls.env.ref("hotel.hotel_room_type_1")
|
||||
cls.room_type_2 = cls.env.ref("hotel.hotel_room_type_2")
|
||||
cls.room_type_3 = cls.env.ref("hotel.hotel_room_type_3")
|
||||
cls.room_type_0 = cls.env.ref("pms.pms_room_type_0")
|
||||
cls.room_type_1 = cls.env.ref("pms.pms_room_type_1")
|
||||
cls.room_type_2 = cls.env.ref("pms.pms_room_type_2")
|
||||
cls.room_type_3 = cls.env.ref("pms.pms_room_type_3")
|
||||
|
||||
cls.demo_room_type_0 = cls.env.ref("hotel.demo_hotel_room_type_0")
|
||||
cls.demo_room_type_1 = cls.env.ref("hotel.demo_hotel_room_type_1")
|
||||
cls.demo_room_type_0 = cls.env.ref("pms.demo_pms_room_type_0")
|
||||
cls.demo_room_type_1 = cls.env.ref("pms.demo_pms_room_type_1")
|
||||
|
||||
cls.room_0 = cls.env.ref("hotel.hotel_room_0")
|
||||
cls.room_1 = cls.env.ref("hotel.hotel_room_1")
|
||||
cls.room_2 = cls.env.ref("hotel.hotel_room_2")
|
||||
cls.room_3 = cls.env.ref("hotel.hotel_room_3")
|
||||
cls.room_4 = cls.env.ref("hotel.hotel_room_4")
|
||||
cls.room_5 = cls.env.ref("hotel.hotel_room_5")
|
||||
cls.room_6 = cls.env.ref("hotel.hotel_room_6")
|
||||
cls.room_0 = cls.env.ref("pms.pms_room_0")
|
||||
cls.room_1 = cls.env.ref("pms.pms_room_1")
|
||||
cls.room_2 = cls.env.ref("pms.pms_room_2")
|
||||
cls.room_3 = cls.env.ref("pms.pms_room_3")
|
||||
cls.room_4 = cls.env.ref("pms.pms_room_4")
|
||||
cls.room_5 = cls.env.ref("pms.pms_room_5")
|
||||
cls.room_6 = cls.env.ref("pms.pms_room_6")
|
||||
|
||||
cls.list0 = cls.env.ref("product.list0")
|
||||
cls.list1 = cls.env["product.pricelist"].create(
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2017 Solucións Aloxa S.L. <info@aloxa.eu>
|
||||
# Alexandre Díaz <dev@redneboa.es>
|
||||
#
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
from datetime import timedelta
|
||||
|
||||
from odoo.addons.hotel import date_utils
|
||||
|
||||
from .common import TestHotel
|
||||
|
||||
|
||||
class TestHotelReservations(TestHotel):
|
||||
def test_cancel_folio(self):
|
||||
now_utc_dt = date_utils.now()
|
||||
|
||||
org_reserv_start_utc_dt = now_utc_dt + timedelta(days=3)
|
||||
org_reserv_end_utc_dt = org_reserv_start_utc_dt + timedelta(days=6)
|
||||
folio = self.create_folio(self.user_hotel_manager, self.partner_2)
|
||||
reservation_a = self.create_reservation(
|
||||
self.user_hotel_manager,
|
||||
folio,
|
||||
org_reserv_start_utc_dt,
|
||||
org_reserv_end_utc_dt,
|
||||
self.hotel_room_double_200,
|
||||
"Reservation Test #1",
|
||||
)
|
||||
reservation_b = self.create_reservation(
|
||||
self.user_hotel_manager,
|
||||
folio,
|
||||
org_reserv_start_utc_dt,
|
||||
org_reserv_end_utc_dt,
|
||||
self.hotel_room_simple_100,
|
||||
"Reservation Test #2",
|
||||
)
|
||||
self.assertEqual(len(folio.reservation_ids), 2, "Invalid room lines count")
|
||||
folio.action_cancel()
|
||||
self.assertEqual(folio.state, "cancel", "Invalid folio state")
|
||||
for rline in folio.reservation_ids:
|
||||
self.assertEqual(rline.state, "cancelled", "Invalid reservation state")
|
||||
@@ -1,14 +0,0 @@
|
||||
from odoo import fields
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
from .common import TestHotel
|
||||
|
||||
|
||||
class TestHotelProperty(TestHotel):
|
||||
|
||||
# be aware using self.env.user.hotel_id because it is the value configure for the user running the tests
|
||||
|
||||
def test_default_pricelist(self):
|
||||
# A default pricelist must be related with one and only one hotel
|
||||
with self.assertRaises(ValidationError):
|
||||
self.demo_hotel_property.default_pricelist_id = self.list0
|
||||
@@ -1,54 +0,0 @@
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2017 Solucións Aloxa S.L. <info@aloxa.eu>
|
||||
# Alexandre Díaz <dev@redneboa.es>
|
||||
#
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
from .common import TestHotel
|
||||
|
||||
|
||||
class TestHotelRoom(TestHotel):
|
||||
def test_rooms_by_hotel(self):
|
||||
# A room cannot be created in a room type of another hotel
|
||||
with self.assertRaises(ValidationError):
|
||||
record = (
|
||||
self.env["hotel.room"]
|
||||
.sudo()
|
||||
.create(
|
||||
{
|
||||
"name": "Test Room",
|
||||
"hotel_id": self.demo_hotel_property.id,
|
||||
"room_type_id": self.room_type_0.id,
|
||||
}
|
||||
)
|
||||
)
|
||||
# A room cannot be changed to another hotel
|
||||
with self.assertRaises(ValidationError):
|
||||
self.room_0.sudo().write({"hotel_id": self.demo_room_type_0.hotel_id.id})
|
||||
|
||||
def test_rooms_by_room_type(self):
|
||||
# A room cannot be changed to a room type of another hotel
|
||||
with self.assertRaises(ValidationError):
|
||||
self.room_0.sudo().write({"room_type_id": self.demo_room_type_1.id})
|
||||
|
||||
def test_check_capacity(self):
|
||||
# The capacity of the room must be greater than 0
|
||||
with self.assertRaises(ValidationError):
|
||||
self.room_0.sudo().write({"capacity": 0})
|
||||
@@ -1,43 +0,0 @@
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2017 Solucións Aloxa S.L. <info@aloxa.eu>
|
||||
# Alexandre Díaz <dev@redneboa.es>
|
||||
#
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
from psycopg2 import IntegrityError
|
||||
|
||||
from odoo.tools import mute_logger
|
||||
|
||||
from .common import TestHotel
|
||||
|
||||
|
||||
class TestHotelRoomType(TestHotel):
|
||||
|
||||
# TODO: use users with different access rules
|
||||
|
||||
# code type must be unique by hotel
|
||||
def test_code_type_unique_by_hotel(self):
|
||||
with self.assertRaises(IntegrityError), mute_logger("odoo.sql_db"):
|
||||
self.room_type_0.sudo().write({"code_type": self.room_type_1.code_type})
|
||||
|
||||
# code type can be used in other hotel
|
||||
def test_code_type_shared_by_hotel(self):
|
||||
test_result = self.demo_room_type_0.sudo().write(
|
||||
{"code_type": self.room_type_0.code_type}
|
||||
)
|
||||
self.assertEqual(test_result, True)
|
||||
@@ -1,10 +0,0 @@
|
||||
from .common import TestHotel
|
||||
|
||||
|
||||
class TestInheritedIrHttp(TestHotel):
|
||||
def test_user_hotel_company(self):
|
||||
admin_user = self.env.ref("base.user_root")
|
||||
self.assertTrue(
|
||||
admin_user.hotel_id.company_id in admin_user.company_ids,
|
||||
"Wrong hotel and company access settings for %s" % admin_user.name,
|
||||
)
|
||||
@@ -1,33 +0,0 @@
|
||||
from odoo import fields
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
from .common import TestHotel
|
||||
|
||||
|
||||
class TestInheritedProductPricelist(TestHotel):
|
||||
|
||||
# be aware using self.env.user.hotel_id because it is the value configure for the user running the tests
|
||||
|
||||
def test_daily_pricelist(self):
|
||||
# A daily pricelist must be related with one and only one hotel #1
|
||||
with self.assertRaises(ValidationError):
|
||||
self.list0.hotel_ids += self.demo_hotel_property
|
||||
|
||||
# A daily pricelist must be related with one and only one hotel #2
|
||||
with self.assertRaises(ValidationError):
|
||||
self.list0.hotel_ids = False
|
||||
|
||||
# create a valid record using a daily pricelist
|
||||
test_result = self.env["product.pricelist"].create(
|
||||
{
|
||||
"name": "Test Daily Pricelist",
|
||||
"hotel_ids": [(4, self.demo_hotel_property.id)],
|
||||
}
|
||||
)
|
||||
self.assertEqual(test_result.pricelist_type, "daily")
|
||||
self.assertEqual(test_result.hotel_ids, self.demo_hotel_property)
|
||||
|
||||
def test_pricelist_by_hotel(self):
|
||||
# Relationship mismatch when the pricelist is already used as default in a different hotel
|
||||
with self.assertRaises(ValidationError):
|
||||
self.list0.hotel_ids = self.demo_hotel_property
|
||||
@@ -1,63 +0,0 @@
|
||||
from odoo import fields
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
from .common import TestHotel
|
||||
|
||||
|
||||
class TestMassiveChanges(TestHotel):
|
||||
|
||||
# be aware using self.env.user.hotel_id because it is the value configure for the user running the tests
|
||||
|
||||
# base massive change record
|
||||
def base_massive_change_vals(self, hotel_id=None):
|
||||
return {
|
||||
"hotel_id": hotel_id and hotel_id.id or self.main_hotel_property.id,
|
||||
"date_start": fields.Date.today(),
|
||||
"date_end": fields.Date.today(),
|
||||
}
|
||||
|
||||
def pricelist_massive_change_vals(self, pricelist_id=None):
|
||||
return {
|
||||
"pricelist_id": pricelist_id and pricelist_id.id or self.list0.id,
|
||||
"price": 50.0,
|
||||
}
|
||||
|
||||
def test_daily_pricelist(self):
|
||||
# Only daily pricelist can be manage by a massive change
|
||||
self.list0.pricelist_type = ""
|
||||
with self.assertRaises(ValidationError):
|
||||
vals = self.base_massive_change_vals()
|
||||
vals.update(self.pricelist_massive_change_vals())
|
||||
self.env["hotel.wizard.massive.changes"].create(vals)
|
||||
|
||||
# create a valid record using a daily pricelist
|
||||
self.list0.pricelist_type = "daily"
|
||||
test_result = self.env["hotel.wizard.massive.changes"].create(vals)
|
||||
self.assertEqual(test_result.pricelist_id, self.list0)
|
||||
|
||||
def test_pricelist_by_hotel(self):
|
||||
# Ensure the pricelist plan belongs to the current hotel #1
|
||||
with self.assertRaises(ValidationError):
|
||||
vals = self.base_massive_change_vals(self.demo_hotel_property)
|
||||
vals.update(self.pricelist_massive_change_vals())
|
||||
self.env["hotel.wizard.massive.changes"].create(vals)
|
||||
|
||||
# Ensure the pricelist plan belongs to the current hotel #2
|
||||
with self.assertRaises(ValidationError):
|
||||
vals = self.base_massive_change_vals()
|
||||
vals.update(self.pricelist_massive_change_vals(self.list1))
|
||||
self.list1.hotel_ids = self.demo_hotel_property
|
||||
self.list1.pricelist_type = "daily"
|
||||
self.env["hotel.wizard.massive.changes"].create(vals)
|
||||
|
||||
# create a valid record using the current hotel
|
||||
vals = self.base_massive_change_vals()
|
||||
vals.update(self.pricelist_massive_change_vals(self.list1))
|
||||
self.list1.hotel_ids = self.main_hotel_property
|
||||
self.list1.pricelist_type = "daily"
|
||||
test_result = self.env["hotel.wizard.massive.changes"].create(vals)
|
||||
self.assertEqual(test_result.pricelist_id.hotel_ids, self.main_hotel_property)
|
||||
|
||||
def test_do_massive_change(self):
|
||||
# check the result of a massive change
|
||||
pass
|
||||
35
pms/tests/test_pms_reservation.py
Normal file
35
pms/tests/test_pms_reservation.py
Normal file
@@ -0,0 +1,35 @@
|
||||
from datetime import timedelta
|
||||
|
||||
from odoo import fields
|
||||
|
||||
from .common import TestHotel
|
||||
|
||||
|
||||
class TestPmsReservations(TestHotel):
|
||||
def test_create_reservation(self):
|
||||
today = fields.date.today()
|
||||
checkin = today + timedelta(days=8)
|
||||
checkout = checkin + timedelta(days=11)
|
||||
demo_user = self.env.ref("base.user_demo")
|
||||
customer = self.env.ref("base.res_partner_12")
|
||||
reservation_vals = {
|
||||
"checkin": checkin,
|
||||
"checkout": checkout,
|
||||
"room_type_id": self.room_type_3.id,
|
||||
"partner_id": customer.id,
|
||||
"pms_property_id": self.main_hotel_property.id,
|
||||
}
|
||||
reservation = (
|
||||
self.env["pms.reservation"].with_user(demo_user).create(reservation_vals)
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
reservation.reservation_line_ids[0].date,
|
||||
checkin,
|
||||
"Reservation lines don't start in the correct date",
|
||||
)
|
||||
self.assertEqual(
|
||||
reservation.reservation_line_ids[-1].date,
|
||||
checkout - timedelta(1),
|
||||
"Reservation lines don't end in the correct date",
|
||||
)
|
||||
@@ -1,294 +0,0 @@
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2017 Solucións Aloxa S.L. <info@aloxa.eu>
|
||||
# Alexandre Díaz <dev@redneboa.es>
|
||||
#
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
import datetime
|
||||
import logging
|
||||
from datetime import timedelta
|
||||
|
||||
import pytz
|
||||
from openerp.exceptions import ValidationError
|
||||
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT
|
||||
|
||||
from odoo import fields
|
||||
|
||||
from odoo.addons.hotel import date_utils
|
||||
|
||||
from .common import TestHotel
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TestHotelReservations(TestHotel):
|
||||
def test_create_reservation(self):
|
||||
now_utc_dt = date_utils.now()
|
||||
reserv_start_utc_dt = now_utc_dt + timedelta(days=3)
|
||||
reserv_end_utc_dt = reserv_start_utc_dt + timedelta(days=3)
|
||||
folio = self.create_folio(self.user_hotel_manager, self.partner_2)
|
||||
reservation = self.create_reservation(
|
||||
self.user_hotel_manager,
|
||||
folio,
|
||||
reserv_start_utc_dt,
|
||||
reserv_end_utc_dt,
|
||||
self.hotel_room_double_200,
|
||||
"Reservation Test #1",
|
||||
)
|
||||
|
||||
reserv_start_dt = date_utils.dt_as_timezone(reserv_start_utc_dt, self.tz_hotel)
|
||||
reserv_end_dt = date_utils.dt_as_timezone(
|
||||
reserv_end_utc_dt - timedelta(days=1), self.tz_hotel
|
||||
)
|
||||
self.assertEqual(
|
||||
reservation.reservation_lines[0].date,
|
||||
reserv_start_dt.strftime(DEFAULT_SERVER_DATE_FORMAT),
|
||||
"Reservation lines don't start in the correct date",
|
||||
)
|
||||
self.assertEqual(
|
||||
reservation.reservation_lines[-1].date,
|
||||
reserv_end_dt.strftime(DEFAULT_SERVER_DATE_FORMAT),
|
||||
"Reservation lines don't end in the correct date",
|
||||
)
|
||||
|
||||
total_price = 0.0
|
||||
for rline in reservation.reservation_lines:
|
||||
total_price += rline.price
|
||||
self.assertEqual(
|
||||
folio.amount_untaxed,
|
||||
total_price,
|
||||
"Folio amount doesn't match with reservation lines",
|
||||
)
|
||||
|
||||
def test_create_reservations(self):
|
||||
now_utc_dt = date_utils.now()
|
||||
reserv_start_utc_dt = now_utc_dt + timedelta(days=3)
|
||||
reserv_end_utc_dt = reserv_start_utc_dt + timedelta(days=3)
|
||||
folio = self.create_folio(self.user_hotel_manager, self.partner_2)
|
||||
reservation = self.create_reservation(
|
||||
self.user_hotel_manager,
|
||||
folio,
|
||||
reserv_start_utc_dt,
|
||||
reserv_end_utc_dt,
|
||||
self.hotel_room_double_200,
|
||||
"Reservation Test #1",
|
||||
)
|
||||
|
||||
reserv_start_utc_dt = reserv_end_utc_dt
|
||||
reserv_end_utc_dt = reserv_start_utc_dt + timedelta(days=3)
|
||||
folio = self.create_folio(self.user_hotel_manager, self.partner_2)
|
||||
reservation = self.create_reservation(
|
||||
self.user_hotel_manager,
|
||||
folio,
|
||||
reserv_start_utc_dt,
|
||||
reserv_end_utc_dt,
|
||||
self.hotel_room_double_200,
|
||||
"Reservation Test #2",
|
||||
)
|
||||
|
||||
reserv_end_utc_dt = now_utc_dt + timedelta(days=3)
|
||||
reserv_start_utc_dt = reserv_end_utc_dt - timedelta(days=1)
|
||||
folio = self.create_folio(self.user_hotel_manager, self.partner_2)
|
||||
reservation = self.create_reservation(
|
||||
self.user_hotel_manager,
|
||||
folio,
|
||||
reserv_start_utc_dt,
|
||||
reserv_end_utc_dt,
|
||||
self.hotel_room_double_200,
|
||||
"Reservation Test #3",
|
||||
)
|
||||
|
||||
reserv_start_utc_dt = now_utc_dt + timedelta(days=3)
|
||||
reserv_end_utc_dt = reserv_start_utc_dt + timedelta(days=3)
|
||||
folio = self.create_folio(self.user_hotel_manager, self.partner_2)
|
||||
reservation = self.create_reservation(
|
||||
self.user_hotel_manager,
|
||||
folio,
|
||||
reserv_start_utc_dt,
|
||||
reserv_end_utc_dt,
|
||||
self.hotel_room_simple_100,
|
||||
"Reservation Test #4",
|
||||
)
|
||||
|
||||
def test_create_invalid_reservations(self):
|
||||
now_utc_dt = date_utils.now()
|
||||
|
||||
org_reserv_start_utc_dt = now_utc_dt + timedelta(days=3)
|
||||
org_reserv_end_utc_dt = org_reserv_start_utc_dt + timedelta(days=6)
|
||||
folio = self.create_folio(self.user_hotel_manager, self.partner_2)
|
||||
reservation = self.create_reservation(
|
||||
self.user_hotel_manager,
|
||||
folio,
|
||||
org_reserv_start_utc_dt,
|
||||
org_reserv_end_utc_dt,
|
||||
self.hotel_room_double_200,
|
||||
"Original Reservation Test #1",
|
||||
)
|
||||
|
||||
# Same Dates
|
||||
reserv_start_utc_dt = now_utc_dt + timedelta(days=3)
|
||||
reserv_end_utc_dt = reserv_start_utc_dt + timedelta(days=6)
|
||||
with self.assertRaises(ValidationError):
|
||||
folio = self.create_folio(self.user_hotel_manager, self.partner_2)
|
||||
reservation = self.create_reservation(
|
||||
self.user_hotel_manager,
|
||||
folio,
|
||||
reserv_start_utc_dt,
|
||||
reserv_end_utc_dt,
|
||||
self.hotel_room_double_200,
|
||||
"Invalid Reservation Test #1",
|
||||
)
|
||||
|
||||
# Inside Org Reservation (Start Same Date)
|
||||
reserv_start_utc_dt = now_utc_dt + timedelta(days=3)
|
||||
reserv_end_utc_dt = reserv_start_utc_dt + timedelta(days=3)
|
||||
with self.assertRaises(ValidationError):
|
||||
folio = self.create_folio(self.user_hotel_manager, self.partner_2)
|
||||
reservation = self.create_reservation(
|
||||
self.user_hotel_manager,
|
||||
folio,
|
||||
reserv_start_utc_dt,
|
||||
reserv_end_utc_dt,
|
||||
self.hotel_room_double_200,
|
||||
"Invalid Reservation Test #2",
|
||||
)
|
||||
|
||||
# Inside Org Reservation (Start after)
|
||||
reserv_start_utc_dt = now_utc_dt + timedelta(days=4)
|
||||
reserv_end_utc_dt = reserv_start_utc_dt + timedelta(days=3)
|
||||
with self.assertRaises(ValidationError):
|
||||
folio = self.create_folio(self.user_hotel_manager, self.partner_2)
|
||||
reservation = self.create_reservation(
|
||||
self.user_hotel_manager,
|
||||
folio,
|
||||
reserv_start_utc_dt,
|
||||
reserv_end_utc_dt,
|
||||
self.hotel_room_double_200,
|
||||
"Invalid Reservation Test #3",
|
||||
)
|
||||
|
||||
# Intersect Org Reservation (Start before)
|
||||
reserv_start_utc_dt = now_utc_dt + timedelta(days=2)
|
||||
reserv_end_utc_dt = reserv_start_utc_dt + timedelta(days=3)
|
||||
with self.assertRaises(ValidationError):
|
||||
folio = self.create_folio(self.user_hotel_manager, self.partner_2)
|
||||
reservation = self.create_reservation(
|
||||
self.user_hotel_manager,
|
||||
folio,
|
||||
reserv_start_utc_dt,
|
||||
reserv_end_utc_dt,
|
||||
self.hotel_room_double_200,
|
||||
"Invalid Reservation Test #4",
|
||||
)
|
||||
|
||||
# Intersect Org Reservation (End Same)
|
||||
reserv_start_utc_dt = org_reserv_end_utc_dt - timedelta(days=2)
|
||||
reserv_end_utc_dt = org_reserv_end_utc_dt
|
||||
with self.assertRaises(ValidationError):
|
||||
folio = self.create_folio(self.user_hotel_manager, self.partner_2)
|
||||
reservation = self.create_reservation(
|
||||
self.user_hotel_manager,
|
||||
folio,
|
||||
reserv_start_utc_dt,
|
||||
reserv_end_utc_dt,
|
||||
self.hotel_room_double_200,
|
||||
"Invalid Reservation Test #5",
|
||||
)
|
||||
|
||||
# Intersect Org Reservation (End after)
|
||||
reserv_start_utc_dt = org_reserv_end_utc_dt - timedelta(days=2)
|
||||
reserv_end_utc_dt = org_reserv_end_utc_dt + timedelta(days=3)
|
||||
with self.assertRaises(ValidationError):
|
||||
folio = self.create_folio(self.user_hotel_manager, self.partner_2)
|
||||
reservation = self.create_reservation(
|
||||
self.user_hotel_manager,
|
||||
folio,
|
||||
reserv_start_utc_dt,
|
||||
reserv_end_utc_dt,
|
||||
self.hotel_room_double_200,
|
||||
"Invalid Reservation Test #6",
|
||||
)
|
||||
|
||||
# Overlays Org Reservation
|
||||
reserv_start_utc_dt = org_reserv_start_utc_dt - timedelta(days=2)
|
||||
reserv_end_utc_dt = org_reserv_end_utc_dt + timedelta(days=2)
|
||||
with self.assertRaises(ValidationError):
|
||||
folio = self.create_folio(self.user_hotel_manager, self.partner_2)
|
||||
reservation = self.create_reservation(
|
||||
self.user_hotel_manager,
|
||||
folio,
|
||||
reserv_start_utc_dt,
|
||||
reserv_end_utc_dt,
|
||||
self.hotel_room_double_200,
|
||||
"Invalid Reservation Test #7",
|
||||
)
|
||||
|
||||
# Checkin > Checkout
|
||||
with self.assertRaises(ValidationError):
|
||||
folio = self.create_folio(self.user_hotel_manager, self.partner_2)
|
||||
reservation = self.create_reservation(
|
||||
self.user_hotel_manager,
|
||||
folio,
|
||||
org_reserv_end_utc_dt,
|
||||
org_reserv_start_utc_dt,
|
||||
self.hotel_room_simple_100,
|
||||
"Invalid Reservation Test #8",
|
||||
)
|
||||
|
||||
def test_modify_reservation(self):
|
||||
now_utc_dt = date_utils.now()
|
||||
|
||||
# 5.0, 15.0, 15.0, 35.0, 35.0, 10.0, 10.0
|
||||
|
||||
room_type_prices = self.prices_tmp[
|
||||
self.hotel_room_double_200.price_room_type.id
|
||||
]
|
||||
org_reserv_start_utc_dt = now_utc_dt + timedelta(days=1)
|
||||
org_reserv_end_utc_dt = org_reserv_start_utc_dt + timedelta(days=2)
|
||||
folio = self.create_folio(self.user_hotel_manager, self.partner_2)
|
||||
reservation = self.create_reservation(
|
||||
self.user_hotel_manager,
|
||||
folio,
|
||||
org_reserv_start_utc_dt,
|
||||
org_reserv_end_utc_dt,
|
||||
self.hotel_room_double_200,
|
||||
"Original Reservation Test #1",
|
||||
)
|
||||
ndate = org_reserv_start_utc_dt
|
||||
for r_k, r_v in enumerate(reservation.reservation_lines):
|
||||
self.assertEqual(r_v.date, ndate.strftime(DEFAULT_SERVER_DATE_FORMAT))
|
||||
self.assertEqual(r_v.price, room_type_prices[r_k + 1])
|
||||
ndate = ndate + timedelta(days=1)
|
||||
self.assertEqual(reservation.amount_room, 30.0)
|
||||
ndate = org_reserv_start_utc_dt + timedelta(days=1)
|
||||
line = reservation.reservation_lines.filtered(
|
||||
lambda r: r.date == ndate.strftime(DEFAULT_SERVER_DATE_FORMAT)
|
||||
)
|
||||
reservation.reservation_lines = [(1, line.id, {"price": 100.0})]
|
||||
self.assertEqual(reservation.amount_room, 115.0)
|
||||
reservation.sudo(self.user_hotel_manager).write(
|
||||
{
|
||||
"checkin": (org_reserv_start_utc_dt + timedelta(days=1)).strftime(
|
||||
DEFAULT_SERVER_DATE_FORMAT
|
||||
),
|
||||
"checkout": (org_reserv_end_utc_dt + timedelta(days=1)).strftime(
|
||||
DEFAULT_SERVER_DATE_FORMAT
|
||||
),
|
||||
}
|
||||
)
|
||||
self.assertEqual(reservation.amount_room, 135.0)
|
||||
Reference in New Issue
Block a user