mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[ADD] Counts checkins pending
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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",
|
||||
)
|
||||
|
||||
@@ -131,20 +131,14 @@
|
||||
<button
|
||||
type="object"
|
||||
class="oe_stat_button"
|
||||
icon="fa-users"
|
||||
name="action_checks"
|
||||
attrs="{'invisible': [('checkin_partner_pending_count','<=',0)]}"
|
||||
attrs="{'invisible': [('state', 'in', ('cancelled','done'))]}"
|
||||
>
|
||||
<div class="o_form_field o_stat_info">
|
||||
<span class="o_stat_value">
|
||||
<field
|
||||
name="checkin_partner_pending_count"
|
||||
widget="statinfo"
|
||||
nolabel="1"
|
||||
/>
|
||||
</span>
|
||||
<span class="o_stat_text">Pending Checks</span>
|
||||
</div>
|
||||
<field
|
||||
name="checkins_ratio"
|
||||
string="Checkins"
|
||||
widget="percentpie"
|
||||
/>
|
||||
</button>
|
||||
</div>
|
||||
<span
|
||||
|
||||
Reference in New Issue
Block a user