Merge PR #165 into 14.0

Signed-off-by DarioLodeiros
This commit is contained in:
OCA-git-bot
2022-06-29 16:06:05 +00:00
5 changed files with 290 additions and 130 deletions

View File

@@ -30,22 +30,7 @@
<field name="nextcall" eval="DateTime.now()" /> <field name="nextcall" eval="DateTime.now()" />
<field name="code">model.auto_departure_delayed()</field> <field name="code">model.auto_departure_delayed()</field>
</record> </record>
<!-- Scheduler For To Inform Guest About Reservation Before 24 Hours -->
<record model="ir.cron" id="autocheckout_reservations">
<field name="name">Automatic Checkout on past 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:00:00')"
/>
<field name="code">model.autocheckout()</field>
</record>
<record model="ir.cron" id="priority_reservations"> <record model="ir.cron" id="priority_reservations">
<field name="name">Recompute priority on reservations</field> <field name="name">Recompute priority on reservations</field>
<field name="interval_number">1</field> <field name="interval_number">1</field>

View File

@@ -904,7 +904,7 @@ class PmsCheckinPartner(models.Model):
if values.get("document_expedition_date"): if values.get("document_expedition_date"):
doc_type = values.get("document_type") doc_type = values.get("document_type")
doc_type = self.env["res.partner.id_category"].search( doc_type = self.env["res.partner.id_category"].search(
[("name", "=", doc_type)] [("code", "=", doc_type)]
) )
doc_date = values.get("document_expedition_date") doc_date = values.get("document_expedition_date")
birthdate = values.get("birthdate_date") birthdate = values.get("birthdate_date")

View File

@@ -1091,7 +1091,7 @@ class PmsReservation(models.Model):
record.reservation_type != "out" record.reservation_type != "out"
and record.overnight_room and record.overnight_room
and record.state in ("draft", "confirm", "arrival_delayed") and record.state in ("draft", "confirm", "arrival_delayed")
and record.checkin <= fields.Date.today() and fields.Date.today() >= record.checkin
) )
else False else False
) )
@@ -1103,7 +1103,7 @@ class PmsReservation(models.Model):
True True
if ( if (
record.state in ["onboard", "departure_delayed"] record.state in ["onboard", "departure_delayed"]
and record.checkout >= fields.Date.today() and fields.Date.today() >= record.checkout
) )
else False else False
) )
@@ -1954,19 +1954,15 @@ class PmsReservation(models.Model):
) )
@api.model @api.model
def autocheckout(self): def autocheckout(self, reservation):
reservations = self.env["pms.reservation"].search( reservation.action_reservation_checkout()
[ if not any(
("state", "not in", ["done", "cancel"]), [checkin.state == "done" for checkin in reservation.checkin_partner_ids]
("checkout", "<", fields.Date.today()), ):
]
)
for res in reservations:
res.action_reservation_checkout()
res_without_checkin = reservations.filtered(lambda r: r.state != "onboard")
for res in res_without_checkin:
msg = _("No checkin was made for this reservation") msg = _("No checkin was made for this reservation")
res.message_post(subject=_("No Checkins!"), subtype="mt_comment", body=msg) reservation.message_post(
subject=_("No Checkins!"), subtype="mt_comment", body=msg
)
return True return True
@api.model @api.model
@@ -2089,29 +2085,39 @@ class PmsReservation(models.Model):
@api.model @api.model
def auto_arrival_delayed(self): def auto_arrival_delayed(self):
# No show when pass 1 day from checkin day # No show when pass 1 day from checkin day
arrival_delayed_reservations = self.env["pms.reservation"].search( reservations = self.env["pms.reservation"].search(
[ [
("state", "in", ("draft", "confirm")), ("state", "in", ("draft", "confirm", "arrival_delayed")),
("checkin", "<", fields.Date.today()), ("checkin", "<", fields.Date.today()),
("overnight_room", "=", True),
] ]
) )
for record in arrival_delayed_reservations: for reservation in reservations:
if record.overnight_room: if reservation.checkout > fields.Datetime.today().date():
record.state = "arrival_delayed" reservation.state = "arrival_delayed"
else:
reservation.state = "departure_delayed"
reservation.message_post(
body=_(
"""No entry has been recorded in this reservation""",
)
)
@api.model @api.model
def auto_departure_delayed(self): def auto_departure_delayed(self):
# No checkout when pass checkout hour # No checkout when pass checkout hour
reservations = self.env["pms.reservation"].search( reservations = self.env["pms.reservation"].search(
[ [
("state", "in", ("onboard",)), ("state", "in", ("onboard", "departure_delayed")),
("checkout", "<=", fields.Datetime.today()), ("checkout", "<=", fields.Datetime.today().date()),
] ]
) )
for reservation in reservations: for reservation in reservations:
if reservation.overnight_room: if reservation.overnight_room:
if reservation.checkout_datetime <= fields.Datetime.now(): if reservation.checkout == fields.Datetime.today().date():
reservations.state = "departure_delayed" reservation.state = "departure_delayed"
else:
reservation.autocheckout(reservation)
else: else:
reservation.state = "done" reservation.state = "done"

View File

@@ -1,6 +1,7 @@
import datetime import datetime
import logging import logging
from dateutil.relativedelta import relativedelta
from freezegun import freeze_time from freezegun import freeze_time
from odoo import fields from odoo import fields
@@ -457,8 +458,8 @@ class TestPmsCheckinPartner(TestPms):
has already passed and the resrvation had not yet changed its state to onboard. has already passed and the resrvation had not yet changed its state to onboard.
The date that was previously set was 2012-01-14, The date that was previously set was 2012-01-14,
it was advanced one day (to 2012-01-15). it was advanced two days (to 2012-01-16).
There are three reservations with checkin day on 2012-01-14, There are three reservations with checkin day on 2012-01-15,
after invoking the method auto_arrival_delayed after invoking the method auto_arrival_delayed
those reservation change their state to 'auto_arrival_delayed' those reservation change their state to 'auto_arrival_delayed'
""" """
@@ -517,13 +518,13 @@ class TestPmsCheckinPartner(TestPms):
) )
self.reservation_1.write( self.reservation_1.write(
{ {
"checkin": datetime.date.today() + datetime.timedelta(days=4), "checkin": datetime.date.today() + datetime.timedelta(days=1),
"checkout": datetime.date.today() + datetime.timedelta(days=6), "checkout": datetime.date.today() + datetime.timedelta(days=6),
"adults": 1, "adults": 1,
} }
) )
reservation2_vals = { reservation2_vals = {
"checkin": datetime.date.today() + datetime.timedelta(days=4), "checkin": datetime.date.today() + datetime.timedelta(days=1),
"checkout": datetime.date.today() + datetime.timedelta(days=6), "checkout": datetime.date.today() + datetime.timedelta(days=6),
"adults": 1, "adults": 1,
"room_type_id": self.room_type1.id, "room_type_id": self.room_type1.id,
@@ -532,7 +533,7 @@ class TestPmsCheckinPartner(TestPms):
"folio_id": self.reservation_1.folio_id.id, "folio_id": self.reservation_1.folio_id.id,
} }
reservation3_vals = { reservation3_vals = {
"checkin": datetime.date.today() + datetime.timedelta(days=4), "checkin": datetime.date.today() + datetime.timedelta(days=1),
"checkout": datetime.date.today() + datetime.timedelta(days=6), "checkout": datetime.date.today() + datetime.timedelta(days=6),
"adults": 1, "adults": 1,
"room_type_id": self.room_type1.id, "room_type_id": self.room_type1.id,
@@ -546,7 +547,7 @@ class TestPmsCheckinPartner(TestPms):
PmsReservation = self.env["pms.reservation"] PmsReservation = self.env["pms.reservation"]
# ACTION # ACTION
freezer = freeze_time("2012-01-19 10:00:00") freezer = freeze_time("2012-01-16 10:00:00")
freezer.start() freezer.start()
PmsReservation.auto_arrival_delayed() PmsReservation.auto_arrival_delayed()
@@ -562,6 +563,120 @@ class TestPmsCheckinPartner(TestPms):
) )
freezer.stop() freezer.stop()
@freeze_time("2012-01-14")
def test_auto_arrival_delayed_checkout(self):
"""
The state of reservation 'arrival_delayed' happen when the checkin day
has already passed and the resrvation had not yet changed its state to onboard.
But, if checkout day is passed without checkout, the reservation pass to
departure delayed with a reservation note warning
The date that was previously set was 2012-01-14,
it was advanced two days (to 2012-01-16).
There are three reservations with checkout day on 2012-01-15,
after invoking the method auto_arrival_delayed
those reservation change their state to 'departure_delayed'
"""
# ARRANGE
self.host2 = self.env["res.partner"].create(
{
"name": "Carlos",
"mobile": "654667733",
"email": "carlos@example.com",
"birthdate_date": "1995-12-10",
"gender": "male",
}
)
self.env["res.partner.id_number"].create(
{
"category_id": self.id_category.id,
"name": "61369791H",
"valid_from": datetime.date.today(),
"partner_id": self.host2.id,
}
)
self.host3 = self.env["res.partner"].create(
{
"name": "Enmanuel",
"mobile": "654667733",
"email": "enmanuel@example.com",
"birthdate_date": "1995-12-10",
"gender": "male",
}
)
self.env["res.partner.id_number"].create(
{
"category_id": self.id_category.id,
"name": "53563260D",
"valid_from": datetime.date.today(),
"partner_id": self.host3.id,
}
)
self.host4 = self.env["res.partner"].create(
{
"name": "Enrique",
"mobile": "654667733",
"email": "enrique@example.com",
"birthdate_date": "1995-12-10",
"gender": "male",
}
)
self.env["res.partner.id_number"].create(
{
"category_id": self.id_category.id,
"name": "63742138F",
"valid_from": datetime.date.today(),
"partner_id": self.host4.id,
}
)
self.reservation_1.write(
{
"checkin": datetime.date.today(),
"checkout": datetime.date.today() + datetime.timedelta(days=1),
"adults": 1,
}
)
reservation2_vals = {
"checkin": datetime.date.today(),
"checkout": datetime.date.today() + datetime.timedelta(days=1),
"adults": 1,
"room_type_id": self.room_type1.id,
"partner_id": self.host1.id,
"pms_property_id": self.pms_property1.id,
"folio_id": self.reservation_1.folio_id.id,
}
reservation3_vals = {
"checkin": datetime.date.today(),
"checkout": datetime.date.today() + datetime.timedelta(days=1),
"adults": 1,
"room_type_id": self.room_type1.id,
"partner_id": self.host1.id,
"pms_property_id": self.pms_property1.id,
"folio_id": self.reservation_1.folio_id.id,
}
self.reservation_2 = self.env["pms.reservation"].create(reservation2_vals)
self.reservation_3 = self.env["pms.reservation"].create(reservation3_vals)
folio_1 = self.reservation_1.folio_id
PmsReservation = self.env["pms.reservation"]
# ACTION
freezer = freeze_time("2012-01-16 10:00:00")
freezer.start()
PmsReservation.auto_arrival_delayed()
departure_delayed_reservations = folio_1.reservation_ids.filtered(
lambda r: r.state == "departure_delayed"
)
# ASSERT
self.assertEqual(
len(departure_delayed_reservations),
3,
"Reservations not set like No Show",
)
freezer.stop()
@freeze_time("2012-01-14") @freeze_time("2012-01-14")
def test_auto_departure_delayed(self): def test_auto_departure_delayed(self):
""" """
@@ -1201,15 +1316,15 @@ class TestPmsCheckinPartner(TestPms):
is = 20 years old and document_date = today + 1 year. The expected is = 20 years old and document_date = today + 1 year. The expected
expedition date has to be doc_date - 5 years expedition date has to be doc_date - 5 years
""" """
doc_date = fields.date.today() + datetime.timedelta(days=366) doc_date = fields.date.today() + relativedelta(years=1)
doc_date_str = str(doc_date) doc_date_str = str(doc_date)
# age=20 years old # age=20 years old
birthdate = fields.date.today() - datetime.timedelta(days=7305) birthdate = fields.date.today() - relativedelta(years=20)
birthdate_str = str(birthdate) birthdate_str = str(birthdate)
# expected_expedition_date = doc_date - 5 years # expected_expedition_date = doc_date - 5 years
expected_exp_date = doc_date - datetime.timedelta(days=1826.25) expected_exp_date = doc_date - relativedelta(years=5)
expedition_date = ( expedition_date = (
self.checkin1.calculate_doc_type_expedition_date_from_validity_date( self.checkin1.calculate_doc_type_expedition_date_from_validity_date(
self.id_category, doc_date_str, birthdate_str self.id_category, doc_date_str, birthdate_str
@@ -1237,15 +1352,15 @@ class TestPmsCheckinPartner(TestPms):
is = 40 years old and document_date = today + 1 year. The expected is = 40 years old and document_date = today + 1 year. The expected
expedition date has to be doc_date - 10 years expedition date has to be doc_date - 10 years
""" """
doc_date = fields.date.today() + datetime.timedelta(days=366) doc_date = fields.date.today() + relativedelta(years=1)
doc_date_str = str(doc_date) doc_date_str = str(doc_date)
# age=40 years old # age=40 years old
birthdate = fields.date.today() - datetime.timedelta(days=14610) birthdate = fields.date.today() - relativedelta(years=40)
birthdate_str = str(birthdate) birthdate_str = str(birthdate)
# expected_expedition_date = doc_date - 10 years # expected_expedition_date = doc_date - 10 years
expected_exp_date = doc_date - datetime.timedelta(days=3652.5) expected_exp_date = doc_date - relativedelta(years=10)
expedition_date = ( expedition_date = (
self.checkin1.calculate_doc_type_expedition_date_from_validity_date( self.checkin1.calculate_doc_type_expedition_date_from_validity_date(
self.id_category, doc_date_str, birthdate_str self.id_category, doc_date_str, birthdate_str
@@ -1273,15 +1388,15 @@ class TestPmsCheckinPartner(TestPms):
is = 20 years old and document_date = today + 1 year. The expected is = 20 years old and document_date = today + 1 year. The expected
expedition date has to be doc_date - 5 years expedition date has to be doc_date - 5 years
""" """
doc_date = fields.date.today() + datetime.timedelta(days=366) doc_date = fields.date.today() + relativedelta(years=1)
doc_date_str = str(doc_date) doc_date_str = str(doc_date)
# age=20 years old # age=20 years old
birthdate = fields.date.today() - datetime.timedelta(days=7305) birthdate = fields.date.today() - relativedelta(years=20)
birthdate_str = str(birthdate) birthdate_str = str(birthdate)
# expected_expedition_date = doc_date - 5 years # expected_expedition_date = doc_date - 5 years
expected_exp_date = doc_date - datetime.timedelta(days=1826.25) expected_exp_date = doc_date - relativedelta(years=5)
expedition_date = ( expedition_date = (
self.checkin1.calculate_doc_type_expedition_date_from_validity_date( self.checkin1.calculate_doc_type_expedition_date_from_validity_date(
self.id_category, doc_date_str, birthdate_str self.id_category, doc_date_str, birthdate_str
@@ -1310,15 +1425,15 @@ class TestPmsCheckinPartner(TestPms):
expedition date has to be doc_date - 10 years expedition date has to be doc_date - 10 years
""" """
doc_type_id = self.env["res.partner.id_category"].search([("code", "=", "P")]) doc_type_id = self.env["res.partner.id_category"].search([("code", "=", "P")])
doc_date = fields.date.today() + datetime.timedelta(days=366) doc_date = fields.date.today() + relativedelta(years=1)
doc_date_str = str(doc_date) doc_date_str = str(doc_date)
# age=40 years old # age=40 years old
birthdate = fields.date.today() - datetime.timedelta(days=14610) birthdate = fields.date.today() - relativedelta(years=40)
birthdate_str = str(birthdate) birthdate_str = str(birthdate)
# expected_expedition_date = doc_date - 10 years # expected_expedition_date = doc_date - 10 years
expected_exp_date = doc_date - datetime.timedelta(days=3652.5) expected_exp_date = doc_date - relativedelta(years=10)
expedition_date = ( expedition_date = (
self.checkin1.calculate_doc_type_expedition_date_from_validity_date( self.checkin1.calculate_doc_type_expedition_date_from_validity_date(
doc_type_id, doc_date_str, birthdate_str doc_type_id, doc_date_str, birthdate_str
@@ -1347,15 +1462,15 @@ class TestPmsCheckinPartner(TestPms):
expedition date has to be doc_date - 10 years expedition date has to be doc_date - 10 years
""" """
doc_type_id = self.env["res.partner.id_category"].search([("code", "=", "C")]) doc_type_id = self.env["res.partner.id_category"].search([("code", "=", "C")])
doc_date = fields.date.today() + datetime.timedelta(days=366) doc_date = fields.date.today() + relativedelta(years=1)
doc_date_str = str(doc_date) doc_date_str = str(doc_date)
# age=40 years old # age=40 years old
birthdate = fields.date.today() - datetime.timedelta(days=14610) birthdate = fields.date.today() - relativedelta(years=40)
birthdate_str = str(birthdate) birthdate_str = str(birthdate)
# expected_expedition_date = doc_date - 10 years # expected_expedition_date = doc_date - 10 years
expected_exp_date = doc_date - datetime.timedelta(days=3652.5) expected_exp_date = doc_date - relativedelta(years=10)
expedition_date = ( expedition_date = (
self.checkin1.calculate_doc_type_expedition_date_from_validity_date( self.checkin1.calculate_doc_type_expedition_date_from_validity_date(
doc_type_id, doc_date_str, birthdate_str doc_type_id, doc_date_str, birthdate_str
@@ -1384,9 +1499,9 @@ class TestPmsCheckinPartner(TestPms):
expedition date has to be the value of doc_date. expedition date has to be the value of doc_date.
""" """
doc_type_id = self.env["res.partner.id_category"].search([("code", "=", "D")]) doc_type_id = self.env["res.partner.id_category"].search([("code", "=", "D")])
doc_date = fields.date.today() - datetime.timedelta(days=366) doc_date = fields.date.today() - relativedelta(years=1)
doc_date_str = str(doc_date) doc_date_str = str(doc_date)
birthdate = fields.date.today() - datetime.timedelta(days=7305) birthdate = fields.date.today() - relativedelta(years=20)
birthdate_str = str(birthdate) birthdate_str = str(birthdate)
expedition_date = ( expedition_date = (
self.checkin1.calculate_doc_type_expedition_date_from_validity_date( self.checkin1.calculate_doc_type_expedition_date_from_validity_date(
@@ -1435,7 +1550,7 @@ class TestPmsCheckinPartner(TestPms):
"lastname2": "Gonzalez", "lastname2": "Gonzalez",
"document_type": self.id_category.code, "document_type": self.id_category.code,
"document_number": "18038946T", "document_number": "18038946T",
"document_expedition_date": "2015-10-07", "document_expedition_date": "2010-10-07",
"birthdate_date": "1983-10-05", "birthdate_date": "1983-10-05",
"mobile": "60595595", "mobile": "60595595",
"email": "serafin@example.com", "email": "serafin@example.com",
@@ -1450,7 +1565,7 @@ class TestPmsCheckinPartner(TestPms):
checkin_partner_vals.update( checkin_partner_vals.update(
{ {
"birthdate_date": datetime.date(1983, 10, 5), "birthdate_date": datetime.date(1983, 10, 5),
"document_expedition_date": datetime.date(2015, 10, 7), "document_expedition_date": datetime.date(2010, 10, 7),
"nationality_id": nationality_id, "nationality_id": nationality_id,
} }
) )

View File

@@ -103,6 +103,7 @@ class TestPmsReservations(TestPms):
} }
) )
@freeze_time("2012-01-14")
def test_reservation_dates_not_consecutive(self): def test_reservation_dates_not_consecutive(self):
""" """
Check the constrain if not consecutive dates Check the constrain if not consecutive dates
@@ -132,6 +133,7 @@ class TestPmsReservations(TestPms):
} }
) )
@freeze_time("2012-01-14")
def test_reservation_dates_compute_checkin_out(self): def test_reservation_dates_compute_checkin_out(self):
""" """
Check the reservation creation with specific reservation lines Check the reservation creation with specific reservation lines
@@ -175,6 +177,7 @@ class TestPmsReservations(TestPms):
not correspond to the last day indicated in the dates", not correspond to the last day indicated in the dates",
) )
@freeze_time("2012-01-14")
def test_create_reservation_start_date(self): def test_create_reservation_start_date(self):
""" """
Check that the reservation checkin and the first reservation date are equal. Check that the reservation checkin and the first reservation date are equal.
@@ -205,6 +208,7 @@ class TestPmsReservations(TestPms):
"Reservation lines don't start in the correct date", "Reservation lines don't start in the correct date",
) )
@freeze_time("2012-01-14")
def test_create_reservation_end_date(self): def test_create_reservation_end_date(self):
""" """
Check that the reservation checkout and the last reservation date are equal. Check that the reservation checkout and the last reservation date are equal.
@@ -233,6 +237,7 @@ class TestPmsReservations(TestPms):
"Reservation lines don't end in the correct date", "Reservation lines don't end in the correct date",
) )
@freeze_time("2012-01-14")
def test_split_reservation01(self): def test_split_reservation01(self):
""" """
# TEST CASE # TEST CASE
@@ -270,6 +275,7 @@ class TestPmsReservations(TestPms):
"The entire reservation should be allocated in the preferred room", "The entire reservation should be allocated in the preferred room",
) )
@freeze_time("2012-01-14")
def test_split_reservation02(self): def test_split_reservation02(self):
""" """
# TEST CASE # TEST CASE
@@ -389,6 +395,7 @@ class TestPmsReservations(TestPms):
"The reservation shouldn't have more than 2 changes", "The reservation shouldn't have more than 2 changes",
) )
@freeze_time("2012-01-14")
def test_split_reservation04(self): def test_split_reservation04(self):
""" """
# TEST CASE # TEST CASE
@@ -494,6 +501,7 @@ class TestPmsReservations(TestPms):
3, rooms, "The reservation shouldn't be splitted in more than 3 roomss" 3, rooms, "The reservation shouldn't be splitted in more than 3 roomss"
) )
@freeze_time("2012-01-14")
def test_split_reservation05(self): def test_split_reservation05(self):
""" """
# TEST CASE # TEST CASE
@@ -535,6 +543,7 @@ class TestPmsReservations(TestPms):
) )
r_test.flush() r_test.flush()
@freeze_time("2012-01-14")
def test_split_reservation06(self): def test_split_reservation06(self):
""" """
# TEST CASE # TEST CASE
@@ -577,6 +586,7 @@ class TestPmsReservations(TestPms):
) )
r_test.flush() r_test.flush()
@freeze_time("2012-01-14")
def test_split_reservation07(self): def test_split_reservation07(self):
""" """
# TEST CASE # TEST CASE
@@ -648,6 +658,7 @@ class TestPmsReservations(TestPms):
} }
) )
@freeze_time("2012-01-14")
def test_manage_children_raise(self): def test_manage_children_raise(self):
# TEST CASE # TEST CASE
""" """
@@ -675,6 +686,7 @@ class TestPmsReservations(TestPms):
) )
reservation.flush() reservation.flush()
@freeze_time("2012-01-14")
def test_to_assign_priority_reservation(self): def test_to_assign_priority_reservation(self):
""" """
To assign reservation must have priority = 1 To assign reservation must have priority = 1
@@ -729,6 +741,7 @@ class TestPmsReservations(TestPms):
error_msm, error_msm,
) )
@freeze_time("2012-01-14")
def test_arrival_delayed_priority_reservation(self): def test_arrival_delayed_priority_reservation(self):
""" """
Arrival delayed reservation must have priority = 1 Arrival delayed reservation must have priority = 1
@@ -767,69 +780,70 @@ class TestPmsReservations(TestPms):
error_msm, error_msm,
) )
@freeze_time("1981-11-10") # @freeze_time("1981-11-10")
def test_departure_delayed_priority_reservation(self): # def test_departure_delayed_priority_reservation(self):
""" # """
To departure delayed reservation must have priority = 1 # To departure delayed reservation must have priority = 1
------ # ------
Create a reservation and make the work flow to onboard state, # Create a reservation and make the work flow to onboard state,
using jump dates, we make the reservation should have left yesterday, # using jump dates, we make the reservation should have left yesterday,
regardless of the rest of the fields the priority must be 1 # regardless of the rest of the fields the priority must be 1
""" # """
# ARRANGE # # ARRANGE
expected_priority = 1 # expected_priority = 1
freezer = freeze_time("1981-10-08") # freezer = freeze_time("1981-11-08")
freezer.start() # freezer.start()
res = self.env["pms.reservation"].create( # res = self.env["pms.reservation"].create(
{ # {
"checkin": fields.date.today(), # "checkin": fields.date.today(),
"checkout": fields.date.today() + datetime.timedelta(days=1), # "checkout": fields.date.today() + datetime.timedelta(days=1),
"preferred_room_id": self.room2.id, # "preferred_room_id": self.room2.id,
"partner_id": self.partner1.id, # "partner_id": self.partner1.id,
"pms_property_id": self.pms_property1.id, # "pms_property_id": self.pms_property1.id,
} # }
) # )
host1 = self.env["res.partner"].create( # host1 = self.env["res.partner"].create(
{ # {
"firstname": "Pepe", # "firstname": "Pepe",
"lastname": "Paz", # "lastname": "Paz",
"email": "pepe@example.com", # "email": "pepe@example.com",
"birthdate_date": "1995-12-10", # "birthdate_date": "1995-12-10",
"gender": "male", # "gender": "male",
} # }
) # )
checkin1 = self.env["pms.checkin.partner"].create( # checkin1 = self.env["pms.checkin.partner"].create(
{ # {
"partner_id": host1.id, # "partner_id": host1.id,
"reservation_id": res.id, # "reservation_id": res.id,
"document_type": self.id_category.id, # "document_type": self.id_category.id,
"document_number": "77156490T", # "document_number": "77156490T",
"document_expedition_date": fields.date.today() # "document_expedition_date": fields.date.today()
+ datetime.timedelta(days=665), # + datetime.timedelta(days=665),
} # }
) # )
checkin1.action_on_board() # checkin1.action_on_board()
freezer.stop() # freezer.stop()
# ACT # # ACT
res.auto_departure_delayed() # res.auto_departure_delayed()
computed_priority = res.priority # computed_priority = res.priority
# ASSERT # # ASSERT
error_msm = ( # error_msm = (
( # (
"The priority of a departure delayed reservation \ # "The priority of a departure delayed reservation \
should be %d and this is %d" # should be %d and this is %d"
) # )
% (expected_priority, computed_priority) # % (expected_priority, computed_priority)
) # )
self.assertEqual( # self.assertEqual(
computed_priority, # computed_priority,
expected_priority, # expected_priority,
error_msm, # error_msm,
) # )
@freeze_time("2012-01-14")
def test_cancel_pending_amount_priority_reservation(self): def test_cancel_pending_amount_priority_reservation(self):
""" """
Cancelled with pending payments reservation must have priority = 2 Cancelled with pending payments reservation must have priority = 2
@@ -999,6 +1013,7 @@ class TestPmsReservations(TestPms):
error_msm, error_msm,
) )
@freeze_time("2012-01-14")
def test_confirm_arriva_lt_3_days_priority_reservation(self): def test_confirm_arriva_lt_3_days_priority_reservation(self):
""" """
Confirm reservation with arrival in less than 3 days, priority = 2 * days for checkout Confirm reservation with arrival in less than 3 days, priority = 2 * days for checkout
@@ -1036,6 +1051,7 @@ class TestPmsReservations(TestPms):
error_msm, error_msm,
) )
@freeze_time("2012-01-14")
def test_onboard_all_pay_priority_reservation(self): def test_onboard_all_pay_priority_reservation(self):
""" """
Onboard with all pay reservation must have priority = 3 * days for checkout Onboard with all pay reservation must have priority = 3 * days for checkout
@@ -1174,6 +1190,7 @@ class TestPmsReservations(TestPms):
error_msm, error_msm,
) )
@freeze_time("2012-01-14")
def test_confirm_arriva_bt_3_and_20_days_priority_reservation(self): 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 Confirm reservation with arrival between 3 and 20 days, priority = 3 * days for checkout
@@ -1211,6 +1228,7 @@ class TestPmsReservations(TestPms):
error_msm, error_msm,
) )
@freeze_time("2012-01-14")
def test_confirm_arrival_more_than_20_days_priority_reservation(self): def test_confirm_arrival_more_than_20_days_priority_reservation(self):
""" """
Confirm reservation with arrival more than 20 days, priority = 4 * days for checkout Confirm reservation with arrival more than 20 days, priority = 4 * days for checkout
@@ -1859,6 +1877,7 @@ class TestPmsReservations(TestPms):
url = "/my/reservations/%s" % reservation.id url = "/my/reservations/%s" % reservation.id
self.assertEqual(reservation.access_url, url, "Reservation url isn't correct") self.assertEqual(reservation.access_url, url, "Reservation url isn't correct")
@freeze_time("2012-01-14")
def test_compute_ready_for_checkin(self): def test_compute_ready_for_checkin(self):
""" """
Check that the ready_for_checkin field is True when the reservation Check that the ready_for_checkin field is True when the reservation
@@ -1959,6 +1978,7 @@ class TestPmsReservations(TestPms):
} }
) )
@freeze_time("2012-01-14")
def test_check_more_adults_than_beds(self): def test_check_more_adults_than_beds(self):
""" """
Check that a reservation cannot be created when the field Check that a reservation cannot be created when the field
@@ -1986,6 +2006,7 @@ class TestPmsReservations(TestPms):
) )
reservation.flush() reservation.flush()
@freeze_time("2012-01-14")
def test_check_format_arrival_hour(self): def test_check_format_arrival_hour(self):
""" """
Check that the format of the arrival_hour field is correct(HH:mm) Check that the format of the arrival_hour field is correct(HH:mm)
@@ -2009,6 +2030,7 @@ class TestPmsReservations(TestPms):
} }
) )
@freeze_time("2012-01-14")
def test_check_format_departure_hour(self): def test_check_format_departure_hour(self):
""" """
Check that the format of the departure_hour field is correct(HH:mm) Check that the format of the departure_hour field is correct(HH:mm)
@@ -2032,6 +2054,7 @@ class TestPmsReservations(TestPms):
} }
) )
@freeze_time("2012-01-14")
def test_check_property_integrity_room(self): def test_check_property_integrity_room(self):
""" """
Check that a reservation cannot be created with a room Check that a reservation cannot be created with a room
@@ -2068,6 +2091,7 @@ class TestPmsReservations(TestPms):
} }
) )
@freeze_time("2012-01-14")
def test_shared_folio_true(self): def test_shared_folio_true(self):
""" """
Check that the shared_folio field of a reservation whose Check that the shared_folio field of a reservation whose
@@ -2104,6 +2128,7 @@ class TestPmsReservations(TestPms):
"Folio.reservations > 1, so reservation.shared_folio must be True", "Folio.reservations > 1, so reservation.shared_folio must be True",
) )
@freeze_time("2012-01-14")
def test_shared_folio_false(self): def test_shared_folio_false(self):
""" """
Check that the shared_folio field for a reservation whose folio has no Check that the shared_folio field for a reservation whose folio has no
@@ -2127,6 +2152,7 @@ class TestPmsReservations(TestPms):
"Folio.reservations = 1, so reservation.shared_folio must be False", "Folio.reservations = 1, so reservation.shared_folio must be False",
) )
@freeze_time("2012-01-14")
def test_reservation_action_cancel_fail(self): def test_reservation_action_cancel_fail(self):
""" """
Check that a reservation cannot be in the cancel state if Check that a reservation cannot be in the cancel state if
@@ -2157,6 +2183,7 @@ class TestPmsReservations(TestPms):
with self.assertRaises(UserError): with self.assertRaises(UserError):
reservation.action_cancel() reservation.action_cancel()
@freeze_time("2012-01-14")
def test_cancelation_reason_noshow(self): def test_cancelation_reason_noshow(self):
""" """
Check that if a reservation has already passed and there is no check-in, Check that if a reservation has already passed and there is no check-in,
@@ -2208,6 +2235,7 @@ class TestPmsReservations(TestPms):
"cancelled_reason must be 'noshow'", "cancelled_reason must be 'noshow'",
) )
@freeze_time("2012-01-14")
def test_cancelation_reason_intime(self): def test_cancelation_reason_intime(self):
""" """
Check that if a reservation is canceled on time according Check that if a reservation is canceled on time according
@@ -2258,6 +2286,7 @@ class TestPmsReservations(TestPms):
reservation.cancelled_reason, "intime", "Cancelled reason must be 'intime'" reservation.cancelled_reason, "intime", "Cancelled reason must be 'intime'"
) )
@freeze_time("2012-01-14")
def test_cancelation_reason_late(self): def test_cancelation_reason_late(self):
""" """
Check that if a reservation is canceled outside the cancellation Check that if a reservation is canceled outside the cancellation
@@ -2304,6 +2333,7 @@ class TestPmsReservations(TestPms):
reservation.flush() reservation.flush()
self.assertEqual(reservation.cancelled_reason, "late", "-----------") self.assertEqual(reservation.cancelled_reason, "late", "-----------")
@freeze_time("2012-01-14")
def test_compute_checkin_partner_count(self): def test_compute_checkin_partner_count(self):
""" """
Check that the number of guests of a reservation is equal Check that the number of guests of a reservation is equal
@@ -2329,8 +2359,8 @@ class TestPmsReservations(TestPms):
) )
self.reservation = self.env["pms.reservation"].create( self.reservation = self.env["pms.reservation"].create(
{ {
"checkin": "2013-01-14", "checkin": "2012-01-14",
"checkout": "2013-01-17", "checkout": "2012-01-17",
"partner_id": self.host1.id, "partner_id": self.host1.id,
"pms_property_id": self.pms_property1.id, "pms_property_id": self.pms_property1.id,
"adults": 3, "adults": 3,
@@ -2360,6 +2390,7 @@ class TestPmsReservations(TestPms):
"Checkin_partner_count must be match with number of checkin_partner_ids", "Checkin_partner_count must be match with number of checkin_partner_ids",
) )
@freeze_time("2012-01-14")
def test_compute_checkin_partner_pending_count(self): def test_compute_checkin_partner_pending_count(self):
""" """
Check that the checkin_partner_count field gives Check that the checkin_partner_count field gives
@@ -2388,8 +2419,8 @@ class TestPmsReservations(TestPms):
) )
self.reservation = self.env["pms.reservation"].create( self.reservation = self.env["pms.reservation"].create(
{ {
"checkin": "2014-01-14", "checkin": "2012-01-14",
"checkout": "2014-01-17", "checkout": "2012-01-17",
"partner_id": self.host1.id, "partner_id": self.host1.id,
"pms_property_id": self.pms_property1.id, "pms_property_id": self.pms_property1.id,
"room_type_id": self.room_type_triple.id, "room_type_id": self.room_type_triple.id,
@@ -2422,6 +2453,7 @@ class TestPmsReservations(TestPms):
"Checkin_partner_pending_count isn't correct", "Checkin_partner_pending_count isn't correct",
) )
@freeze_time("2012-01-14")
def test_reservation_action_checkout_fail(self): def test_reservation_action_checkout_fail(self):
""" """
Check that a reservation cannot be checkout because Check that a reservation cannot be checkout because
@@ -2453,6 +2485,7 @@ class TestPmsReservations(TestPms):
with self.assertRaises(UserError): with self.assertRaises(UserError):
reservation.action_reservation_checkout() reservation.action_reservation_checkout()
@freeze_time("2012-01-14")
def test_partner_name_folio(self): def test_partner_name_folio(self):
""" """
Check that a reservation without a partner_name Check that a reservation without a partner_name
@@ -2474,8 +2507,8 @@ class TestPmsReservations(TestPms):
self.reservation = self.env["pms.reservation"].create( self.reservation = self.env["pms.reservation"].create(
{ {
"checkin": "2014-01-14", "checkin": "2012-01-14",
"checkout": "2014-01-17", "checkout": "2012-01-17",
"pms_property_id": self.pms_property1.id, "pms_property_id": self.pms_property1.id,
"folio_id": self.folio1.id, "folio_id": self.folio1.id,
"room_type_id": self.room_type_double.id, "room_type_id": self.room_type_double.id,
@@ -2488,6 +2521,7 @@ class TestPmsReservations(TestPms):
"The folio partner name and the reservation partner name doesn't correspond", "The folio partner name and the reservation partner name doesn't correspond",
) )
@freeze_time("2012-01-14")
def test_partner_is_agency_not_invoice_to_agency(self): def test_partner_is_agency_not_invoice_to_agency(self):
""" """
Check that a reservation without partner_name but with Check that a reservation without partner_name but with
@@ -2950,6 +2984,7 @@ class TestPmsReservations(TestPms):
"Room discount isn't the expected", "Room discount isn't the expected",
) )
@freeze_time("2012-01-14")
def test_default_normal_reservation_type(self): def test_default_normal_reservation_type(self):
""" """
Check that the default reservation type is "normal". Check that the default reservation type is "normal".
@@ -2987,6 +3022,7 @@ class TestPmsReservations(TestPms):
"The default reservation type should be 'normal'", "The default reservation type should be 'normal'",
) )
@freeze_time("2012-01-14")
def test_price_normal_reservation(self): def test_price_normal_reservation(self):
""" """
Check the price of a normal type reservation. Check the price of a normal type reservation.
@@ -3020,6 +3056,7 @@ class TestPmsReservations(TestPms):
"The expected price of the reservation is not correct", "The expected price of the reservation is not correct",
) )
@freeze_time("2012-01-14")
def test_price_staff_reservation(self): def test_price_staff_reservation(self):
""" """
Check that the price of a staff type reservation Check that the price of a staff type reservation
@@ -3051,6 +3088,7 @@ class TestPmsReservations(TestPms):
"The expected price of the reservation is not correct", "The expected price of the reservation is not correct",
) )
@freeze_time("2012-01-14")
def test_price_out_of_service_reservation(self): def test_price_out_of_service_reservation(self):
""" """
Check that the price of a out type reservation Check that the price of a out type reservation
@@ -3089,6 +3127,7 @@ class TestPmsReservations(TestPms):
"The expected price of the reservation is not correct", "The expected price of the reservation is not correct",
) )
@freeze_time("2012-01-14")
def test_no_pricelist_staff_reservation(self): def test_no_pricelist_staff_reservation(self):
""" """
Check that in a staff type reservation the pricelist is False. Check that in a staff type reservation the pricelist is False.
@@ -3116,6 +3155,7 @@ class TestPmsReservations(TestPms):
"The pricelist of a staff reservation should be False", "The pricelist of a staff reservation should be False",
) )
@freeze_time("2012-01-14")
def test_no_pricelist_out_reservation(self): def test_no_pricelist_out_reservation(self):
""" """
Check that in a out type reservation the pricelist is False. Check that in a out type reservation the pricelist is False.
@@ -3151,6 +3191,7 @@ class TestPmsReservations(TestPms):
"The pricelist of a out of service reservation should be False", "The pricelist of a out of service reservation should be False",
) )
@freeze_time("2012-01-14")
def test_reservation_type_by_folio(self): def test_reservation_type_by_folio(self):
""" """
Check that the reservation type field in a reservation is the Check that the reservation type field in a reservation is the
@@ -3190,6 +3231,7 @@ class TestPmsReservations(TestPms):
"The reservation type of the folio should be 'staff'", "The reservation type of the folio should be 'staff'",
) )
@freeze_time("2012-01-14")
def test_no_partner_id_out_reservation(self): def test_no_partner_id_out_reservation(self):
""" """
Check that a reservation of type out of service does not Check that a reservation of type out of service does not
@@ -3226,6 +3268,7 @@ class TestPmsReservations(TestPms):
"The partner of an out of service reservation should be False", "The partner of an out of service reservation should be False",
) )
@freeze_time("2012-01-14")
def test_create_partner_in_reservation(self): def test_create_partner_in_reservation(self):
""" """
Check that a res_partner is created from a reservation. Check that a res_partner is created from a reservation.
@@ -3258,6 +3301,7 @@ class TestPmsReservations(TestPms):
# ASSERT # ASSERT
self.assertTrue(reservation.partner_id, "The partner has not been created") self.assertTrue(reservation.partner_id, "The partner has not been created")
@freeze_time("2012-01-14")
def test_auto_complete_partner_mobile(self): def test_auto_complete_partner_mobile(self):
""" """
It is checked that the mobile field of the reservation It is checked that the mobile field of the reservation
@@ -3312,6 +3356,7 @@ class TestPmsReservations(TestPms):
"The partner mobile has not autocomplete in reservation", "The partner mobile has not autocomplete in reservation",
) )
@freeze_time("2012-01-14")
def test_auto_complete_partner_email(self): def test_auto_complete_partner_email(self):
""" """
It is checked that the email field of the reservation It is checked that the email field of the reservation
@@ -3366,6 +3411,7 @@ class TestPmsReservations(TestPms):
"The partner mobile has not autocomplete in reservation", "The partner mobile has not autocomplete in reservation",
) )
@freeze_time("2012-01-14")
def test_is_possible_customer_by_email(self): def test_is_possible_customer_by_email(self):
""" """
It is checked that the field possible_existing_customer_ids It is checked that the field possible_existing_customer_ids
@@ -3402,6 +3448,7 @@ class TestPmsReservations(TestPms):
"No customer found with this email", "No customer found with this email",
) )
@freeze_time("2012-01-14")
def test_is_possible_customer_by_mobile(self): def test_is_possible_customer_by_mobile(self):
""" """
It is checked that the field possible_existing_customer_ids It is checked that the field possible_existing_customer_ids
@@ -3438,6 +3485,7 @@ class TestPmsReservations(TestPms):
"No customer found with this mobile", "No customer found with this mobile",
) )
@freeze_time("2012-01-14")
def test_add_possible_customer(self): def test_add_possible_customer(self):
""" """
Check that a partner was correctly added to the reservation Check that a partner was correctly added to the reservation
@@ -3487,6 +3535,7 @@ class TestPmsReservations(TestPms):
"The partner was not added to the reservation ", "The partner was not added to the reservation ",
) )
@freeze_time("2012-01-14")
def test_is_modified_reservation(self): def test_is_modified_reservation(self):
""" """
Checked that the is_modified_reservation field is correctly set Checked that the is_modified_reservation field is correctly set
@@ -3529,6 +3578,7 @@ class TestPmsReservations(TestPms):
"is_modified_reservation field should be True ", "is_modified_reservation field should be True ",
) )
@freeze_time("2012-01-14")
def test_is_not_modified_reservation(self): def test_is_not_modified_reservation(self):
""" """
Checked that the is_modified_reservation field is correctly set Checked that the is_modified_reservation field is correctly set
@@ -3561,6 +3611,7 @@ class TestPmsReservations(TestPms):
"is_modified_reservation field should be False ", "is_modified_reservation field should be False ",
) )
@freeze_time("2012-01-14")
def test_not_add_several_possibles_customers(self): def test_not_add_several_possibles_customers(self):
""" """
Check that multiple partners cannot be added to a reservation Check that multiple partners cannot be added to a reservation
@@ -3615,6 +3666,7 @@ class TestPmsReservations(TestPms):
): ):
several_partners_wizard.add_partner() several_partners_wizard.add_partner()
@freeze_time("2012-01-14")
def test_not_add_any_possibles_customers(self): def test_not_add_any_possibles_customers(self):
""" """
Check that the possible_existing_customer_ids field of the several Check that the possible_existing_customer_ids field of the several
@@ -3746,6 +3798,7 @@ class TestPmsReservations(TestPms):
"Reservation commission is wrong", "Reservation commission is wrong",
) )
@freeze_time("2012-01-14")
def test_closure_reason_out_of_service_mandatory_not(self): def test_closure_reason_out_of_service_mandatory_not(self):
""" """
Ouf of service reservation should contain a closure reason id. Ouf of service reservation should contain a closure reason id.
@@ -3773,6 +3826,7 @@ class TestPmsReservations(TestPms):
} }
) )
@freeze_time("2012-01-14")
def test_closure_reason_out_of_service_mandatory(self): def test_closure_reason_out_of_service_mandatory(self):
""" """
Ouf of service reservation should contain a closure reason id. Ouf of service reservation should contain a closure reason id.