mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP] complete test cases for priority reservations compute
This commit is contained in:
@@ -650,7 +650,7 @@ class PmsReservation(models.Model):
|
||||
if self.folio_pending_amount > 0:
|
||||
return 3
|
||||
days_from_checkout = (fields.date.today() - self.checkout).days
|
||||
if days_from_checkout < 1:
|
||||
if days_from_checkout <= 1:
|
||||
return 6
|
||||
elif days_from_checkout < 15:
|
||||
return 5 * days_from_checkout
|
||||
|
||||
@@ -20,24 +20,23 @@
|
||||
#
|
||||
##############################################################################
|
||||
from . import test_pms_reservation
|
||||
|
||||
# from . import test_pms_pricelist
|
||||
# from . import test_pms_checkin_partner
|
||||
# from . import test_pms_sale_channel
|
||||
# from . import test_pms_folio
|
||||
# from . import test_pms_availability_plan_rules
|
||||
# from . import test_pms_room_type
|
||||
# from . import test_pms_room_type_class
|
||||
# from . import test_pms_board_service
|
||||
# from . import test_pms_wizard_massive_changes
|
||||
# from . import test_pms_booking_engine
|
||||
# from . import test_pms_res_users
|
||||
# from . import test_pms_amenity
|
||||
# from . import test_pms_room
|
||||
# from . import test_pms_board_service_line
|
||||
# from . import test_pms_board_service_room_type
|
||||
# from . import test_pms_board_service_room_type_line
|
||||
# from . import test_pms_folio_invoice
|
||||
# from . import test_pms_folio_sale_line
|
||||
# from . import test_pms_wizard_split_join_swap_reservation
|
||||
# from . import test_product_template
|
||||
from . import test_pms_pricelist
|
||||
from . import test_pms_checkin_partner
|
||||
from . import test_pms_sale_channel
|
||||
from . import test_pms_folio
|
||||
from . import test_pms_availability_plan_rules
|
||||
from . import test_pms_room_type
|
||||
from . import test_pms_room_type_class
|
||||
from . import test_pms_board_service
|
||||
from . import test_pms_wizard_massive_changes
|
||||
from . import test_pms_booking_engine
|
||||
from . import test_pms_res_users
|
||||
from . import test_pms_amenity
|
||||
from . import test_pms_room
|
||||
from . import test_pms_board_service_line
|
||||
from . import test_pms_board_service_room_type
|
||||
from . import test_pms_board_service_room_type_line
|
||||
from . import test_pms_folio_invoice
|
||||
from . import test_pms_folio_sale_line
|
||||
from . import test_pms_wizard_split_join_swap_reservation
|
||||
from . import test_product_template
|
||||
|
||||
@@ -754,13 +754,14 @@ class TestPmsReservations(common.SavepointCase):
|
||||
5 - CONFIRM/DRAFT with arrival in less than 3 days (= 2 * days for checkin)
|
||||
6 - ONBOARD all paid (= 3 * days for checkout)
|
||||
7 - DONE with days from checkout < 1 (= 6)
|
||||
8 - CONFIRM/DRAFT with arrival between 3 and 20 days (= 2 * days for checkin)
|
||||
8 - CONFIRM/DRAFT with arrival between 3 and 20 days (= 3 * days for checkin)
|
||||
9 - CONFIRM/DRAFT with arrival in more than 20 days (= 4 * days for checkin)
|
||||
10 - DONE with days from checkout < 15 (= 5 * days from checkout)
|
||||
11 - DONE with days from checkout between 15 and 90 included (= 10 * days from checkout)
|
||||
12 - DONE with days from checkout > 90 (= 100 * days from checkout)
|
||||
"""
|
||||
# ARRANGE
|
||||
expected_priority = 1
|
||||
self.create_common_scenario()
|
||||
|
||||
# ACT
|
||||
@@ -781,12 +782,12 @@ class TestPmsReservations(common.SavepointCase):
|
||||
"The priority of a reservation to be assigned \
|
||||
should be %d and this is %d"
|
||||
)
|
||||
% (1, computed_priority)
|
||||
% (expected_priority, computed_priority)
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
computed_priority,
|
||||
1,
|
||||
expected_priority,
|
||||
error_msm,
|
||||
)
|
||||
|
||||
@@ -799,6 +800,7 @@ class TestPmsReservations(common.SavepointCase):
|
||||
regardless of the rest of the fields the priority must be 1
|
||||
"""
|
||||
# ARRANGE
|
||||
expected_priority = 1
|
||||
self.create_common_scenario()
|
||||
res = self.env["pms.reservation"].create(
|
||||
{
|
||||
@@ -820,12 +822,12 @@ class TestPmsReservations(common.SavepointCase):
|
||||
"The priority of a arrival delayed reservation \
|
||||
should be %d and this is %d"
|
||||
)
|
||||
% (1, computed_priority)
|
||||
% (expected_priority, computed_priority)
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
computed_priority,
|
||||
1,
|
||||
expected_priority,
|
||||
error_msm,
|
||||
)
|
||||
|
||||
@@ -839,6 +841,7 @@ class TestPmsReservations(common.SavepointCase):
|
||||
regardless of the rest of the fields the priority must be 1
|
||||
"""
|
||||
# ARRANGE
|
||||
expected_priority = 1
|
||||
self.create_common_scenario()
|
||||
freezer = freeze_time("1981-10-08")
|
||||
freezer.start()
|
||||
@@ -883,12 +886,12 @@ class TestPmsReservations(common.SavepointCase):
|
||||
"The priority of a departure delayed reservation \
|
||||
should be %d and this is %d"
|
||||
)
|
||||
% (1, computed_priority)
|
||||
% (expected_priority, computed_priority)
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
computed_priority,
|
||||
1,
|
||||
expected_priority,
|
||||
error_msm,
|
||||
)
|
||||
|
||||
@@ -901,6 +904,7 @@ class TestPmsReservations(common.SavepointCase):
|
||||
pending payments in it, the priority must be 2
|
||||
"""
|
||||
# ARRANGE
|
||||
expected_priority = 2
|
||||
self.create_common_scenario()
|
||||
res = self.env["pms.reservation"].create(
|
||||
{
|
||||
@@ -922,173 +926,642 @@ class TestPmsReservations(common.SavepointCase):
|
||||
"The priority of a cancelled reservation with pending amount \
|
||||
should be %d and this is %d"
|
||||
)
|
||||
% (2, computed_priority)
|
||||
% (expected_priority, computed_priority)
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
computed_priority,
|
||||
2,
|
||||
expected_priority,
|
||||
error_msm,
|
||||
)
|
||||
|
||||
@freeze_time("1981-11-01")
|
||||
def test_order_priority_checkin(self):
|
||||
# TODO: refact to tests priority flow defined above
|
||||
@freeze_time("1981-11-10")
|
||||
def test_done_with_pending_amountpriority_reservation(self):
|
||||
"""
|
||||
Done with pending amount reservation must have priority = 3
|
||||
------
|
||||
Create a reservation and make the work flow to onboard - done state,
|
||||
using jump dates, we make the checkout reservation with pending amount,
|
||||
regardless of the rest of the fields the priority must be 3
|
||||
"""
|
||||
# ARRANGE
|
||||
self.create_common_scenario()
|
||||
r1 = self.env["pms.reservation"].create(
|
||||
expected_priority = 3
|
||||
freezer = freeze_time("1981-10-08")
|
||||
freezer.start()
|
||||
res = self.env["pms.reservation"].create(
|
||||
{
|
||||
"checkin": fields.date.today(),
|
||||
"checkout": fields.date.today() + datetime.timedelta(days=2),
|
||||
"preferred_room_id": self.room1.id,
|
||||
"partner_id": self.env.ref("base.res_partner_12").id,
|
||||
"pms_property_id": self.property.id,
|
||||
}
|
||||
)
|
||||
r2 = self.env["pms.reservation"].create(
|
||||
{
|
||||
"checkin": fields.date.today() + datetime.timedelta(days=1),
|
||||
"checkout": fields.date.today() + datetime.timedelta(days=2),
|
||||
"checkout": fields.date.today() + datetime.timedelta(days=1),
|
||||
"preferred_room_id": self.room2.id,
|
||||
"partner_id": self.env.ref("base.res_partner_12").id,
|
||||
"pms_property_id": self.property.id,
|
||||
}
|
||||
)
|
||||
r1.flush()
|
||||
r2.flush()
|
||||
# ACT
|
||||
reservations = self.env["pms.reservation"].search(
|
||||
[("pms_property_id", "=", self.property.id)]
|
||||
)
|
||||
# ASSERT
|
||||
self.assertEqual(r1, reservations[0])
|
||||
|
||||
@freeze_time("1981-11-01")
|
||||
def test_order_priority_checkout(self):
|
||||
# TODO: refact to tests priority flow defined above
|
||||
# ARRANGE
|
||||
self.create_common_scenario()
|
||||
self.host1 = self.env["res.partner"].create(
|
||||
host1 = self.env["res.partner"].create(
|
||||
{
|
||||
"firstname": "Pepe",
|
||||
"lastname": "Paz",
|
||||
"email": "miguel@example.com",
|
||||
"email": "pepe@example.com",
|
||||
"birthdate_date": "1995-12-10",
|
||||
"gender": "male",
|
||||
}
|
||||
)
|
||||
self.host2 = self.env["res.partner"].create(
|
||||
{
|
||||
"firstname": "Pepe",
|
||||
"lastname": "Paz",
|
||||
"email": "Brais@example.com",
|
||||
"birthdate_date": "1995-12-10",
|
||||
"gender": "male",
|
||||
}
|
||||
)
|
||||
r1 = self.env["pms.reservation"].create(
|
||||
{
|
||||
"checkin": fields.date.today(),
|
||||
"checkout": fields.date.today() + datetime.timedelta(days=1),
|
||||
"room_type_id": self.room_type_double.id,
|
||||
"partner_id": self.env.ref("base.res_partner_12").id,
|
||||
"pms_property_id": self.property.id,
|
||||
}
|
||||
)
|
||||
r2 = self.env["pms.reservation"].create(
|
||||
{
|
||||
"checkin": fields.date.today(),
|
||||
"checkout": fields.date.today() + datetime.timedelta(days=2),
|
||||
"room_type_id": self.room_type_double.id,
|
||||
"partner_id": self.env.ref("base.res_partner_12").id,
|
||||
"pms_property_id": self.property.id,
|
||||
}
|
||||
)
|
||||
checkin1 = self.env["pms.checkin.partner"].create(
|
||||
{
|
||||
"partner_id": self.host1.id,
|
||||
"reservation_id": r1.id,
|
||||
"partner_id": host1.id,
|
||||
"reservation_id": res.id,
|
||||
"document_type": self.id_category.id,
|
||||
"document_number": "77156490T",
|
||||
"document_expedition_date": fields.date.today()
|
||||
+ datetime.timedelta(days=665),
|
||||
}
|
||||
)
|
||||
checkin2 = self.env["pms.checkin.partner"].create(
|
||||
checkin1.action_on_board()
|
||||
|
||||
freezer.stop()
|
||||
freezer = freeze_time("1981-10-09")
|
||||
freezer.start()
|
||||
|
||||
res.action_reservation_checkout()
|
||||
|
||||
# ACT
|
||||
res.auto_departure_delayed()
|
||||
computed_priority = res.priority
|
||||
freezer.stop()
|
||||
|
||||
# ASSERT
|
||||
error_msm = (
|
||||
(
|
||||
"The priority of a done reservation with pending amount\
|
||||
should be %d and this is %d"
|
||||
)
|
||||
% (expected_priority, computed_priority)
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
computed_priority,
|
||||
expected_priority,
|
||||
error_msm,
|
||||
)
|
||||
|
||||
@freeze_time("1981-11-10")
|
||||
def test_onboard_with_pending_amount_priority_reservation(self):
|
||||
"""
|
||||
Onboard with pending amount reservation must have priority = days for checkout
|
||||
------
|
||||
Create a reservation with 3 nights and make the work flow to onboard,
|
||||
using jump dates, we set today in 2 nights before checkout,
|
||||
regardless of the rest of the fields the priority must be 2
|
||||
"""
|
||||
# ARRANGE
|
||||
self.create_common_scenario()
|
||||
expected_priority = 3
|
||||
freezer = freeze_time("1981-10-08")
|
||||
freezer.start()
|
||||
res = self.env["pms.reservation"].create(
|
||||
{
|
||||
"partner_id": self.host2.id,
|
||||
"reservation_id": r2.id,
|
||||
"checkin": fields.date.today(),
|
||||
"checkout": fields.date.today() + datetime.timedelta(days=3),
|
||||
"preferred_room_id": self.room2.id,
|
||||
"partner_id": self.env.ref("base.res_partner_12").id,
|
||||
"pms_property_id": self.property.id,
|
||||
}
|
||||
)
|
||||
host1 = self.env["res.partner"].create(
|
||||
{
|
||||
"firstname": "Pepe",
|
||||
"lastname": "Paz",
|
||||
"email": "pepe@example.com",
|
||||
"birthdate_date": "1995-12-10",
|
||||
"gender": "male",
|
||||
}
|
||||
)
|
||||
checkin1 = self.env["pms.checkin.partner"].create(
|
||||
{
|
||||
"partner_id": host1.id,
|
||||
"reservation_id": res.id,
|
||||
"document_type": self.id_category.id,
|
||||
"document_number": "55562998N",
|
||||
"document_number": "77156490T",
|
||||
"document_expedition_date": fields.date.today()
|
||||
+ datetime.timedelta(days=665),
|
||||
}
|
||||
)
|
||||
|
||||
# ACT
|
||||
checkin1.action_on_board()
|
||||
computed_priority = res.priority
|
||||
freezer.stop()
|
||||
|
||||
# ASSERT
|
||||
error_msm = (
|
||||
(
|
||||
"The priority of a onboard with payment amount reservation \
|
||||
should be %d and this is %d"
|
||||
)
|
||||
% (expected_priority, computed_priority)
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
computed_priority,
|
||||
expected_priority,
|
||||
error_msm,
|
||||
)
|
||||
|
||||
@freeze_time("1981-11-10")
|
||||
def test_confirm_arriva_lt_3_days_priority_reservation(self):
|
||||
"""
|
||||
Confirm reservation with arrival in less than 3 days, priority = 2 * days for checkout
|
||||
------
|
||||
Create a reservation with checkin date on 2 days
|
||||
regardless of the rest of the fields the priority must be 2 * 2 = 4
|
||||
"""
|
||||
# ARRANGE
|
||||
self.create_common_scenario()
|
||||
expected_priority = 4
|
||||
|
||||
# ACT
|
||||
res = self.env["pms.reservation"].create(
|
||||
{
|
||||
"checkin": fields.date.today() + datetime.timedelta(days=2),
|
||||
"checkout": fields.date.today() + datetime.timedelta(days=5),
|
||||
"preferred_room_id": self.room2.id,
|
||||
"partner_id": self.env.ref("base.res_partner_12").id,
|
||||
"pms_property_id": self.property.id,
|
||||
}
|
||||
)
|
||||
computed_priority = res.priority
|
||||
|
||||
# ASSERT
|
||||
error_msm = (
|
||||
(
|
||||
"The priority of a confirm with less than 3 days for arrival \
|
||||
reservation should be %d and this is %d"
|
||||
)
|
||||
% (expected_priority, computed_priority)
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
computed_priority,
|
||||
expected_priority,
|
||||
error_msm,
|
||||
)
|
||||
|
||||
@freeze_time("1981-11-10")
|
||||
def test_onboard_all_pay_priority_reservation(self):
|
||||
"""
|
||||
Onboard with all pay reservation must have priority = 3 * days for checkout
|
||||
------
|
||||
Create a reservation with 3 nights and make the work flow to onboard,
|
||||
using jump dates, we set today in 2 nights before checkout,
|
||||
regardless of the rest of the fields the priority must be 3 * 3 = 9
|
||||
"""
|
||||
# ARRANGE
|
||||
self.create_common_scenario()
|
||||
expected_priority = 9
|
||||
res = self.env["pms.reservation"].create(
|
||||
{
|
||||
"checkin": fields.date.today(),
|
||||
"checkout": fields.date.today() + datetime.timedelta(days=3),
|
||||
"preferred_room_id": self.room2.id,
|
||||
"partner_id": self.env.ref("base.res_partner_12").id,
|
||||
"pms_property_id": self.property.id,
|
||||
}
|
||||
)
|
||||
host1 = self.env["res.partner"].create(
|
||||
{
|
||||
"firstname": "Pepe",
|
||||
"lastname": "Paz",
|
||||
"email": "pepe@example.com",
|
||||
"birthdate_date": "1995-12-10",
|
||||
"gender": "male",
|
||||
}
|
||||
)
|
||||
checkin1 = self.env["pms.checkin.partner"].create(
|
||||
{
|
||||
"partner_id": host1.id,
|
||||
"reservation_id": res.id,
|
||||
"document_type": self.id_category.id,
|
||||
"document_number": "77156490T",
|
||||
"document_expedition_date": fields.date.today()
|
||||
+ datetime.timedelta(days=665),
|
||||
}
|
||||
)
|
||||
|
||||
# ACT
|
||||
checkin1.action_on_board()
|
||||
# REVIEW: set to 0 the price to avoid make the payment
|
||||
# (config account company issues in test)
|
||||
res.reservation_line_ids.write({"price": 0})
|
||||
computed_priority = res.priority
|
||||
|
||||
# ASSERT
|
||||
error_msm = (
|
||||
(
|
||||
"The priority of onboard all pay reservation \
|
||||
should be %d and this is %d"
|
||||
)
|
||||
% (expected_priority, computed_priority)
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
computed_priority,
|
||||
expected_priority,
|
||||
error_msm,
|
||||
)
|
||||
|
||||
@freeze_time("1981-11-10")
|
||||
def test_done_yesterday_all_paid_amountpriority_reservation(self):
|
||||
"""
|
||||
Checkout yesterday without pending amount reservation must have priority = 6
|
||||
------
|
||||
Create a reservation and make the work flow to onboard - done state,
|
||||
using jump dates, we make the checkout reservation without pending amount,
|
||||
and set today 1 day after,
|
||||
regardless of the rest of the fields the priority must be 6
|
||||
"""
|
||||
# ARRANGE
|
||||
self.create_common_scenario()
|
||||
expected_priority = 6
|
||||
freezer = freeze_time("1981-10-08")
|
||||
freezer.start()
|
||||
res = self.env["pms.reservation"].create(
|
||||
{
|
||||
"checkin": fields.date.today(),
|
||||
"checkout": fields.date.today() + datetime.timedelta(days=1),
|
||||
"preferred_room_id": self.room2.id,
|
||||
"partner_id": self.env.ref("base.res_partner_12").id,
|
||||
"pms_property_id": self.property.id,
|
||||
}
|
||||
)
|
||||
host1 = self.env["res.partner"].create(
|
||||
{
|
||||
"firstname": "Pepe",
|
||||
"lastname": "Paz",
|
||||
"email": "pepe@example.com",
|
||||
"birthdate_date": "1995-12-10",
|
||||
"gender": "male",
|
||||
}
|
||||
)
|
||||
checkin1 = self.env["pms.checkin.partner"].create(
|
||||
{
|
||||
"partner_id": host1.id,
|
||||
"reservation_id": res.id,
|
||||
"document_type": self.id_category.id,
|
||||
"document_number": "77156490T",
|
||||
"document_expedition_date": fields.date.today()
|
||||
+ datetime.timedelta(days=665),
|
||||
}
|
||||
)
|
||||
checkin1.action_on_board()
|
||||
checkin2.action_on_board()
|
||||
r1.flush()
|
||||
r2.flush()
|
||||
# ACT
|
||||
reservations = self.env["pms.reservation"].search(
|
||||
[("pms_property_id", "=", self.property.id)]
|
||||
)
|
||||
# ASSERT
|
||||
self.assertEqual(r1, reservations[0])
|
||||
|
||||
@freeze_time("1981-11-01")
|
||||
def test_order_priority_state_onboard_and_pending_amount(self):
|
||||
# TODO: refact to tests priority flow defined above
|
||||
freezer.stop()
|
||||
freezer = freeze_time("1981-10-09")
|
||||
freezer.start()
|
||||
|
||||
res.action_reservation_checkout()
|
||||
# REVIEW: set to 0 the price to avoid make the payment
|
||||
# (config account company issues in test)
|
||||
res.reservation_line_ids.write({"price": 0})
|
||||
|
||||
# ACT
|
||||
freezer.stop()
|
||||
freezer = freeze_time("1981-10-10")
|
||||
freezer.start()
|
||||
|
||||
res.update_daily_priority_reservation()
|
||||
computed_priority = res.priority
|
||||
freezer.stop()
|
||||
|
||||
# ASSERT
|
||||
error_msm = (
|
||||
(
|
||||
"The priority of a done reservation without pending amount\
|
||||
and checkout yesterday should be %d and this is %d"
|
||||
)
|
||||
% (expected_priority, computed_priority)
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
computed_priority,
|
||||
expected_priority,
|
||||
error_msm,
|
||||
)
|
||||
|
||||
@freeze_time("1981-11-10")
|
||||
def test_confirm_arriva_bt_3_and_20_days_priority_reservation(self):
|
||||
"""
|
||||
Confirm reservation with arrival between 3 and 20 days, priority = 3 * days for checkout
|
||||
------
|
||||
Create a reservation with checkin date on 15 days
|
||||
regardless of the rest of the fields the priority must be 3 * 15 = 45
|
||||
"""
|
||||
# ARRANGE
|
||||
self.create_common_scenario()
|
||||
host = self.env["res.partner"].create(
|
||||
expected_priority = 45
|
||||
|
||||
# ACT
|
||||
res = self.env["pms.reservation"].create(
|
||||
{
|
||||
"name": "Miguel",
|
||||
"mobile": "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(
|
||||
{
|
||||
"checkin": fields.date.today(),
|
||||
"checkout": fields.date.today() + datetime.timedelta(days=1),
|
||||
"room_type_id": self.room_type_double.id,
|
||||
"partner_id": host.id,
|
||||
"pms_property_id": self.property.id,
|
||||
}
|
||||
)
|
||||
r1.flush()
|
||||
checkin = self.env["pms.checkin.partner"].create(
|
||||
{
|
||||
"partner_id": host.id,
|
||||
"reservation_id": r1.id,
|
||||
}
|
||||
)
|
||||
checkin.action_on_board()
|
||||
self.env["pms.reservation"].create(
|
||||
{
|
||||
"checkin": fields.date.today(),
|
||||
"checkout": fields.date.today() + datetime.timedelta(days=1),
|
||||
"room_type_id": self.room_type_double.id,
|
||||
"checkin": fields.date.today() + datetime.timedelta(days=15),
|
||||
"checkout": fields.date.today() + datetime.timedelta(days=20),
|
||||
"preferred_room_id": self.room2.id,
|
||||
"partner_id": self.env.ref("base.res_partner_12").id,
|
||||
"pms_property_id": self.property.id,
|
||||
}
|
||||
)
|
||||
# ACT
|
||||
reservations = self.env["pms.reservation"].search(
|
||||
[("pms_property_id", "=", self.property.id)]
|
||||
)
|
||||
computed_priority = res.priority
|
||||
|
||||
# ASSERT
|
||||
self.assertEqual(r1, reservations[0])
|
||||
error_msm = (
|
||||
(
|
||||
"The priority of a confirm with between 3 and 20 days for arrival \
|
||||
reservation should be %d and this is %d"
|
||||
)
|
||||
% (expected_priority, computed_priority)
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
computed_priority,
|
||||
expected_priority,
|
||||
error_msm,
|
||||
)
|
||||
|
||||
@freeze_time("1981-11-10")
|
||||
def test_confirm_arrival_more_than_20_days_priority_reservation(self):
|
||||
"""
|
||||
Confirm reservation with arrival more than 20 days, priority = 4 * days for checkout
|
||||
------
|
||||
Create a reservation with checkin date on 21 days
|
||||
regardless of the rest of the fields the priority must be 4 * 21 = 84
|
||||
"""
|
||||
# ARRANGE
|
||||
self.create_common_scenario()
|
||||
expected_priority = 84
|
||||
|
||||
# ACT
|
||||
res = self.env["pms.reservation"].create(
|
||||
{
|
||||
"checkin": fields.date.today() + datetime.timedelta(days=21),
|
||||
"checkout": fields.date.today() + datetime.timedelta(days=25),
|
||||
"preferred_room_id": self.room2.id,
|
||||
"partner_id": self.env.ref("base.res_partner_12").id,
|
||||
"pms_property_id": self.property.id,
|
||||
}
|
||||
)
|
||||
computed_priority = res.priority
|
||||
|
||||
# ASSERT
|
||||
error_msm = (
|
||||
(
|
||||
"The priority of a confirm with more than 20 days for arrival \
|
||||
reservation should be %d and this is %d"
|
||||
)
|
||||
% (expected_priority, computed_priority)
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
computed_priority,
|
||||
expected_priority,
|
||||
error_msm,
|
||||
)
|
||||
|
||||
@freeze_time("1981-11-10")
|
||||
def test_done_checkout_lt_15_days_before_all_paid_priority_reservation(self):
|
||||
"""
|
||||
Checkout less than 15 days before without pending amount reservation
|
||||
must have priority = 5 * days from checkout
|
||||
------
|
||||
Create a reservation and make the work flow to onboard - done state,
|
||||
using jump dates, we make the checkout reservation without pending amount,
|
||||
and set today 6 day after,
|
||||
regardless of the rest of the fields the priority must be 6 * 5 = 30
|
||||
"""
|
||||
# ARRANGE
|
||||
self.create_common_scenario()
|
||||
expected_priority = 30
|
||||
freezer = freeze_time("1981-10-09")
|
||||
freezer.start()
|
||||
res = self.env["pms.reservation"].create(
|
||||
{
|
||||
"checkin": fields.date.today(),
|
||||
"checkout": fields.date.today() + datetime.timedelta(days=1),
|
||||
"preferred_room_id": self.room2.id,
|
||||
"partner_id": self.env.ref("base.res_partner_12").id,
|
||||
"pms_property_id": self.property.id,
|
||||
}
|
||||
)
|
||||
host1 = self.env["res.partner"].create(
|
||||
{
|
||||
"firstname": "Pepe",
|
||||
"lastname": "Paz",
|
||||
"email": "pepe@example.com",
|
||||
"birthdate_date": "1995-12-10",
|
||||
"gender": "male",
|
||||
}
|
||||
)
|
||||
checkin1 = self.env["pms.checkin.partner"].create(
|
||||
{
|
||||
"partner_id": host1.id,
|
||||
"reservation_id": res.id,
|
||||
"document_type": self.id_category.id,
|
||||
"document_number": "77156490T",
|
||||
"document_expedition_date": fields.date.today()
|
||||
+ datetime.timedelta(days=665),
|
||||
}
|
||||
)
|
||||
checkin1.action_on_board()
|
||||
|
||||
freezer.stop()
|
||||
freezer = freeze_time("1981-10-10")
|
||||
freezer.start()
|
||||
|
||||
res.action_reservation_checkout()
|
||||
# REVIEW: set to 0 the price to avoid make the payment
|
||||
# (config account company issues in test)
|
||||
res.reservation_line_ids.write({"price": 0})
|
||||
|
||||
# ACT
|
||||
freezer.stop()
|
||||
freezer = freeze_time("1981-10-16")
|
||||
freezer.start()
|
||||
|
||||
res.update_daily_priority_reservation()
|
||||
computed_priority = res.priority
|
||||
freezer.stop()
|
||||
|
||||
# ASSERT
|
||||
error_msm = (
|
||||
(
|
||||
"The priority of a done reservation without pending amount\
|
||||
and checkout less than 15 days before should be %d and this is %d"
|
||||
)
|
||||
% (expected_priority, computed_priority)
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
computed_priority,
|
||||
expected_priority,
|
||||
error_msm,
|
||||
)
|
||||
|
||||
@freeze_time("1981-11-10")
|
||||
def test_done_checkout_bt_30_and_90_days_before_all_paid_priority_reservation(self):
|
||||
"""
|
||||
Checkout between 30 and 90 days before without pending amount reservation
|
||||
must have priority = 10 * days from checkout
|
||||
------
|
||||
Create a reservation and make the work flow to onboard - done state,
|
||||
using jump dates, we make the checkout reservation without pending amount,
|
||||
and set today 45 day after,
|
||||
regardless of the rest of the fields the priority must be 10 * 45 = 450
|
||||
"""
|
||||
# ARRANGE
|
||||
self.create_common_scenario()
|
||||
expected_priority = 450
|
||||
freezer = freeze_time("1981-10-09")
|
||||
freezer.start()
|
||||
res = self.env["pms.reservation"].create(
|
||||
{
|
||||
"checkin": fields.date.today(),
|
||||
"checkout": fields.date.today() + datetime.timedelta(days=1),
|
||||
"preferred_room_id": self.room2.id,
|
||||
"partner_id": self.env.ref("base.res_partner_12").id,
|
||||
"pms_property_id": self.property.id,
|
||||
}
|
||||
)
|
||||
host1 = self.env["res.partner"].create(
|
||||
{
|
||||
"firstname": "Pepe",
|
||||
"lastname": "Paz",
|
||||
"email": "pepe@example.com",
|
||||
"birthdate_date": "1995-12-10",
|
||||
"gender": "male",
|
||||
}
|
||||
)
|
||||
checkin1 = self.env["pms.checkin.partner"].create(
|
||||
{
|
||||
"partner_id": host1.id,
|
||||
"reservation_id": res.id,
|
||||
"document_type": self.id_category.id,
|
||||
"document_number": "77156490T",
|
||||
"document_expedition_date": fields.date.today()
|
||||
+ datetime.timedelta(days=665),
|
||||
}
|
||||
)
|
||||
checkin1.action_on_board()
|
||||
|
||||
freezer.stop()
|
||||
freezer = freeze_time("1981-10-10")
|
||||
freezer.start()
|
||||
|
||||
res.action_reservation_checkout()
|
||||
# REVIEW: set to 0 the price to avoid make the payment
|
||||
# (config account company issues in test)
|
||||
res.reservation_line_ids.write({"price": 0})
|
||||
|
||||
# ACT
|
||||
freezer.stop()
|
||||
freezer = freeze_time("1981-11-24")
|
||||
freezer.start()
|
||||
|
||||
res.update_daily_priority_reservation()
|
||||
computed_priority = res.priority
|
||||
freezer.stop()
|
||||
|
||||
# ASSERT
|
||||
error_msm = (
|
||||
(
|
||||
"The priority of a done reservation without pending amount\
|
||||
and checkout between 30 and 90 days before should be %d and this is %d"
|
||||
)
|
||||
% (expected_priority, computed_priority)
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
computed_priority,
|
||||
expected_priority,
|
||||
error_msm,
|
||||
)
|
||||
|
||||
@freeze_time("1981-11-10")
|
||||
def test_done_checkout_mt_90_days_before_all_paid_priority_reservation(self):
|
||||
"""
|
||||
Checkout more than 90 days before without pending amount reservation
|
||||
must have priority = 100 * days from checkout
|
||||
------
|
||||
Create a reservation and make the work flow to onboard - done state,
|
||||
using jump dates, we make the checkout reservation without pending amount,
|
||||
and set today 91 day after,
|
||||
regardless of the rest of the fields the priority must be 100 * 91 = 9100
|
||||
"""
|
||||
# ARRANGE
|
||||
self.create_common_scenario()
|
||||
expected_priority = 9100
|
||||
freezer = freeze_time("1981-10-09")
|
||||
freezer.start()
|
||||
res = self.env["pms.reservation"].create(
|
||||
{
|
||||
"checkin": fields.date.today(),
|
||||
"checkout": fields.date.today() + datetime.timedelta(days=1),
|
||||
"preferred_room_id": self.room2.id,
|
||||
"partner_id": self.env.ref("base.res_partner_12").id,
|
||||
"pms_property_id": self.property.id,
|
||||
}
|
||||
)
|
||||
host1 = self.env["res.partner"].create(
|
||||
{
|
||||
"firstname": "Pepe",
|
||||
"lastname": "Paz",
|
||||
"email": "pepe@example.com",
|
||||
"birthdate_date": "1995-12-10",
|
||||
"gender": "male",
|
||||
}
|
||||
)
|
||||
checkin1 = self.env["pms.checkin.partner"].create(
|
||||
{
|
||||
"partner_id": host1.id,
|
||||
"reservation_id": res.id,
|
||||
"document_type": self.id_category.id,
|
||||
"document_number": "77156490T",
|
||||
"document_expedition_date": fields.date.today()
|
||||
+ datetime.timedelta(days=665),
|
||||
}
|
||||
)
|
||||
checkin1.action_on_board()
|
||||
|
||||
freezer.stop()
|
||||
freezer = freeze_time("1981-10-10")
|
||||
freezer.start()
|
||||
|
||||
res.action_reservation_checkout()
|
||||
# REVIEW: set to 0 the price to avoid make the payment
|
||||
# (config account company issues in test)
|
||||
res.reservation_line_ids.write({"price": 0})
|
||||
|
||||
# ACT
|
||||
freezer.stop()
|
||||
freezer = freeze_time("1982-01-09")
|
||||
freezer.start()
|
||||
|
||||
res.update_daily_priority_reservation()
|
||||
computed_priority = res.priority
|
||||
freezer.stop()
|
||||
|
||||
# ASSERT
|
||||
error_msm = (
|
||||
(
|
||||
"The priority of a done reservation without pending amount\
|
||||
and checkout more than 90 days before should be %d and this is %d"
|
||||
)
|
||||
% (expected_priority, computed_priority)
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
computed_priority,
|
||||
expected_priority,
|
||||
error_msm,
|
||||
)
|
||||
|
||||
def test_reservation_action_assign(self):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user