mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP] Precommit
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
@@ -20,46 +19,50 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
import logging
|
||||
from datetime import timedelta
|
||||
|
||||
from odoo import api, fields
|
||||
from odoo.tests import common
|
||||
from odoo.tools import (
|
||||
DEFAULT_SERVER_DATE_FORMAT,
|
||||
DEFAULT_SERVER_DATETIME_FORMAT)
|
||||
import logging
|
||||
from odoo.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TestHotel(common.SavepointCase):
|
||||
|
||||
@classmethod
|
||||
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,
|
||||
})
|
||||
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):
|
||||
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!")
|
||||
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)
|
||||
@@ -79,27 +82,26 @@ 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("hotel.main_hotel_property")
|
||||
cls.demo_hotel_property = cls.env.ref("hotel.demo_hotel_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("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.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("hotel.demo_hotel_room_type_0")
|
||||
cls.demo_room_type_1 = cls.env.ref("hotel.demo_hotel_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("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.list0 = cls.env.ref('product.list0')
|
||||
cls.list1 = cls.env['product.pricelist'].create({
|
||||
'name': 'Test Pricelist',
|
||||
'pricelist_type': ''
|
||||
})
|
||||
cls.list0 = cls.env.ref("product.list0")
|
||||
cls.list1 = cls.env["product.pricelist"].create(
|
||||
{"name": "Test Pricelist", "pricelist_type": ""}
|
||||
)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
@@ -21,12 +20,13 @@
|
||||
#
|
||||
##############################################################################
|
||||
from datetime import timedelta
|
||||
from .common import TestHotel
|
||||
|
||||
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()
|
||||
|
||||
@@ -39,17 +39,18 @@ class TestHotelReservations(TestHotel):
|
||||
org_reserv_start_utc_dt,
|
||||
org_reserv_end_utc_dt,
|
||||
self.hotel_room_double_200,
|
||||
"Reservation Test #1")
|
||||
"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')
|
||||
"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')
|
||||
self.assertEqual(folio.state, "cancel", "Invalid folio state")
|
||||
for rline in folio.reservation_ids:
|
||||
self.assertEqual(rline.state, 'cancelled',
|
||||
'Invalid reservation state')
|
||||
self.assertEqual(rline.state, "cancelled", "Invalid reservation state")
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
from .common import TestHotel
|
||||
from odoo import fields
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
from .common import TestHotel
|
||||
|
||||
|
||||
class TestHotelProperty(TestHotel):
|
||||
|
||||
|
||||
@@ -19,36 +19,36 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
from .common import TestHotel
|
||||
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,
|
||||
})
|
||||
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
|
||||
})
|
||||
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
|
||||
})
|
||||
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
|
||||
})
|
||||
self.room_0.sudo().write({"capacity": 0})
|
||||
|
||||
@@ -19,10 +19,12 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
from .common import TestHotel
|
||||
from psycopg2 import IntegrityError
|
||||
|
||||
from odoo.tools import mute_logger
|
||||
|
||||
from .common import TestHotel
|
||||
|
||||
|
||||
class TestHotelRoomType(TestHotel):
|
||||
|
||||
@@ -30,15 +32,12 @@ class TestHotelRoomType(TestHotel):
|
||||
|
||||
# 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
|
||||
})
|
||||
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
|
||||
})
|
||||
test_result = self.demo_room_type_0.sudo().write(
|
||||
{"code_type": self.room_type_0.code_type}
|
||||
)
|
||||
self.assertEqual(test_result, True)
|
||||
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
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)
|
||||
|
||||
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,7 +1,8 @@
|
||||
from .common import TestHotel
|
||||
from odoo import fields
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
from .common import TestHotel
|
||||
|
||||
|
||||
class TestInheritedProductPricelist(TestHotel):
|
||||
|
||||
@@ -17,11 +18,13 @@ class TestInheritedProductPricelist(TestHotel):
|
||||
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')
|
||||
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):
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
from .common import TestHotel
|
||||
from odoo import fields
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
from .common import TestHotel
|
||||
|
||||
|
||||
class TestMassiveChanges(TestHotel):
|
||||
|
||||
@@ -10,59 +11,51 @@ class TestMassiveChanges(TestHotel):
|
||||
# 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(),
|
||||
"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,
|
||||
"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 = ''
|
||||
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)
|
||||
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.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)
|
||||
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)
|
||||
)
|
||||
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)
|
||||
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)
|
||||
)
|
||||
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.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):
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
@@ -21,19 +20,23 @@
|
||||
#
|
||||
##############################################################################
|
||||
import datetime
|
||||
from datetime import timedelta
|
||||
from odoo import fields
|
||||
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT
|
||||
from openerp.exceptions import ValidationError
|
||||
from .common import TestHotel
|
||||
from odoo.addons.hotel import date_utils
|
||||
import pytz
|
||||
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)
|
||||
@@ -45,25 +48,32 @@ class TestHotelReservations(TestHotel):
|
||||
reserv_start_utc_dt,
|
||||
reserv_end_utc_dt,
|
||||
self.hotel_room_double_200,
|
||||
"Reservation Test #1")
|
||||
"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")
|
||||
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")
|
||||
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()
|
||||
@@ -76,7 +86,8 @@ class TestHotelReservations(TestHotel):
|
||||
reserv_start_utc_dt,
|
||||
reserv_end_utc_dt,
|
||||
self.hotel_room_double_200,
|
||||
"Reservation Test #1")
|
||||
"Reservation Test #1",
|
||||
)
|
||||
|
||||
reserv_start_utc_dt = reserv_end_utc_dt
|
||||
reserv_end_utc_dt = reserv_start_utc_dt + timedelta(days=3)
|
||||
@@ -87,7 +98,8 @@ class TestHotelReservations(TestHotel):
|
||||
reserv_start_utc_dt,
|
||||
reserv_end_utc_dt,
|
||||
self.hotel_room_double_200,
|
||||
"Reservation Test #2")
|
||||
"Reservation Test #2",
|
||||
)
|
||||
|
||||
reserv_end_utc_dt = now_utc_dt + timedelta(days=3)
|
||||
reserv_start_utc_dt = reserv_end_utc_dt - timedelta(days=1)
|
||||
@@ -98,7 +110,8 @@ class TestHotelReservations(TestHotel):
|
||||
reserv_start_utc_dt,
|
||||
reserv_end_utc_dt,
|
||||
self.hotel_room_double_200,
|
||||
"Reservation Test #3")
|
||||
"Reservation Test #3",
|
||||
)
|
||||
|
||||
reserv_start_utc_dt = now_utc_dt + timedelta(days=3)
|
||||
reserv_end_utc_dt = reserv_start_utc_dt + timedelta(days=3)
|
||||
@@ -109,7 +122,8 @@ class TestHotelReservations(TestHotel):
|
||||
reserv_start_utc_dt,
|
||||
reserv_end_utc_dt,
|
||||
self.hotel_room_simple_100,
|
||||
"Reservation Test #4")
|
||||
"Reservation Test #4",
|
||||
)
|
||||
|
||||
def test_create_invalid_reservations(self):
|
||||
now_utc_dt = date_utils.now()
|
||||
@@ -123,7 +137,8 @@ class TestHotelReservations(TestHotel):
|
||||
org_reserv_start_utc_dt,
|
||||
org_reserv_end_utc_dt,
|
||||
self.hotel_room_double_200,
|
||||
"Original Reservation Test #1")
|
||||
"Original Reservation Test #1",
|
||||
)
|
||||
|
||||
# Same Dates
|
||||
reserv_start_utc_dt = now_utc_dt + timedelta(days=3)
|
||||
@@ -136,7 +151,8 @@ class TestHotelReservations(TestHotel):
|
||||
reserv_start_utc_dt,
|
||||
reserv_end_utc_dt,
|
||||
self.hotel_room_double_200,
|
||||
"Invalid Reservation Test #1")
|
||||
"Invalid Reservation Test #1",
|
||||
)
|
||||
|
||||
# Inside Org Reservation (Start Same Date)
|
||||
reserv_start_utc_dt = now_utc_dt + timedelta(days=3)
|
||||
@@ -149,7 +165,8 @@ class TestHotelReservations(TestHotel):
|
||||
reserv_start_utc_dt,
|
||||
reserv_end_utc_dt,
|
||||
self.hotel_room_double_200,
|
||||
"Invalid Reservation Test #2")
|
||||
"Invalid Reservation Test #2",
|
||||
)
|
||||
|
||||
# Inside Org Reservation (Start after)
|
||||
reserv_start_utc_dt = now_utc_dt + timedelta(days=4)
|
||||
@@ -162,7 +179,8 @@ class TestHotelReservations(TestHotel):
|
||||
reserv_start_utc_dt,
|
||||
reserv_end_utc_dt,
|
||||
self.hotel_room_double_200,
|
||||
"Invalid Reservation Test #3")
|
||||
"Invalid Reservation Test #3",
|
||||
)
|
||||
|
||||
# Intersect Org Reservation (Start before)
|
||||
reserv_start_utc_dt = now_utc_dt + timedelta(days=2)
|
||||
@@ -175,7 +193,8 @@ class TestHotelReservations(TestHotel):
|
||||
reserv_start_utc_dt,
|
||||
reserv_end_utc_dt,
|
||||
self.hotel_room_double_200,
|
||||
"Invalid Reservation Test #4")
|
||||
"Invalid Reservation Test #4",
|
||||
)
|
||||
|
||||
# Intersect Org Reservation (End Same)
|
||||
reserv_start_utc_dt = org_reserv_end_utc_dt - timedelta(days=2)
|
||||
@@ -188,7 +207,8 @@ class TestHotelReservations(TestHotel):
|
||||
reserv_start_utc_dt,
|
||||
reserv_end_utc_dt,
|
||||
self.hotel_room_double_200,
|
||||
"Invalid Reservation Test #5")
|
||||
"Invalid Reservation Test #5",
|
||||
)
|
||||
|
||||
# Intersect Org Reservation (End after)
|
||||
reserv_start_utc_dt = org_reserv_end_utc_dt - timedelta(days=2)
|
||||
@@ -201,7 +221,8 @@ class TestHotelReservations(TestHotel):
|
||||
reserv_start_utc_dt,
|
||||
reserv_end_utc_dt,
|
||||
self.hotel_room_double_200,
|
||||
"Invalid Reservation Test #6")
|
||||
"Invalid Reservation Test #6",
|
||||
)
|
||||
|
||||
# Overlays Org Reservation
|
||||
reserv_start_utc_dt = org_reserv_start_utc_dt - timedelta(days=2)
|
||||
@@ -214,7 +235,8 @@ class TestHotelReservations(TestHotel):
|
||||
reserv_start_utc_dt,
|
||||
reserv_end_utc_dt,
|
||||
self.hotel_room_double_200,
|
||||
"Invalid Reservation Test #7")
|
||||
"Invalid Reservation Test #7",
|
||||
)
|
||||
|
||||
# Checkin > Checkout
|
||||
with self.assertRaises(ValidationError):
|
||||
@@ -225,14 +247,17 @@ class TestHotelReservations(TestHotel):
|
||||
org_reserv_end_utc_dt,
|
||||
org_reserv_start_utc_dt,
|
||||
self.hotel_room_simple_100,
|
||||
"Invalid Reservation Test #8")
|
||||
"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]
|
||||
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)
|
||||
@@ -242,19 +267,28 @@ class TestHotelReservations(TestHotel):
|
||||
org_reserv_start_utc_dt,
|
||||
org_reserv_end_utc_dt,
|
||||
self.hotel_room_double_200,
|
||||
"Original Reservation Test #1")
|
||||
"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])
|
||||
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})]
|
||||
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),
|
||||
})
|
||||
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