diff --git a/pms/models/pms_reservation.py b/pms/models/pms_reservation.py
index 77607787c..3ee218c74 100644
--- a/pms/models/pms_reservation.py
+++ b/pms/models/pms_reservation.py
@@ -187,6 +187,15 @@ class PmsReservation(models.Model):
)
# TODO: Warning Mens to update pricelist
checkin_partner_ids = fields.One2many("pms.checkin.partner", "reservation_id")
+ count_pending_arrival = fields.Integer(
+ "Reservation Description",
+ compute="_compute_count_pending_arrival",
+ store=True,
+ )
+ checkins_ratio = fields.Integer(
+ string="Pending Arrival Ratio",
+ compute="_compute_checkins_ratio",
+ )
segmentation_ids = fields.Many2many(
"res.partner.category",
string="Segmentation",
@@ -534,6 +543,25 @@ class PmsReservation(models.Model):
# TODO: Warning change de pricelist?
reservation.pricelist_id = pricelist_id
+ @api.depends("checkin_partner_ids", "checkin_partner_ids.state")
+ def _compute_count_pending_arrival(self):
+ for reservation in self:
+ reservation.count_pending_arrival = reservation.adults - len(
+ reservation.checkin_partner_ids.filtered(
+ lambda c: c.state in ("onboard", "done")
+ )
+ )
+
+ @api.depends("count_pending_arrival")
+ def _compute_checkins_ratio(self):
+ self.checkins_ratio = 0
+ for reservation in self.filtered(lambda r: r.adults > 0):
+ reservation.checkins_ratio = (
+ (reservation.adults - reservation.count_pending_arrival)
+ * 100
+ / reservation.adults
+ )
+
# REVIEW: Dont run with set room_type_id -> room_id(compute)-> No set adults¿?
@api.depends("preferred_room_id")
def _compute_adults(self):
diff --git a/pms/tests/test_pms_checkin_partner.py b/pms/tests/test_pms_checkin_partner.py
index 9b3f8638f..89e63430b 100644
--- a/pms/tests/test_pms_checkin_partner.py
+++ b/pms/tests/test_pms_checkin_partner.py
@@ -155,3 +155,115 @@ class TestPmsCheckinPartner(TestHotel):
]
}
)
+
+ @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",
+ )
diff --git a/pms/views/pms_reservation_views.xml b/pms/views/pms_reservation_views.xml
index 928d8659f..79a94840a 100644
--- a/pms/views/pms_reservation_views.xml
+++ b/pms/views/pms_reservation_views.xml
@@ -131,20 +131,14 @@