mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[REF]pms: Change related reservation_type to compute in pms.reservation
This commit is contained in:
@@ -342,9 +342,10 @@ class PmsReservation(models.Model):
|
||||
reservation_type = fields.Selection(
|
||||
string="Reservation Type",
|
||||
help="Type of reservations. It can be 'normal', 'staff' or 'out of service",
|
||||
related="folio_id.reservation_type",
|
||||
store=True,
|
||||
readonly=False,
|
||||
compute="_compute_reservation_type",
|
||||
selection=[("normal", "Normal"), ("staff", "Staff"), ("out", "Out of Service")],
|
||||
)
|
||||
splitted = fields.Boolean(
|
||||
string="Splitted",
|
||||
@@ -1352,6 +1353,14 @@ class PmsReservation(models.Model):
|
||||
else:
|
||||
reservation.rooms = reservation.preferred_room_id.name
|
||||
|
||||
@api.depends("folio_id", "folio_id.reservation_type")
|
||||
def _compute_reservation_type(self):
|
||||
for record in self:
|
||||
if record.folio_id:
|
||||
record.reservation_type = record.folio_id.reservation_type
|
||||
else:
|
||||
record.reservation_type = "normal"
|
||||
|
||||
def _search_allowed_checkin(self, operator, value):
|
||||
if operator not in ("=",):
|
||||
raise UserError(
|
||||
@@ -1644,6 +1653,8 @@ class PmsReservation(models.Model):
|
||||
raise ValidationError(_("Partner contact name is required"))
|
||||
# Create the folio in case of need
|
||||
# (To allow to create reservations direct)
|
||||
if vals.get("reservation_type"):
|
||||
folio_vals["reservation_type"] = vals.get("reservation_type")
|
||||
folio = self.env["pms.folio"].create(folio_vals)
|
||||
vals.update(
|
||||
{
|
||||
|
||||
@@ -547,35 +547,38 @@ class PmsService(models.Model):
|
||||
|
||||
def _get_price_unit_line(self, date=False):
|
||||
self.ensure_one()
|
||||
folio = self.folio_id
|
||||
reservation = self.reservation_id
|
||||
origin = reservation if reservation else folio
|
||||
if origin:
|
||||
partner = origin.partner_id
|
||||
pricelist = origin.pricelist_id
|
||||
board_room_type = False
|
||||
product_context = dict(
|
||||
self.env.context,
|
||||
lang=partner.lang,
|
||||
partner=partner.id,
|
||||
quantity=self.product_qty,
|
||||
date=folio.date_order if folio else fields.Date.today(),
|
||||
pricelist=pricelist.id,
|
||||
board_service=board_room_type.id if board_room_type else False,
|
||||
uom=self.product_id.uom_id.id,
|
||||
fiscal_position=False,
|
||||
property=self.reservation_id.pms_property_id.id,
|
||||
)
|
||||
if date:
|
||||
product_context["consumption_date"] = date
|
||||
if reservation and self.is_board_service:
|
||||
product_context["board_service"] = reservation.board_service_room_id.id
|
||||
product = self.product_id.with_context(product_context)
|
||||
return self.env["account.tax"]._fix_tax_included_price_company(
|
||||
self._get_display_price(product),
|
||||
product.taxes_id,
|
||||
self.tax_ids,
|
||||
origin.company_id,
|
||||
)
|
||||
else:
|
||||
return 0
|
||||
if self.reservation_id.reservation_type == "normal":
|
||||
folio = self.folio_id
|
||||
reservation = self.reservation_id
|
||||
origin = reservation if reservation else folio
|
||||
if origin:
|
||||
partner = origin.partner_id
|
||||
pricelist = origin.pricelist_id
|
||||
board_room_type = False
|
||||
product_context = dict(
|
||||
self.env.context,
|
||||
lang=partner.lang,
|
||||
partner=partner.id,
|
||||
quantity=self.product_qty,
|
||||
date=folio.date_order if folio else fields.Date.today(),
|
||||
pricelist=pricelist.id,
|
||||
board_service=board_room_type.id if board_room_type else False,
|
||||
uom=self.product_id.uom_id.id,
|
||||
fiscal_position=False,
|
||||
property=self.reservation_id.pms_property_id.id,
|
||||
)
|
||||
if date:
|
||||
product_context["consumption_date"] = date
|
||||
if reservation and self.is_board_service:
|
||||
product_context[
|
||||
"board_service"
|
||||
] = reservation.board_service_room_id.id
|
||||
product = self.product_id.with_context(product_context)
|
||||
return self.env["account.tax"]._fix_tax_included_price_company(
|
||||
self._get_display_price(product),
|
||||
product.taxes_id,
|
||||
self.tax_ids,
|
||||
origin.company_id,
|
||||
)
|
||||
else:
|
||||
return 0
|
||||
|
||||
@@ -371,104 +371,6 @@ class TestPmsFolio(TestPms):
|
||||
"The default reservation type of the folio should be 'normal'",
|
||||
)
|
||||
|
||||
def test_staff_reservation_type_folio(self):
|
||||
"""
|
||||
Check that the reservation type field of a folio is equal
|
||||
to 'staff', if your reservations also have this field
|
||||
as 'staff'.
|
||||
---------------
|
||||
A folio is created. A reservation is created to which the
|
||||
value of the folio_id is the id of the previously created
|
||||
folio and the field reservation_type equal to 'staff'. A
|
||||
second reservation with the same folio_id and reservation_type
|
||||
is created. Then it is verified that the value of the reservation_type
|
||||
field of the folio is 'staff'.
|
||||
"""
|
||||
# ARRANGE AND ACT
|
||||
self.partner1 = self.env["res.partner"].create({"name": "Ana"})
|
||||
folio1 = self.env["pms.folio"].create(
|
||||
{
|
||||
"pms_property_id": self.pms_property1.id,
|
||||
"partner_id": self.partner1.id,
|
||||
}
|
||||
)
|
||||
|
||||
self.env["pms.reservation"].create(
|
||||
{
|
||||
"room_type_id": self.room_type_double.id,
|
||||
"checkin": fields.date.today(),
|
||||
"checkout": fields.date.today() + datetime.timedelta(days=1),
|
||||
"folio_id": folio1.id,
|
||||
"reservation_type": "staff",
|
||||
}
|
||||
)
|
||||
|
||||
self.env["pms.reservation"].create(
|
||||
{
|
||||
"room_type_id": self.room_type_double.id,
|
||||
"checkin": fields.date.today(),
|
||||
"checkout": fields.date.today() + datetime.timedelta(days=1),
|
||||
"folio_id": folio1.id,
|
||||
"reservation_type": "staff",
|
||||
}
|
||||
)
|
||||
|
||||
# ASSERT
|
||||
self.assertEqual(
|
||||
folio1.reservation_type,
|
||||
"staff",
|
||||
"The reservation type of the folio should be 'staff'",
|
||||
)
|
||||
|
||||
def test_out_reservation_type_folio(self):
|
||||
"""
|
||||
Check that the reservation type field of a folio is equal
|
||||
to 'out', if your reservations also have this field
|
||||
as 'out'.
|
||||
---------------
|
||||
A folio is created. A reservation is created to which the
|
||||
value of the folio_id is the id of the previously created
|
||||
folio and the field reservation_type equal to 'out'. A
|
||||
second reservation with the same folio_id and reservation_type
|
||||
is created. Then it is verified that the value of the reservation_type
|
||||
field of the folio is 'out'.
|
||||
"""
|
||||
# ARRANGE AND ACT
|
||||
self.partner1 = self.env["res.partner"].create({"name": "Ana"})
|
||||
folio1 = self.env["pms.folio"].create(
|
||||
{
|
||||
"pms_property_id": self.pms_property1.id,
|
||||
"partner_id": self.partner1.id,
|
||||
}
|
||||
)
|
||||
|
||||
self.env["pms.reservation"].create(
|
||||
{
|
||||
"room_type_id": self.room_type_double.id,
|
||||
"checkin": fields.date.today(),
|
||||
"checkout": fields.date.today() + datetime.timedelta(days=1),
|
||||
"folio_id": folio1.id,
|
||||
"reservation_type": "out",
|
||||
}
|
||||
)
|
||||
|
||||
self.env["pms.reservation"].create(
|
||||
{
|
||||
"room_type_id": self.room_type_double.id,
|
||||
"checkin": fields.date.today(),
|
||||
"checkout": fields.date.today() + datetime.timedelta(days=1),
|
||||
"folio_id": folio1.id,
|
||||
"reservation_type": "out",
|
||||
}
|
||||
)
|
||||
|
||||
# ASSERT
|
||||
self.assertEqual(
|
||||
folio1.reservation_type,
|
||||
"out",
|
||||
"The reservation type of the folio should be 'out'",
|
||||
)
|
||||
|
||||
def test_invoice_status_staff_reservation(self):
|
||||
"""
|
||||
Check that the value of the invoice_status field is 'no'
|
||||
|
||||
@@ -186,6 +186,19 @@
|
||||
bg_color="bg-warning"
|
||||
attrs="{'invisible': [('payment_state', '!=', 'partial')]}"
|
||||
/>
|
||||
<widget
|
||||
name="web_ribbon"
|
||||
title="Staff"
|
||||
bg_color="bg-info"
|
||||
attrs="{'invisible': [('reservation_type', 'not in', 'staff')]}"
|
||||
/>
|
||||
|
||||
<widget
|
||||
name="web_ribbon"
|
||||
title="Out of Service"
|
||||
bg_color="bg-dark"
|
||||
attrs="{'invisible': [('reservation_type', 'not in', 'out')]}"
|
||||
/>
|
||||
<h2>
|
||||
<field name="name" />
|
||||
</h2>
|
||||
@@ -542,12 +555,17 @@
|
||||
decoration-muted="state == 'cancel'"
|
||||
default_order="create_date desc"
|
||||
>
|
||||
<field name="name" />
|
||||
<field
|
||||
name="name"
|
||||
decoration-info="reservation_type == 'staff'"
|
||||
decoration-bf="reservation_type == 'out'"
|
||||
/>
|
||||
<field name="partner_id" invisible="1" />
|
||||
<field name="partner_name" select="1" />
|
||||
<field name="date_order" select="1" />
|
||||
<field name="user_id" widget="many2one_avatar_user" optional="show" />
|
||||
<field name="reservation_ids" widget="many2many_tags" optional="show" />
|
||||
<field name="reservation_type" invisible="1" />
|
||||
<field
|
||||
name="amount_total"
|
||||
sum="Total amount"
|
||||
|
||||
@@ -223,6 +223,19 @@
|
||||
title="Partial"
|
||||
bg_color="bg-warning"
|
||||
attrs="{'invisible': [('folio_payment_state', '!=', 'partial')]}"
|
||||
/>
|
||||
<widget
|
||||
name="web_ribbon"
|
||||
title="Staff"
|
||||
bg_color="bg-info"
|
||||
attrs="{'invisible': [('reservation_type', 'not in', 'staff')]}"
|
||||
/>
|
||||
|
||||
<widget
|
||||
name="web_ribbon"
|
||||
title="Out of Service"
|
||||
bg_color="bg-dark"
|
||||
attrs="{'invisible': [('reservation_type', 'not in', 'out')]}"
|
||||
/>
|
||||
<div
|
||||
class="card bg-danger mb8"
|
||||
@@ -496,7 +509,7 @@
|
||||
<group
|
||||
string="Services"
|
||||
name="reservation_services"
|
||||
attrs="{'invisible':[('reservation_type', 'not in', ('normal'))]}"
|
||||
attrs="{'invisible':[('reservation_type', 'in', ('out'))]}"
|
||||
>
|
||||
<field
|
||||
name="service_ids"
|
||||
@@ -681,8 +694,14 @@
|
||||
decoration-bf="splitted"
|
||||
js_class="pms_booking_engine_request_tree"
|
||||
>
|
||||
<field name="reservation_type" invisible="1" />
|
||||
<field name="folio_id" optional="show" decoration-bf="1" />
|
||||
<field name="name" optional="show" />
|
||||
<field
|
||||
name="name"
|
||||
optional="show"
|
||||
decoration-info="reservation_type == 'staff'"
|
||||
decoration-bf="reservation_type == 'out'"
|
||||
/>
|
||||
<field name="splitted" invisible="1" />
|
||||
<field name="pricelist_id" invisible="1" />
|
||||
<field name="rooms" />
|
||||
|
||||
Reference in New Issue
Block a user