mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP] Add fields in booking engine (#84)
* [IMP] Add fields in folio wizard * pre-commit * [IMP] Compute service line qty automatically * [IMP] many2many widget segmentation fiel bookin engine Co-authored-by: Darío Lodeiros <dario@commitsun.com>
This commit is contained in:
@@ -271,7 +271,12 @@ class PmsService(models.Model):
|
|||||||
name += "\n" + product.description_sale
|
name += "\n" + product.description_sale
|
||||||
service.name = name
|
service.name = name
|
||||||
|
|
||||||
@api.depends("reservation_id.checkin", "reservation_id.checkout", "product_id")
|
@api.depends(
|
||||||
|
"reservation_id.checkin",
|
||||||
|
"reservation_id.checkout",
|
||||||
|
"product_id",
|
||||||
|
"reservation_id.adults",
|
||||||
|
)
|
||||||
def _compute_service_line_ids(self):
|
def _compute_service_line_ids(self):
|
||||||
for service in self:
|
for service in self:
|
||||||
if service.product_id:
|
if service.product_id:
|
||||||
@@ -288,15 +293,22 @@ class PmsService(models.Model):
|
|||||||
if consumed_on == "after":
|
if consumed_on == "after":
|
||||||
i += 1
|
i += 1
|
||||||
idate = reservation.checkin + timedelta(days=i)
|
idate = reservation.checkin + timedelta(days=i)
|
||||||
old_line = service._search_old_lines(idate)
|
old_line = service.service_line_ids.filtered(
|
||||||
if idate in [
|
lambda r: r.date == idate
|
||||||
line.date for line in service.service_line_ids
|
)
|
||||||
]:
|
price_unit = service._get_price_unit_line(idate)
|
||||||
# REVIEW: If the date is already
|
if old_line and old_line.auto_qty:
|
||||||
# cached (otherwise double the date)
|
lines.append(
|
||||||
pass
|
(
|
||||||
|
1,
|
||||||
|
old_line.id,
|
||||||
|
{
|
||||||
|
"day_qty": day_qty,
|
||||||
|
"auto_qty": True,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
)
|
||||||
elif not old_line:
|
elif not old_line:
|
||||||
price_unit = service._get_price_unit_line(idate)
|
|
||||||
lines.append(
|
lines.append(
|
||||||
(
|
(
|
||||||
0,
|
0,
|
||||||
@@ -304,12 +316,11 @@ class PmsService(models.Model):
|
|||||||
{
|
{
|
||||||
"date": idate,
|
"date": idate,
|
||||||
"day_qty": day_qty,
|
"day_qty": day_qty,
|
||||||
|
"auto_qty": True,
|
||||||
"price_unit": price_unit,
|
"price_unit": price_unit,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else:
|
|
||||||
lines.append((4, old_line.id))
|
|
||||||
move_day = 0
|
move_day = 0
|
||||||
if consumed_on == "after":
|
if consumed_on == "after":
|
||||||
move_day = 1
|
move_day = 1
|
||||||
@@ -332,7 +343,6 @@ class PmsService(models.Model):
|
|||||||
)
|
)
|
||||||
service.service_line_ids = lines
|
service.service_line_ids = lines
|
||||||
else:
|
else:
|
||||||
# TODO: Review (business logic refact) no per_day logic service
|
|
||||||
if not service.service_line_ids:
|
if not service.service_line_ids:
|
||||||
price_unit = service._get_price_unit_line()
|
price_unit = service._get_price_unit_line()
|
||||||
service.service_line_ids = [
|
service.service_line_ids = [
|
||||||
@@ -347,8 +357,6 @@ class PmsService(models.Model):
|
|||||||
)
|
)
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
# TODO: Service without reservation(room) but with folio¿?
|
|
||||||
# example: tourist tour in group
|
|
||||||
if not service.service_line_ids:
|
if not service.service_line_ids:
|
||||||
price_unit = service._get_price_unit_line()
|
price_unit = service._get_price_unit_line()
|
||||||
service.service_line_ids = [
|
service.service_line_ids = [
|
||||||
@@ -365,13 +373,6 @@ class PmsService(models.Model):
|
|||||||
else:
|
else:
|
||||||
service.service_line_ids = False
|
service.service_line_ids = False
|
||||||
|
|
||||||
def _search_old_lines(self, date):
|
|
||||||
self.ensure_one()
|
|
||||||
if isinstance(self._origin.id, int):
|
|
||||||
old_line = self._origin.service_line_ids.filtered(lambda r: r.date == date)
|
|
||||||
return old_line
|
|
||||||
return False
|
|
||||||
|
|
||||||
# Default methods
|
# Default methods
|
||||||
|
|
||||||
def name_get(self):
|
def name_get(self):
|
||||||
|
|||||||
@@ -110,6 +110,13 @@ class PmsServiceLine(models.Model):
|
|||||||
readonly=True,
|
readonly=True,
|
||||||
store=True,
|
store=True,
|
||||||
)
|
)
|
||||||
|
auto_qty = fields.Boolean(
|
||||||
|
string="Qty automated setted",
|
||||||
|
help="Show if the day qty was calculated automatically",
|
||||||
|
compute="_compute_auto_qty",
|
||||||
|
readonly=False,
|
||||||
|
store=True,
|
||||||
|
)
|
||||||
|
|
||||||
@api.depends("day_qty", "discount", "price_unit", "tax_ids")
|
@api.depends("day_qty", "discount", "price_unit", "tax_ids")
|
||||||
def _compute_day_amount_service(self):
|
def _compute_day_amount_service(self):
|
||||||
@@ -213,6 +220,16 @@ class PmsServiceLine(models.Model):
|
|||||||
# else:
|
# else:
|
||||||
# reservation.reservation_line_ids.update({"cancel_discount": 0})
|
# reservation.reservation_line_ids.update({"cancel_discount": 0})
|
||||||
|
|
||||||
|
@api.depends("day_qty")
|
||||||
|
def _compute_auto_qty(self):
|
||||||
|
"""
|
||||||
|
Set auto_qty = False if the service is no linked to room or
|
||||||
|
if the day_qty was set manually
|
||||||
|
(See autogeneration of service lines in
|
||||||
|
_compute_service_line_ids -pms.service-)
|
||||||
|
"""
|
||||||
|
self.auto_qty = False
|
||||||
|
|
||||||
# Constraints and onchanges
|
# Constraints and onchanges
|
||||||
@api.constrains("day_qty")
|
@api.constrains("day_qty")
|
||||||
def no_free_resources(self):
|
def no_free_resources(self):
|
||||||
|
|||||||
@@ -30,6 +30,9 @@ class FolioWizard(models.TransientModel):
|
|||||||
string="Property",
|
string="Property",
|
||||||
default=lambda self: self._default_pms_property_id(),
|
default=lambda self: self._default_pms_property_id(),
|
||||||
)
|
)
|
||||||
|
segmentation_ids = fields.Many2many(
|
||||||
|
"res.partner.category", string="Segmentation", ondelete="restrict"
|
||||||
|
)
|
||||||
partner_id = fields.Many2one(
|
partner_id = fields.Many2one(
|
||||||
"res.partner",
|
"res.partner",
|
||||||
)
|
)
|
||||||
@@ -43,6 +46,21 @@ class FolioWizard(models.TransientModel):
|
|||||||
store=True,
|
store=True,
|
||||||
readonly=False,
|
readonly=False,
|
||||||
)
|
)
|
||||||
|
agency_id = fields.Many2one(
|
||||||
|
string="Agency",
|
||||||
|
comodel_name="res.partner",
|
||||||
|
ondelete="restrict",
|
||||||
|
domain=[("is_agency", "=", True)],
|
||||||
|
)
|
||||||
|
channel_type_id = fields.Many2one(
|
||||||
|
string="Direct Sale Channel",
|
||||||
|
readonly=False,
|
||||||
|
store=True,
|
||||||
|
comodel_name="pms.sale.channel",
|
||||||
|
domain=[("channel_type", "=", "direct")],
|
||||||
|
compute="_compute_channel_type_id",
|
||||||
|
ondelete="restrict",
|
||||||
|
)
|
||||||
total_price_folio = fields.Float(
|
total_price_folio = fields.Float(
|
||||||
string="Total Price", compute="_compute_total_price_folio"
|
string="Total Price", compute="_compute_total_price_folio"
|
||||||
)
|
)
|
||||||
@@ -71,6 +89,12 @@ class FolioWizard(models.TransientModel):
|
|||||||
for record in self:
|
for record in self:
|
||||||
record.pricelist_id = record.partner_id.property_product_pricelist.id
|
record.pricelist_id = record.partner_id.property_product_pricelist.id
|
||||||
|
|
||||||
|
@api.depends("agency_id")
|
||||||
|
def _compute_channel_type_id(self):
|
||||||
|
for record in self:
|
||||||
|
if record.agency_id:
|
||||||
|
record.channel_type_id = record.agency_id.sale_channel_id.id
|
||||||
|
|
||||||
@api.depends("availability_results.price_total", "discount")
|
@api.depends("availability_results.price_total", "discount")
|
||||||
def _compute_total_price_folio(self):
|
def _compute_total_price_folio(self):
|
||||||
for record in self:
|
for record in self:
|
||||||
@@ -144,6 +168,9 @@ class FolioWizard(models.TransientModel):
|
|||||||
"pricelist_id": record.pricelist_id.id,
|
"pricelist_id": record.pricelist_id.id,
|
||||||
"partner_id": record.partner_id.id,
|
"partner_id": record.partner_id.id,
|
||||||
"pms_property_id": record.pms_property_id.id,
|
"pms_property_id": record.pms_property_id.id,
|
||||||
|
"agency_id": record.agency_id.id,
|
||||||
|
"channel_type_id": record.channel_type_id.id,
|
||||||
|
"segmentation_ids": [(6, 0, record.segmentation_ids.ids)],
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
@@ -159,6 +186,7 @@ class FolioWizard(models.TransientModel):
|
|||||||
"partner_id": record.partner_id.id,
|
"partner_id": record.partner_id.id,
|
||||||
"pricelist_id": record.pricelist_id.id,
|
"pricelist_id": record.pricelist_id.id,
|
||||||
"pms_property_id": folio.pms_property_id.id,
|
"pms_property_id": folio.pms_property_id.id,
|
||||||
|
"board_service_room_id": line.board_service_room_id.id,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
res.reservation_line_ids.discount = record.discount * 100
|
res.reservation_line_ids.discount = record.discount * 100
|
||||||
|
|||||||
@@ -19,11 +19,18 @@
|
|||||||
options="{'related_start_date': 'start_date'}"
|
options="{'related_start_date': 'start_date'}"
|
||||||
/>
|
/>
|
||||||
<field name="folio_id" invisible="1" />
|
<field name="folio_id" invisible="1" />
|
||||||
|
<field name="agency_id" />
|
||||||
|
<field name="segmentation_ids" widget="many2many_tags" />
|
||||||
</group>
|
</group>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-5">
|
<div class="col-5">
|
||||||
<group>
|
<group>
|
||||||
<field name="partner_id" string="Partner" required="1" />
|
<field
|
||||||
|
name="partner_id"
|
||||||
|
string="Partner"
|
||||||
|
required="1"
|
||||||
|
options="{'no_create': True,'no_open': True}"
|
||||||
|
/>
|
||||||
<field
|
<field
|
||||||
name="pms_property_id"
|
name="pms_property_id"
|
||||||
required="1"
|
required="1"
|
||||||
@@ -35,7 +42,9 @@
|
|||||||
string="Pricelist"
|
string="Pricelist"
|
||||||
required="1"
|
required="1"
|
||||||
domain="['|', ('pms_property_ids', '=', False), ('pms_property_ids', 'in', pms_property_id)]"
|
domain="['|', ('pms_property_ids', '=', False), ('pms_property_ids', 'in', pms_property_id)]"
|
||||||
|
options="{'no_create': True,'no_open': True}"
|
||||||
/>
|
/>
|
||||||
|
<field name="channel_type_id" />
|
||||||
</group>
|
</group>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -75,6 +84,7 @@
|
|||||||
attrs="{'readonly':[('num_rooms_available','<',1)]}"
|
attrs="{'readonly':[('num_rooms_available','<',1)]}"
|
||||||
force_save="1"
|
force_save="1"
|
||||||
/>
|
/>
|
||||||
|
<field name="board_service_room_id" />
|
||||||
<field
|
<field
|
||||||
name="price_per_room"
|
name="price_per_room"
|
||||||
readonly="1"
|
readonly="1"
|
||||||
|
|||||||
@@ -58,8 +58,15 @@ class AvailabilityWizard(models.TransientModel):
|
|||||||
related="folio_wizard_id.pms_property_id",
|
related="folio_wizard_id.pms_property_id",
|
||||||
string="Property",
|
string="Property",
|
||||||
)
|
)
|
||||||
|
board_service_room_id = fields.Many2one(
|
||||||
|
string="Board Service",
|
||||||
|
help="Board Service included in the room",
|
||||||
|
comodel_name="pms.board.service.room.type",
|
||||||
|
domain="[('pms_room_type_id','=',room_type_id)]",
|
||||||
|
tracking=True,
|
||||||
|
)
|
||||||
|
|
||||||
@api.depends("num_rooms_selected", "checkin", "checkout")
|
@api.depends("num_rooms_selected", "checkin", "checkout", "board_service_room_id")
|
||||||
def _compute_price_total(self):
|
def _compute_price_total(self):
|
||||||
for record in self:
|
for record in self:
|
||||||
record.price_total = 0
|
record.price_total = 0
|
||||||
@@ -88,6 +95,12 @@ class AvailabilityWizard(models.TransientModel):
|
|||||||
)
|
)
|
||||||
room_type_total_price_per_room += product.price
|
room_type_total_price_per_room += product.price
|
||||||
|
|
||||||
|
if record.board_service_room_id:
|
||||||
|
nights = (record.checkout - record.checkin).days
|
||||||
|
room_type_total_price_per_room += (
|
||||||
|
record.board_service_room_id.amount * nights
|
||||||
|
)
|
||||||
|
|
||||||
# udpate the price per room
|
# udpate the price per room
|
||||||
record.price_per_room = room_type_total_price_per_room
|
record.price_per_room = room_type_total_price_per_room
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user