mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[DEL]pms: delete priority reservation/folio compute field
This commit is contained in:
@@ -30,21 +30,6 @@
|
|||||||
<field name="code">model.auto_departure_delayed()</field>
|
<field name="code">model.auto_departure_delayed()</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<record model="ir.cron" id="priority_reservations">
|
|
||||||
<field name="name">Recompute priority on reservations</field>
|
|
||||||
<field name="interval_number">1</field>
|
|
||||||
<field name="user_id" ref="base.user_root" />
|
|
||||||
<field name="interval_type">days</field>
|
|
||||||
<field name="numbercall">-1</field>
|
|
||||||
<field name="doall" eval="False" />
|
|
||||||
<field name="state">code</field>
|
|
||||||
<field name="model_id" ref="model_pms_reservation" />
|
|
||||||
<field
|
|
||||||
name="nextcall"
|
|
||||||
eval="(DateTime.now() + timedelta(days=1)).strftime('%Y-%m-%d 05:30:00')"
|
|
||||||
/>
|
|
||||||
<field name="code">model.update_daily_priority_reservation()</field>
|
|
||||||
</record>
|
|
||||||
<!-- Scheduler for send confirmed email -->
|
<!-- Scheduler for send confirmed email -->
|
||||||
<!-- <record model="ir.cron" id="send_confirmation_email_folio">
|
<!-- <record model="ir.cron" id="send_confirmation_email_folio">
|
||||||
<field name="name">Send Confirmation Email</field>
|
<field name="name">Send Confirmation Email</field>
|
||||||
|
|||||||
@@ -485,12 +485,6 @@ class PmsFolio(models.Model):
|
|||||||
compute="_compute_amount_all",
|
compute="_compute_amount_all",
|
||||||
tracking=True,
|
tracking=True,
|
||||||
)
|
)
|
||||||
max_reservation_priority = fields.Integer(
|
|
||||||
string="Max reservation priority on the entire folio",
|
|
||||||
help="Max reservation priority on the entire folio",
|
|
||||||
compute="_compute_max_reservation_priority",
|
|
||||||
store=True,
|
|
||||||
)
|
|
||||||
invoice_status = fields.Selection(
|
invoice_status = fields.Selection(
|
||||||
string="Invoice Status",
|
string="Invoice Status",
|
||||||
help="Invoice Status; it can be: invoiced, to invoice, to confirm, no",
|
help="Invoice Status; it can be: invoiced, to invoice, to confirm, no",
|
||||||
@@ -1368,12 +1362,6 @@ class PmsFolio(models.Model):
|
|||||||
}
|
}
|
||||||
return vals
|
return vals
|
||||||
|
|
||||||
@api.depends("reservation_ids", "reservation_ids.priority")
|
|
||||||
def _compute_max_reservation_priority(self):
|
|
||||||
for record in self.filtered("reservation_ids"):
|
|
||||||
reservation_priors = record.reservation_ids.mapped("priority")
|
|
||||||
record.max_reservation_priority = max(reservation_priors)
|
|
||||||
|
|
||||||
def _compute_checkin_partner_count(self):
|
def _compute_checkin_partner_count(self):
|
||||||
for record in self:
|
for record in self:
|
||||||
if (
|
if (
|
||||||
@@ -2196,7 +2184,7 @@ class PmsFolio(models.Model):
|
|||||||
# Review: force to autoreconcile payment with invoices already created
|
# Review: force to autoreconcile payment with invoices already created
|
||||||
pay.flush()
|
pay.flush()
|
||||||
for move in folio.move_ids:
|
for move in folio.move_ids:
|
||||||
move._autoreconcile_folio_payments()
|
move.sudo()._autoreconcile_folio_payments()
|
||||||
|
|
||||||
# Automatic register payment in cash register
|
# Automatic register payment in cash register
|
||||||
# TODO: cash_register to avoid flow in the new api (delete it in the future)
|
# TODO: cash_register to avoid flow in the new api (delete it in the future)
|
||||||
|
|||||||
@@ -39,12 +39,6 @@ class PmsReservation(models.Model):
|
|||||||
help="Techinal field to get reservation name",
|
help="Techinal field to get reservation name",
|
||||||
readonly=True,
|
readonly=True,
|
||||||
)
|
)
|
||||||
priority = fields.Integer(
|
|
||||||
string="Priority",
|
|
||||||
help="Priority of a reservation",
|
|
||||||
store="True",
|
|
||||||
compute="_compute_priority",
|
|
||||||
)
|
|
||||||
preferred_room_id = fields.Many2one(
|
preferred_room_id = fields.Many2one(
|
||||||
string="Room",
|
string="Room",
|
||||||
help="It's the preferred room assigned to reservation, "
|
help="It's the preferred room assigned to reservation, "
|
||||||
@@ -772,71 +766,6 @@ class PmsReservation(models.Model):
|
|||||||
for record in self:
|
for record in self:
|
||||||
record.check_adults = True
|
record.check_adults = True
|
||||||
|
|
||||||
@api.depends(
|
|
||||||
"checkin",
|
|
||||||
"checkout",
|
|
||||||
"state",
|
|
||||||
"folio_payment_state",
|
|
||||||
"to_assign",
|
|
||||||
)
|
|
||||||
def _compute_priority(self):
|
|
||||||
# TODO: Notifications priority
|
|
||||||
for record in self:
|
|
||||||
if record.to_assign or record.state in (
|
|
||||||
"arrival_delayed",
|
|
||||||
"departure_delayed",
|
|
||||||
):
|
|
||||||
record.priority = 1
|
|
||||||
elif record.state == "cancel":
|
|
||||||
record.priority = record.cancel_priority()
|
|
||||||
elif record.state == "onboard":
|
|
||||||
record.priority = record.onboard_priority()
|
|
||||||
elif record.state in ("draf", "confirm"):
|
|
||||||
record.priority = record.reservations_future_priority()
|
|
||||||
elif record.state == "done":
|
|
||||||
record.priority = record.reservations_past_priority()
|
|
||||||
|
|
||||||
def cancel_priority(self):
|
|
||||||
self.ensure_one()
|
|
||||||
if self.folio_pending_amount > 0:
|
|
||||||
return 2
|
|
||||||
elif self.checkout >= fields.date.today():
|
|
||||||
return 100
|
|
||||||
else:
|
|
||||||
return 1000 * (fields.date.today() - self.checkout).days
|
|
||||||
|
|
||||||
def onboard_priority(self):
|
|
||||||
self.ensure_one()
|
|
||||||
days_for_checkout = (self.checkout - fields.date.today()).days
|
|
||||||
if self.folio_pending_amount > 0:
|
|
||||||
return days_for_checkout
|
|
||||||
else:
|
|
||||||
return 3 * days_for_checkout
|
|
||||||
|
|
||||||
def reservations_future_priority(self):
|
|
||||||
self.ensure_one()
|
|
||||||
days_for_checkin = (self.checkin - fields.date.today()).days
|
|
||||||
if days_for_checkin < 3:
|
|
||||||
return 2 * days_for_checkin
|
|
||||||
elif days_for_checkin < 20:
|
|
||||||
return 3 * days_for_checkin
|
|
||||||
else:
|
|
||||||
return 4 * days_for_checkin
|
|
||||||
|
|
||||||
def reservations_past_priority(self):
|
|
||||||
self.ensure_one()
|
|
||||||
if self.folio_pending_amount > 0:
|
|
||||||
return 3
|
|
||||||
days_from_checkout = (fields.date.today() - self.checkout).days
|
|
||||||
if days_from_checkout <= 1:
|
|
||||||
return 6
|
|
||||||
elif days_from_checkout < 15:
|
|
||||||
return 5 * days_from_checkout
|
|
||||||
elif days_from_checkout <= 90:
|
|
||||||
return 10 * days_from_checkout
|
|
||||||
elif days_from_checkout > 90:
|
|
||||||
return 100 * days_from_checkout
|
|
||||||
|
|
||||||
@api.depends("pricelist_id", "room_type_id")
|
@api.depends("pricelist_id", "room_type_id")
|
||||||
def _compute_board_service_room_id(self):
|
def _compute_board_service_room_id(self):
|
||||||
for reservation in self:
|
for reservation in self:
|
||||||
@@ -2341,12 +2270,6 @@ class PmsReservation(models.Model):
|
|||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@api.model
|
|
||||||
def update_daily_priority_reservation(self):
|
|
||||||
reservations = self.env["pms.reservation"].search([("priority", "<", 1000)])
|
|
||||||
reservations._compute_priority()
|
|
||||||
return True
|
|
||||||
|
|
||||||
def action_confirm(self):
|
def action_confirm(self):
|
||||||
for record in self:
|
for record in self:
|
||||||
vals = {}
|
vals = {}
|
||||||
|
|||||||
@@ -363,41 +363,6 @@ class TestPmsFolio(TestPms):
|
|||||||
reservation1.agency_id, folio1.partner_id, "Agency has to be the partner"
|
reservation1.agency_id, folio1.partner_id, "Agency has to be the partner"
|
||||||
)
|
)
|
||||||
|
|
||||||
# TestCases: Priority
|
|
||||||
|
|
||||||
def test_compute_folio_priority(self):
|
|
||||||
"""
|
|
||||||
Check the priority of a folio based on its reservations
|
|
||||||
#TODO: Commented test waiting to redefine the priority calculation
|
|
||||||
"""
|
|
||||||
# reservation1 = 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,
|
|
||||||
# }
|
|
||||||
# )
|
|
||||||
# reservation1.allowed_checkin = False
|
|
||||||
|
|
||||||
# self.env["pms.reservation"].create(
|
|
||||||
# {
|
|
||||||
# "folio_id": reservation1.folio_id.id,
|
|
||||||
# "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,
|
|
||||||
# }
|
|
||||||
# )
|
|
||||||
|
|
||||||
# self.assertEqual(
|
|
||||||
# reservation1.priority,
|
|
||||||
# reservation1.folio_id.max_reservation_priority,
|
|
||||||
# "The max. reservation priority on the whole folio is incorrect",
|
|
||||||
# )
|
|
||||||
|
|
||||||
# TestCases: Payments
|
# TestCases: Payments
|
||||||
@freeze_time("2000-02-02")
|
@freeze_time("2000-02-02")
|
||||||
def test_full_pay_folio(self):
|
def test_full_pay_folio(self):
|
||||||
|
|||||||
@@ -711,818 +711,6 @@ class TestPmsReservations(TestPms):
|
|||||||
)
|
)
|
||||||
reservation.flush()
|
reservation.flush()
|
||||||
|
|
||||||
@freeze_time("2012-01-14")
|
|
||||||
def test_to_assign_priority_reservation(self):
|
|
||||||
"""
|
|
||||||
To assign reservation must have priority = 1
|
|
||||||
------
|
|
||||||
Create a reservation with only room_type (to_assign = True),
|
|
||||||
regardless of the rest of the fields the priority must be 1
|
|
||||||
|
|
||||||
NOTE:
|
|
||||||
WORK FLOW PRIORITY COMPUTE
|
|
||||||
Check reservation priority
|
|
||||||
--------
|
|
||||||
1 - TO ASSIGN, ARRIVAL DELAYED, DEPARTURE DELAYED (= 1)
|
|
||||||
2 - CANCELLED with pending amount (= 2)
|
|
||||||
3 - DONE with pending amount (= 3)
|
|
||||||
4 - ONBOARD with pending amount (= days for checkout)
|
|
||||||
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 (= 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
|
|
||||||
|
|
||||||
# ACT
|
|
||||||
res = self.env["pms.reservation"].create(
|
|
||||||
{
|
|
||||||
"checkin": fields.date.today() + datetime.timedelta(days=30),
|
|
||||||
"checkout": fields.date.today() + datetime.timedelta(days=31),
|
|
||||||
"room_type_id": self.room_type_double.id,
|
|
||||||
"partner_id": self.partner1.id,
|
|
||||||
"pms_property_id": self.pms_property1.id,
|
|
||||||
"sale_channel_origin_id": self.sale_channel_direct.id,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
computed_priority = res.priority
|
|
||||||
|
|
||||||
# ASSERT
|
|
||||||
error_msm = (
|
|
||||||
(
|
|
||||||
"The priority of a reservation to be assigned \
|
|
||||||
should be %d and this is %d"
|
|
||||||
)
|
|
||||||
% (expected_priority, computed_priority)
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(
|
|
||||||
computed_priority,
|
|
||||||
expected_priority,
|
|
||||||
error_msm,
|
|
||||||
)
|
|
||||||
|
|
||||||
@freeze_time("2012-01-14")
|
|
||||||
def test_arrival_delayed_priority_reservation(self):
|
|
||||||
"""
|
|
||||||
Arrival delayed reservation must have priority = 1
|
|
||||||
------
|
|
||||||
Create a reservation with checkin date yesterday, and without checkin action,
|
|
||||||
regardless of the rest of the fields the priority must be 1
|
|
||||||
"""
|
|
||||||
# ARRANGE
|
|
||||||
expected_priority = 1
|
|
||||||
res = self.env["pms.reservation"].create(
|
|
||||||
{
|
|
||||||
"checkin": fields.date.today() + datetime.timedelta(days=-1),
|
|
||||||
"checkout": fields.date.today() + datetime.timedelta(days=1),
|
|
||||||
"preferred_room_id": self.room1.id,
|
|
||||||
"partner_id": self.partner1.id,
|
|
||||||
"pms_property_id": self.pms_property1.id,
|
|
||||||
"sale_channel_origin_id": self.sale_channel_direct.id,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
# ACT
|
|
||||||
res.auto_arrival_delayed()
|
|
||||||
computed_priority = res.priority
|
|
||||||
|
|
||||||
# ASSERT
|
|
||||||
error_msm = (
|
|
||||||
(
|
|
||||||
"The priority of a arrival delayed 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_departure_delayed_priority_reservation(self):
|
|
||||||
# """
|
|
||||||
# To departure delayed reservation must have priority = 1
|
|
||||||
# ------
|
|
||||||
# Create a reservation and make the work flow to onboard state,
|
|
||||||
# using jump dates, we make the reservation should have left yesterday,
|
|
||||||
# regardless of the rest of the fields the priority must be 1
|
|
||||||
# """
|
|
||||||
# # ARRANGE
|
|
||||||
# expected_priority = 1
|
|
||||||
# freezer = freeze_time("1981-11-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.partner1.id,
|
|
||||||
# "pms_property_id": self.pms_property1.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_expedition_date": fields.date.today()
|
|
||||||
# + datetime.timedelta(days=665),
|
|
||||||
# }
|
|
||||||
# )
|
|
||||||
# checkin1.action_on_board()
|
|
||||||
# freezer.stop()
|
|
||||||
|
|
||||||
# # ACT
|
|
||||||
# res.auto_departure_delayed()
|
|
||||||
# computed_priority = res.priority
|
|
||||||
|
|
||||||
# # ASSERT
|
|
||||||
# error_msm = (
|
|
||||||
# (
|
|
||||||
# "The priority of a departure delayed reservation \
|
|
||||||
# should be %d and this is %d"
|
|
||||||
# )
|
|
||||||
# % (expected_priority, computed_priority)
|
|
||||||
# )
|
|
||||||
|
|
||||||
# self.assertEqual(
|
|
||||||
# computed_priority,
|
|
||||||
# expected_priority,
|
|
||||||
# error_msm,
|
|
||||||
# )
|
|
||||||
|
|
||||||
@freeze_time("2012-01-14")
|
|
||||||
def _test_cancel_pending_amount_priority_reservation(self):
|
|
||||||
"""
|
|
||||||
Cancelled with pending payments reservation must have priority = 2
|
|
||||||
------
|
|
||||||
create a reservation and cancel it ensuring that there are
|
|
||||||
pending payments in it, the priority must be 2
|
|
||||||
"""
|
|
||||||
# ARRANGE
|
|
||||||
expected_priority = 2
|
|
||||||
self.room_type_double.list_price = 25
|
|
||||||
res = self.env["pms.reservation"].create(
|
|
||||||
{
|
|
||||||
"checkin": fields.date.today() + datetime.timedelta(days=55),
|
|
||||||
"checkout": fields.date.today() + datetime.timedelta(days=56),
|
|
||||||
"preferred_room_id": self.room2.id,
|
|
||||||
"partner_id": self.partner1.id,
|
|
||||||
"pms_property_id": self.pms_property1.id,
|
|
||||||
"sale_channel_origin_id": self.sale_channel_direct.id,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
# ACT
|
|
||||||
res.action_cancel()
|
|
||||||
res.flush()
|
|
||||||
computed_priority = res.priority
|
|
||||||
|
|
||||||
# ASSERT
|
|
||||||
error_msm = (
|
|
||||||
(
|
|
||||||
"The priority of a cancelled 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_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
|
|
||||||
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=1),
|
|
||||||
"preferred_room_id": self.room2.id,
|
|
||||||
"partner_id": self.partner1.id,
|
|
||||||
"pms_property_id": self.pms_property1.id,
|
|
||||||
"sale_channel_origin_id": self.sale_channel_direct.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_expedition_date": fields.date.today()
|
|
||||||
+ datetime.timedelta(days=665),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
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
|
|
||||||
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=3),
|
|
||||||
"preferred_room_id": self.room2.id,
|
|
||||||
"partner_id": self.partner1.id,
|
|
||||||
"pms_property_id": self.pms_property1.id,
|
|
||||||
"sale_channel_origin_id": self.sale_channel_direct.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_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("2012-01-14")
|
|
||||||
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
|
|
||||||
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.partner1.id,
|
|
||||||
"pms_property_id": self.pms_property1.id,
|
|
||||||
"sale_channel_origin_id": self.sale_channel_direct.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("2012-01-14")
|
|
||||||
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
|
|
||||||
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.partner1.id,
|
|
||||||
"pms_property_id": self.pms_property1.id,
|
|
||||||
"sale_channel_origin_id": self.sale_channel_direct.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_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
|
|
||||||
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.partner1.id,
|
|
||||||
"pms_property_id": self.pms_property1.id,
|
|
||||||
"sale_channel_origin_id": self.sale_channel_direct.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_expedition_date": fields.date.today()
|
|
||||||
+ datetime.timedelta(days=665),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
checkin1.action_on_board()
|
|
||||||
|
|
||||||
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("2012-01-14")
|
|
||||||
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
|
|
||||||
expected_priority = 45
|
|
||||||
|
|
||||||
# ACT
|
|
||||||
res = self.env["pms.reservation"].create(
|
|
||||||
{
|
|
||||||
"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.partner1.id,
|
|
||||||
"pms_property_id": self.pms_property1.id,
|
|
||||||
"sale_channel_origin_id": self.sale_channel_direct.id,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
computed_priority = res.priority
|
|
||||||
|
|
||||||
# ASSERT
|
|
||||||
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("2012-01-14")
|
|
||||||
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
|
|
||||||
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.partner1.id,
|
|
||||||
"pms_property_id": self.pms_property1.id,
|
|
||||||
"sale_channel_origin_id": self.sale_channel_direct.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
|
|
||||||
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.partner1.id,
|
|
||||||
"pms_property_id": self.pms_property1.id,
|
|
||||||
"sale_channel_origin_id": self.sale_channel_direct.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_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
|
|
||||||
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.partner1.id,
|
|
||||||
"pms_property_id": self.pms_property1.id,
|
|
||||||
"sale_channel_origin_id": self.sale_channel_direct.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_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
|
|
||||||
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.partner1.id,
|
|
||||||
"pms_property_id": self.pms_property1.id,
|
|
||||||
"sale_channel_origin_id": self.sale_channel_direct.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_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):
|
def test_reservation_action_assign(self):
|
||||||
"""
|
"""
|
||||||
Checks the correct operation of the assign method
|
Checks the correct operation of the assign method
|
||||||
|
|||||||
Reference in New Issue
Block a user