Merge branch '14.0' into 14.0-pms_pricelist_rules_priority

This commit is contained in:
Darío Lodeiros
2020-12-01 12:32:44 +01:00
committed by GitHub
26 changed files with 1645 additions and 519 deletions

View File

@@ -22,3 +22,6 @@
from . import test_pms_reservation
from . import test_pms_pricelist
from . import test_pms_pricelist_priority
from . import test_pms_checkin_partner
from . import test_pms_sale_channel
from . import test_pms_folio

View File

@@ -0,0 +1,384 @@
import logging
from freezegun import freeze_time
from odoo import fields
from odoo.exceptions import ValidationError
from .common import TestHotel
_logger = logging.getLogger(__name__)
@freeze_time("2012-01-14")
class TestPmsCheckinPartner(TestHotel):
@classmethod
def arrange_single_checkin(cls):
# Arrange for one checkin on one reservation
cls.host1 = cls.env["res.partner"].create(
{
"name": "Miguel",
"phone": "654667733",
"email": "miguel@example.com",
}
)
reservation_vals = {
"checkin": "2012-01-14",
"checkout": "2012-01-17",
"room_type_id": cls.env.ref("pms.pms_room_type_3").id,
"partner_id": cls.host1.id,
"adults": 3,
"pms_property_id": cls.env.ref("pms.main_pms_property").id,
}
demo_user = cls.env.ref("base.user_demo")
cls.reservation_1 = (
cls.env["pms.reservation"].with_user(demo_user).create(reservation_vals)
)
cls.checkin1 = cls.env["pms.checkin.partner"].create(
{
"partner_id": cls.host1.id,
"reservation_id": cls.reservation_1.id,
}
)
def test_auto_create_checkins(self):
# ACTION
self.arrange_single_checkin()
checkins_count = len(self.reservation_1.checkin_partner_ids)
# ASSERT
self.assertEqual(
checkins_count,
3,
"the automatic partner checkin was not created successful",
)
def test_auto_unlink_checkins(self):
# ARRANGE
self.arrange_single_checkin()
# ACTION
host2 = self.env["res.partner"].create(
{
"name": "Carlos",
"phone": "654667733",
"email": "carlos@example.com",
}
)
self.reservation_1.checkin_partner_ids = [
(
0,
False,
{
"partner_id": host2.id,
},
)
]
checkins_count = len(self.reservation_1.checkin_partner_ids)
# ASSERT
self.assertEqual(
checkins_count,
3,
"the automatic partner checkin was not updated successful",
)
def test_onboard_checkin(self):
# ARRANGE
self.arrange_single_checkin()
# ACT & ASSERT
with self.assertRaises(ValidationError), self.cr.savepoint():
self.reservation_1.state = "onboard"
def test_onboard_reservation(self):
# ARRANGE
self.arrange_single_checkin()
# ACT
self.checkin1.action_on_board()
# ASSERT
self.assertEqual(
self.reservation_1.state,
"onboard",
"the reservation checkin was not successful",
)
def test_premature_checkin(self):
# ARRANGE
self.arrange_single_checkin()
self.reservation_1.write(
{
"checkin": "2012-01-15",
}
)
# ACT & ASSERT
with self.assertRaises(ValidationError), self.cr.savepoint():
self.checkin1.action_on_board()
def test_late_checkin(self):
# ARRANGE
self.arrange_single_checkin()
self.reservation_1.write(
{
"checkin": "2012-01-13",
}
)
# ACT
self.checkin1.action_on_board()
# ASSERT
self.assertEqual(
self.checkin1.arrival,
fields.datetime.now(),
"the late checkin has problems",
)
def test_too_many_people_checkin(self):
# ARRANGE
self.arrange_single_checkin()
host2 = self.env["res.partner"].create(
{
"name": "Carlos",
"phone": "654667733",
"email": "carlos@example.com",
}
)
host3 = self.env["res.partner"].create(
{
"name": "Enmanuel",
"phone": "654667733",
"email": "enmanuel@example.com",
}
)
host4 = self.env["res.partner"].create(
{
"name": "Enrique",
"phone": "654667733",
"email": "enrique@example.com",
}
)
self.env["pms.checkin.partner"].create(
{
"partner_id": host2.id,
"reservation_id": self.reservation_1.id,
}
)
self.env["pms.checkin.partner"].create(
{
"partner_id": host3.id,
"reservation_id": self.reservation_1.id,
}
)
# ACT & ASSERT
with self.assertRaises(ValidationError), self.cr.savepoint():
self.reservation_1.write(
{
"checkin_partner_ids": [
(
0,
0,
{
"partner_id": host4.id,
"reservation_id": self.reservation_1.id,
},
)
]
}
)
@classmethod
def arrange_folio_reservations(cls):
# Arrange on one folio with 3 reservations
demo_user = cls.env.ref("base.user_demo")
cls.host1 = cls.env["res.partner"].create(
{
"name": "Miguel",
"phone": "654667733",
"email": "miguel@example.com",
}
)
cls.host2 = cls.env["res.partner"].create(
{
"name": "Carlos",
"phone": "654667733",
"email": "carlos@example.com",
}
)
cls.host3 = cls.env["res.partner"].create(
{
"name": "Enmanuel",
"phone": "654667733",
"email": "enmanuel@example.com",
}
)
cls.host4 = cls.env["res.partner"].create(
{
"name": "Enrique",
"phone": "654667733",
"email": "enrique@example.com",
}
)
folio_vals = {
"partner_id": cls.host1.id,
}
cls.folio_1 = cls.env["pms.folio"].with_user(demo_user).create(folio_vals)
reservation1_vals = {
"checkin": "2012-01-14",
"checkout": "2012-01-17",
"room_type_id": cls.env.ref("pms.pms_room_type_3").id,
"partner_id": cls.host1.id,
"adults": 3,
"pms_property_id": cls.env.ref("pms.main_pms_property").id,
"folio_id": cls.folio_1.id,
}
reservation2_vals = {
"checkin": "2012-01-14",
"checkout": "2012-01-17",
"room_type_id": cls.env.ref("pms.pms_room_type_2").id,
"partner_id": cls.host1.id,
"adults": 2,
"pms_property_id": cls.env.ref("pms.main_pms_property").id,
"folio_id": cls.folio_1.id,
}
reservation3_vals = {
"checkin": "2012-01-14",
"checkout": "2012-01-17",
"room_type_id": cls.env.ref("pms.pms_room_type_2").id,
"partner_id": cls.host1.id,
"adults": 2,
"pms_property_id": cls.env.ref("pms.main_pms_property").id,
"folio_id": cls.folio_1.id,
}
cls.reservation_1 = (
cls.env["pms.reservation"].with_user(demo_user).create(reservation1_vals)
)
cls.reservation_2 = (
cls.env["pms.reservation"].with_user(demo_user).create(reservation2_vals)
)
cls.reservation_3 = (
cls.env["pms.reservation"].with_user(demo_user).create(reservation3_vals)
)
def test_count_pending_arrival_persons(self):
# ARRANGE
self.arrange_folio_reservations()
self.checkin1 = self.env["pms.checkin.partner"].create(
{
"partner_id": self.host1.id,
"reservation_id": self.reservation_1.id,
}
)
self.checkin2 = self.env["pms.checkin.partner"].create(
{
"partner_id": self.host2.id,
"reservation_id": self.reservation_1.id,
}
)
self.checkin3 = self.env["pms.checkin.partner"].create(
{
"partner_id": self.host3.id,
"reservation_id": self.reservation_1.id,
}
)
# ACT
self.checkin1.action_on_board()
self.checkin2.action_on_board()
# ASSERT
self.assertEqual(
self.reservation_1.count_pending_arrival,
1,
"Fail the count pending arrival on reservation",
)
self.assertEqual(
self.reservation_1.checkins_ratio,
int(2 * 100 / 3),
"Fail the checkins ratio on reservation",
)
def test_complete_checkin_data(self):
# ARRANGE
self.arrange_folio_reservations()
# ACT
self.checkin1 = self.env["pms.checkin.partner"].create(
{
"partner_id": self.host1.id,
"reservation_id": self.reservation_1.id,
}
)
self.checkin2 = self.env["pms.checkin.partner"].create(
{
"partner_id": self.host2.id,
"reservation_id": self.reservation_1.id,
}
)
pending_checkin_data = self.reservation_1.pending_checkin_data
ratio_checkin_data = self.reservation_1.ratio_checkin_data
# ASSERT
self.assertEqual(
pending_checkin_data,
1,
"Fail the count pending checkin data on reservation",
)
self.assertEqual(
ratio_checkin_data,
int(2 * 100 / 3),
"Fail the checkins data ratio on reservation",
)
def test_auto_no_show(self):
# ARRANGE
self.arrange_folio_reservations()
PmsReservation = self.env["pms.reservation"]
# ACTION
freezer = freeze_time("2012-01-15 10:00:00")
freezer.start()
PmsReservation.auto_no_show()
no_show_reservations = PmsReservation.search([("state", "=", "no_show")])
# ASSERT
self.assertEqual(
len(no_show_reservations),
3,
"Reservations not set like No Show",
)
freezer.stop()
def test_auto_no_checkout(self):
# ARRANGE
self.arrange_single_checkin()
PmsReservation = self.env["pms.reservation"]
self.checkin1.action_on_board()
# ACTION
freezer = freeze_time("2012-01-17 12:00:00")
freezer.start()
PmsReservation.auto_no_checkout()
no_checkout_reservations = PmsReservation.search(
[("state", "=", "no_checkout")]
)
freezer.stop()
# ASSERT
self.assertEqual(
len(no_checkout_reservations),
1,
"Reservations not set like No checkout",
)

View File

@@ -0,0 +1,58 @@
import datetime
from freezegun import freeze_time
from .common import TestHotel
freeze_time("2000-02-02")
class TestPmsFolio(TestHotel):
def test_commission_and_partner_correct(self):
# ARRANGE
PmsFolio = self.env["pms.folio"]
PmsReservation = self.env["pms.reservation"]
PmsPartner = self.env["res.partner"]
PmsSaleChannel = self.env["pms.sale.channel"]
# ACT
saleChannel = PmsSaleChannel.create(
{"name": "saleChannel1", "channel_type": "indirect"}
)
agency = PmsPartner.create(
{
"name": "partner1",
"is_agency": True,
"invoice_agency": True,
"default_commission": 15,
"sale_channel_id": saleChannel.id,
}
)
reservation = PmsReservation.create(
{
"checkin": datetime.datetime.now(),
"checkout": datetime.datetime.now() + datetime.timedelta(days=3),
"agency_id": agency.id,
}
)
folio = PmsFolio.create(
{
"agency_id": agency.id,
"reservation_ids": [reservation.id],
}
)
commission = 0
for reservation in folio:
commission += reservation.commission_amount
# ASSERT
self.assertEqual(
folio.commission,
commission,
"Folio commission don't math with his reservation commission",
)
if folio.agency_id:
self.assertEqual(
folio.agency_id, folio.partner_id, "Agency has to be the partner"
)

View File

@@ -0,0 +1,103 @@
import datetime
from freezegun import freeze_time
from odoo.exceptions import ValidationError
from .common import TestHotel
@freeze_time("2010-01-01")
class TestPmsSaleChannel(TestHotel):
def test_not_agency_as_agency(self):
# ARRANGE
PmsReservation = self.env["pms.reservation"]
not_agency = self.env["res.partner"].create(
{"name": "partner1", "is_agency": False}
)
# ACT & ASSERT
with self.assertRaises(ValidationError), self.cr.savepoint():
PmsReservation.create(
{
"checkin": datetime.datetime.now(),
"checkout": datetime.datetime.now() + datetime.timedelta(days=3),
"agency_id": not_agency.id,
}
)
def test_partner_as_direct_channel(self):
# ARRANGE
PmsReservation = self.env["pms.reservation"]
partner = self.env.ref("base.res_partner_12")
# ACT & ASSERT
with self.assertRaises(ValidationError), self.cr.savepoint():
PmsReservation.create(
{
"checkin": datetime.datetime.now(),
"checkout": datetime.datetime.now() + datetime.timedelta(days=3),
"channel_type_id": partner.id,
}
)
def test_channel_type_id_only_directs(self):
# ARRANGE
PmsReservation = self.env["pms.reservation"]
PmsSaleChannel = self.env["pms.sale.channel"]
# ACT
saleChannel = PmsSaleChannel.create({"channel_type": "direct"})
reservation = PmsReservation.create(
{
"checkin": datetime.datetime.now(),
"checkout": datetime.datetime.now() + datetime.datetimedelta(days=3),
"channel_type_id": saleChannel.id,
}
)
# ASSERT
self.assertEqual(
self.browse_ref(reservation.channel_type_id).channel_type,
"direct",
"Sale channel is not direct",
)
def test_agency_id_is_agency(self):
# ARRANGE
PmsReservation = self.env["pms.reservation"]
# ACT
agency = self.env["res.partner"].create({"name": "partner1", "is_agency": True})
reservation = PmsReservation.create(
{
"checkin": datetime.datetime.now(),
"checkout": datetime.datetime.now() + datetime.datetimedelta(days=3),
"agency_id": agency.id,
}
)
# ASSERT
self.assertEqual(
self.browse_ref(reservation.agency_id).is_agency,
True,
"Agency_id doesn't correspond to an agency",
)
def test_sale_channel_id_only_indirect(self):
# ARRANGE
PmsSaleChannel = self.env["pms.sale.channel"]
# ACT
saleChannel = PmsSaleChannel.create({"channel_type": "indirect"})
agency = self.env["res.partner"].create(
{"name": "example", "is_agency": True, "sale_channel_id": saleChannel.id}
)
# ASSERT
self.assertEqual(
self.browse_ref(agency.sale_channel_id).channel_type,
"indirect",
"An agency should be a indirect channel",
)
def test_agency_without_sale_channel_id(self):
# ARRANGE & ACT & ASSERT
with self.assertRaises(ValidationError), self.cr.savepoint():
self.env["res.partner"].create(
{"name": "example", "is_agency": True, "sale_channel_id": None}
)