mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[FIX+IMP] pms: Minor bugfixes and improvements
This commit is contained in:
@@ -42,6 +42,12 @@ class PmsAvailability(models.Model):
|
|||||||
inverse_name="avail_id",
|
inverse_name="avail_id",
|
||||||
check_pms_properties=True,
|
check_pms_properties=True,
|
||||||
)
|
)
|
||||||
|
avail_rule_ids = fields.One2many(
|
||||||
|
string="Avail record rules",
|
||||||
|
comodel_name="pms.availability.plan.rule",
|
||||||
|
inverse_name="avail_id",
|
||||||
|
check_pms_properties=True,
|
||||||
|
)
|
||||||
real_avail = fields.Integer(
|
real_avail = fields.Integer(
|
||||||
string="Real Avail",
|
string="Real Avail",
|
||||||
help="",
|
help="",
|
||||||
|
|||||||
@@ -620,15 +620,19 @@ class PmsFolio(models.Model):
|
|||||||
for record in self:
|
for record in self:
|
||||||
record.company_id = record.pms_property_id.company_id
|
record.company_id = record.pms_property_id.company_id
|
||||||
|
|
||||||
@api.depends("partner_id", "agency_id")
|
@api.depends(
|
||||||
|
"partner_id", "agency_id", "reservation_ids", "reservation_ids.pricelist_id"
|
||||||
|
)
|
||||||
def _compute_pricelist_id(self):
|
def _compute_pricelist_id(self):
|
||||||
for folio in self:
|
for folio in self:
|
||||||
if folio.agency_id and folio.agency_id.apply_pricelist:
|
if len(folio.reservation_ids.pricelist_id) == 1:
|
||||||
folio.pricelist_id = folio.agency_id.property_product_pricelist.id
|
folio.pricelist_id = folio.reservation_ids.pricelist_id
|
||||||
|
elif folio.agency_id and folio.agency_id.apply_pricelist:
|
||||||
|
folio.pricelist_id = folio.agency_id.property_product_pricelist
|
||||||
elif folio.partner_id and folio.partner_id.property_product_pricelist:
|
elif folio.partner_id and folio.partner_id.property_product_pricelist:
|
||||||
folio.pricelist_id = folio.partner_id.property_product_pricelist.id
|
folio.pricelist_id = folio.partner_id.property_product_pricelist
|
||||||
elif not folio.pricelist_id.id:
|
elif not folio.pricelist_id:
|
||||||
folio.pricelist_id = folio.pms_property_id.default_pricelist_id.id
|
folio.pricelist_id = folio.pms_property_id.default_pricelist_id
|
||||||
|
|
||||||
@api.depends("agency_id")
|
@api.depends("agency_id")
|
||||||
def _compute_partner_id(self):
|
def _compute_partner_id(self):
|
||||||
|
|||||||
@@ -745,6 +745,8 @@ class PmsReservation(models.Model):
|
|||||||
pms_property_id=reservation.pms_property_id.id,
|
pms_property_id=reservation.pms_property_id.id,
|
||||||
)
|
)
|
||||||
reservation.allowed_room_ids = rooms_available
|
reservation.allowed_room_ids = rooms_available
|
||||||
|
else:
|
||||||
|
reservation.allowed_room_ids = False
|
||||||
|
|
||||||
@api.depends("reservation_type", "agency_id", "folio_id", "folio_id.agency_id")
|
@api.depends("reservation_type", "agency_id", "folio_id", "folio_id.agency_id")
|
||||||
def _compute_partner_id(self):
|
def _compute_partner_id(self):
|
||||||
@@ -759,30 +761,34 @@ class PmsReservation(models.Model):
|
|||||||
def _compute_reservation_line_ids(self):
|
def _compute_reservation_line_ids(self):
|
||||||
for reservation in self:
|
for reservation in self:
|
||||||
cmds = []
|
cmds = []
|
||||||
days_diff = (reservation.checkout - reservation.checkin).days
|
if reservation.checkout and reservation.checkin:
|
||||||
for i in range(0, days_diff):
|
days_diff = (reservation.checkout - reservation.checkin).days
|
||||||
idate = reservation.checkin + datetime.timedelta(days=i)
|
for i in range(0, days_diff):
|
||||||
old_line = reservation.reservation_line_ids.filtered(
|
idate = reservation.checkin + datetime.timedelta(days=i)
|
||||||
lambda r: r.date == idate
|
old_line = reservation.reservation_line_ids.filtered(
|
||||||
)
|
lambda r: r.date == idate
|
||||||
if not old_line:
|
)
|
||||||
cmds.append(
|
if not old_line:
|
||||||
(
|
cmds.append(
|
||||||
0,
|
(
|
||||||
False,
|
0,
|
||||||
{"date": idate},
|
False,
|
||||||
)
|
{"date": idate},
|
||||||
|
)
|
||||||
|
)
|
||||||
|
reservation.reservation_line_ids -= (
|
||||||
|
reservation.reservation_line_ids.filtered_domain(
|
||||||
|
[
|
||||||
|
"|",
|
||||||
|
("date", ">=", reservation.checkout),
|
||||||
|
("date", "<", reservation.checkin),
|
||||||
|
]
|
||||||
)
|
)
|
||||||
reservation.reservation_line_ids -= (
|
|
||||||
reservation.reservation_line_ids.filtered_domain(
|
|
||||||
[
|
|
||||||
"|",
|
|
||||||
("date", ">=", reservation.checkout),
|
|
||||||
("date", "<", reservation.checkin),
|
|
||||||
]
|
|
||||||
)
|
)
|
||||||
)
|
reservation.reservation_line_ids = cmds
|
||||||
reservation.reservation_line_ids = cmds
|
else:
|
||||||
|
if not reservation.reservation_line_ids:
|
||||||
|
reservation.reservation_line_ids = False
|
||||||
|
|
||||||
@api.depends("board_service_room_id")
|
@api.depends("board_service_room_id")
|
||||||
def _compute_service_ids(self):
|
def _compute_service_ids(self):
|
||||||
@@ -822,27 +828,21 @@ class PmsReservation(models.Model):
|
|||||||
for reservation in self:
|
for reservation in self:
|
||||||
if reservation.agency_id and reservation.agency_id.apply_pricelist:
|
if reservation.agency_id and reservation.agency_id.apply_pricelist:
|
||||||
reservation.pricelist_id = (
|
reservation.pricelist_id = (
|
||||||
reservation.agency_id.property_product_pricelist.id
|
reservation.agency_id.property_product_pricelist
|
||||||
)
|
)
|
||||||
elif (
|
elif (
|
||||||
reservation.partner_id
|
reservation.partner_id
|
||||||
and reservation.partner_id.property_product_pricelist
|
and reservation.partner_id.property_product_pricelist
|
||||||
):
|
):
|
||||||
reservation.pricelist_id = (
|
reservation.pricelist_id = (
|
||||||
reservation.partner_id.property_product_pricelist.id
|
reservation.partner_id.property_product_pricelist
|
||||||
)
|
)
|
||||||
elif not reservation.pricelist_id.id:
|
elif not reservation.pricelist_id.id:
|
||||||
if (
|
if reservation.folio_id and reservation.folio_id.pricelist_id:
|
||||||
reservation.folio_id
|
reservation.pricelist_id = reservation.folio_id.pricelist_id
|
||||||
and len(reservation.folio_id.reservation_ids.mapped("pricelist_id"))
|
|
||||||
== 1
|
|
||||||
):
|
|
||||||
reservation.pricelist_id = (
|
|
||||||
reservation.folio_id.reservation_ids.mapped("pricelist_id")
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
reservation.pricelist_id = (
|
reservation.pricelist_id = (
|
||||||
reservation.pms_property_id.default_pricelist_id.id
|
reservation.pms_property_id.default_pricelist_id
|
||||||
)
|
)
|
||||||
|
|
||||||
@api.depends("pricelist_id", "room_type_id")
|
@api.depends("pricelist_id", "room_type_id")
|
||||||
@@ -1362,22 +1362,22 @@ class PmsReservation(models.Model):
|
|||||||
segmentation_ids = folio.segmentation_ids
|
segmentation_ids = folio.segmentation_ids
|
||||||
return segmentation_ids
|
return segmentation_ids
|
||||||
|
|
||||||
# TODO: Use default values on checkin /checkout is empty
|
# TODO: make this check on computes (checkin/checkout)
|
||||||
@api.constrains("checkin", "checkout", "state", "preferred_room_id", "overbooking")
|
# @api.constrains("checkin", "checkout", "state", "preferred_room_id", "overbooking")
|
||||||
def check_dates(self):
|
# def check_dates(self):
|
||||||
"""
|
# """
|
||||||
1.-When date_order is less then checkin date or
|
# 1.-When date_order is less then checkin date or
|
||||||
Checkout date should be greater than the checkin date.
|
# Checkout date should be greater than the checkin date.
|
||||||
3.-Check the reservation dates are not occuped
|
# 3.-Check the reservation dates are not occuped
|
||||||
"""
|
# """
|
||||||
for record in self:
|
# for record in self:
|
||||||
if record.checkin >= record.checkout:
|
# if record.checkin >= record.checkout:
|
||||||
raise ValidationError(
|
# raise ValidationError(
|
||||||
_(
|
# _(
|
||||||
"Room line Check In Date Should be \
|
# "Room line Check In Date Should be \
|
||||||
less than the Check Out Date!"
|
# less than the Check Out Date!"
|
||||||
)
|
# )
|
||||||
)
|
# )
|
||||||
|
|
||||||
@api.constrains("reservation_line_ids")
|
@api.constrains("reservation_line_ids")
|
||||||
def check_consecutive_dates(self):
|
def check_consecutive_dates(self):
|
||||||
@@ -1432,24 +1432,29 @@ class PmsReservation(models.Model):
|
|||||||
@api.constrains("arrival_hour")
|
@api.constrains("arrival_hour")
|
||||||
def _check_arrival_hour(self):
|
def _check_arrival_hour(self):
|
||||||
for record in self:
|
for record in self:
|
||||||
try:
|
if record.arrival_hour:
|
||||||
time.strptime(record.arrival_hour, "%H:%M")
|
try:
|
||||||
return True
|
time.strptime(record.arrival_hour, "%H:%M")
|
||||||
except ValueError:
|
return True
|
||||||
raise ValidationError(
|
except ValueError:
|
||||||
_("Format Arrival Hour (HH:MM) Error: %s", record.arrival_hour)
|
raise ValidationError(
|
||||||
)
|
_("Format Arrival Hour (HH:MM) Error: %s", record.arrival_hour)
|
||||||
|
)
|
||||||
|
|
||||||
@api.constrains("departure_hour")
|
@api.constrains("departure_hour")
|
||||||
def _check_departure_hour(self):
|
def _check_departure_hour(self):
|
||||||
for record in self:
|
for record in self:
|
||||||
try:
|
if record.departure_hour:
|
||||||
time.strptime(record.departure_hour, "%H:%M")
|
try:
|
||||||
return True
|
time.strptime(record.departure_hour, "%H:%M")
|
||||||
except ValueError:
|
return True
|
||||||
raise ValidationError(
|
except ValueError:
|
||||||
_("Format Departure Hour (HH:MM) Error: %s", record.departure_hour)
|
raise ValidationError(
|
||||||
)
|
_(
|
||||||
|
"Format Departure Hour (HH:MM) Error: %s",
|
||||||
|
record.departure_hour,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
@api.constrains("agency_id")
|
@api.constrains("agency_id")
|
||||||
def _no_agency_as_agency(self):
|
def _no_agency_as_agency(self):
|
||||||
|
|||||||
@@ -195,10 +195,10 @@ class PmsRoomType(models.Model):
|
|||||||
)
|
)
|
||||||
return super().create(vals)
|
return super().create(vals)
|
||||||
|
|
||||||
def unlink(self):
|
# def unlink(self):
|
||||||
for record in self:
|
# for record in self:
|
||||||
record.product_id.unlink()
|
# record.product_id.unlink()
|
||||||
return super().unlink()
|
# return super().unlink()
|
||||||
|
|
||||||
def get_capacity(self):
|
def get_capacity(self):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
|
|||||||
@@ -297,7 +297,7 @@
|
|||||||
string="General Info"
|
string="General Info"
|
||||||
name="contact_details"
|
name="contact_details"
|
||||||
>
|
>
|
||||||
<field name="partner_id" invisible="1" />
|
<field name="partner_id" invisible="0" />
|
||||||
<field
|
<field
|
||||||
name="partner_name"
|
name="partner_name"
|
||||||
placeholder="Guest"
|
placeholder="Guest"
|
||||||
|
|||||||
Reference in New Issue
Block a user