[REF]pms: Change related reservation_type to compute in pms.reservation

This commit is contained in:
braisab
2021-08-09 19:39:00 +02:00
parent 39f8a35f05
commit dc725d4a1e
5 changed files with 87 additions and 134 deletions

View File

@@ -342,9 +342,10 @@ class PmsReservation(models.Model):
reservation_type = fields.Selection( reservation_type = fields.Selection(
string="Reservation Type", string="Reservation Type",
help="Type of reservations. It can be 'normal', 'staff' or 'out of service", help="Type of reservations. It can be 'normal', 'staff' or 'out of service",
related="folio_id.reservation_type",
store=True, store=True,
readonly=False, readonly=False,
compute="_compute_reservation_type",
selection=[("normal", "Normal"), ("staff", "Staff"), ("out", "Out of Service")],
) )
splitted = fields.Boolean( splitted = fields.Boolean(
string="Splitted", string="Splitted",
@@ -1352,6 +1353,14 @@ class PmsReservation(models.Model):
else: else:
reservation.rooms = reservation.preferred_room_id.name 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): def _search_allowed_checkin(self, operator, value):
if operator not in ("=",): if operator not in ("=",):
raise UserError( raise UserError(
@@ -1644,6 +1653,8 @@ class PmsReservation(models.Model):
raise ValidationError(_("Partner contact name is required")) raise ValidationError(_("Partner contact name is required"))
# Create the folio in case of need # Create the folio in case of need
# (To allow to create reservations direct) # (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) folio = self.env["pms.folio"].create(folio_vals)
vals.update( vals.update(
{ {

View File

@@ -547,35 +547,38 @@ class PmsService(models.Model):
def _get_price_unit_line(self, date=False): def _get_price_unit_line(self, date=False):
self.ensure_one() self.ensure_one()
folio = self.folio_id if self.reservation_id.reservation_type == "normal":
reservation = self.reservation_id folio = self.folio_id
origin = reservation if reservation else folio reservation = self.reservation_id
if origin: origin = reservation if reservation else folio
partner = origin.partner_id if origin:
pricelist = origin.pricelist_id partner = origin.partner_id
board_room_type = False pricelist = origin.pricelist_id
product_context = dict( board_room_type = False
self.env.context, product_context = dict(
lang=partner.lang, self.env.context,
partner=partner.id, lang=partner.lang,
quantity=self.product_qty, partner=partner.id,
date=folio.date_order if folio else fields.Date.today(), quantity=self.product_qty,
pricelist=pricelist.id, date=folio.date_order if folio else fields.Date.today(),
board_service=board_room_type.id if board_room_type else False, pricelist=pricelist.id,
uom=self.product_id.uom_id.id, board_service=board_room_type.id if board_room_type else False,
fiscal_position=False, uom=self.product_id.uom_id.id,
property=self.reservation_id.pms_property_id.id, fiscal_position=False,
) property=self.reservation_id.pms_property_id.id,
if date: )
product_context["consumption_date"] = date if date:
if reservation and self.is_board_service: product_context["consumption_date"] = date
product_context["board_service"] = reservation.board_service_room_id.id if reservation and self.is_board_service:
product = self.product_id.with_context(product_context) product_context[
return self.env["account.tax"]._fix_tax_included_price_company( "board_service"
self._get_display_price(product), ] = reservation.board_service_room_id.id
product.taxes_id, product = self.product_id.with_context(product_context)
self.tax_ids, return self.env["account.tax"]._fix_tax_included_price_company(
origin.company_id, self._get_display_price(product),
) product.taxes_id,
else: self.tax_ids,
return 0 origin.company_id,
)
else:
return 0

View File

@@ -371,104 +371,6 @@ class TestPmsFolio(TestPms):
"The default reservation type of the folio should be 'normal'", "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): def test_invoice_status_staff_reservation(self):
""" """
Check that the value of the invoice_status field is 'no' Check that the value of the invoice_status field is 'no'

View File

@@ -186,6 +186,19 @@
bg_color="bg-warning" bg_color="bg-warning"
attrs="{'invisible': [('payment_state', '!=', 'partial')]}" 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> <h2>
<field name="name" /> <field name="name" />
</h2> </h2>
@@ -542,12 +555,17 @@
decoration-muted="state == 'cancel'" decoration-muted="state == 'cancel'"
default_order="create_date desc" 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_id" invisible="1" />
<field name="partner_name" select="1" /> <field name="partner_name" select="1" />
<field name="date_order" select="1" /> <field name="date_order" select="1" />
<field name="user_id" widget="many2one_avatar_user" optional="show" /> <field name="user_id" widget="many2one_avatar_user" optional="show" />
<field name="reservation_ids" widget="many2many_tags" optional="show" /> <field name="reservation_ids" widget="many2many_tags" optional="show" />
<field name="reservation_type" invisible="1" />
<field <field
name="amount_total" name="amount_total"
sum="Total amount" sum="Total amount"

View File

@@ -223,6 +223,19 @@
title="Partial" title="Partial"
bg_color="bg-warning" bg_color="bg-warning"
attrs="{'invisible': [('folio_payment_state', '!=', 'partial')]}" 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 <div
class="card bg-danger mb8" class="card bg-danger mb8"
@@ -496,7 +509,7 @@
<group <group
string="Services" string="Services"
name="reservation_services" name="reservation_services"
attrs="{'invisible':[('reservation_type', 'not in', ('normal'))]}" attrs="{'invisible':[('reservation_type', 'in', ('out'))]}"
> >
<field <field
name="service_ids" name="service_ids"
@@ -681,8 +694,14 @@
decoration-bf="splitted" decoration-bf="splitted"
js_class="pms_booking_engine_request_tree" js_class="pms_booking_engine_request_tree"
> >
<field name="reservation_type" invisible="1" />
<field name="folio_id" optional="show" decoration-bf="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="splitted" invisible="1" />
<field name="pricelist_id" invisible="1" /> <field name="pricelist_id" invisible="1" />
<field name="rooms" /> <field name="rooms" />