mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP] Splitted Reservations
This commit is contained in:
@@ -425,23 +425,13 @@ class PmsReservation(models.Model):
|
||||
else:
|
||||
reservation.name = "/"
|
||||
|
||||
@api.depends("adults", "room_type_id")
|
||||
@api.depends("reservation_line_ids","reservation_line_ids.room_id")
|
||||
def _compute_room_id(self):
|
||||
reservations_no_room = self.filtered_domain([("room_id", "=", False)])
|
||||
reservations_with_room = self - reservations_no_room
|
||||
for reservation in reservations_with_room:
|
||||
if reservation.adults:
|
||||
reservation._check_adults()
|
||||
for reservation in reservations_no_room:
|
||||
if reservation.room_type_id:
|
||||
reservation.room_id = reservation._autoassign()
|
||||
# TODO: check_split reservation
|
||||
if not reservation.room_id:
|
||||
raise UserError(
|
||||
_("%s: No rooms available") % (self.room_type_id.name)
|
||||
)
|
||||
# TODO: Allow with confirmation message to
|
||||
# change de room if the user change the room_type?
|
||||
_logger.info("COMPUTE_ROOM_ID")
|
||||
for reservation in self:
|
||||
_logger.info("room_id: ")
|
||||
reservation.room_id = reservation.reservation_line_ids[0].room_id
|
||||
_logger.info(reservation.room_id)
|
||||
|
||||
@api.depends("room_id")
|
||||
def _compute_room_type_id(self):
|
||||
@@ -468,20 +458,6 @@ class PmsReservation(models.Model):
|
||||
current_lines=reservation.reservation_line_ids.ids,
|
||||
)
|
||||
)
|
||||
if (
|
||||
reservation.room_id
|
||||
and reservation.room_id.id not in rooms_available.ids
|
||||
):
|
||||
room_name = reservation.room_id.name
|
||||
warning_msg = (
|
||||
_(
|
||||
"You tried to change/confirm \
|
||||
reservation with room those already reserved in this \
|
||||
reservation period: %s "
|
||||
)
|
||||
% room_name
|
||||
)
|
||||
raise ValidationError(warning_msg)
|
||||
reservation.allowed_room_ids = rooms_available
|
||||
|
||||
@api.depends("reservation_type")
|
||||
@@ -563,15 +539,16 @@ class PmsReservation(models.Model):
|
||||
|
||||
@api.depends("room_id")
|
||||
def _compute_adults(self):
|
||||
_logger.info("COMPUTE_ADULTS")
|
||||
for reservation in self:
|
||||
_logger.info("adults")
|
||||
if reservation.room_id:
|
||||
if reservation.adults:
|
||||
reservation._check_adults()
|
||||
# TODO: Notification if the room capacity is higher than adults?
|
||||
else:
|
||||
if reservation.adults == 0:
|
||||
reservation.adults = reservation.room_id.capacity
|
||||
else:
|
||||
reservation.adults = 0
|
||||
_logger.info(reservation.room_id)
|
||||
_logger.info(reservation.adults)
|
||||
|
||||
@api.depends("checkin", "checkout", "state")
|
||||
def _compute_to_send(self):
|
||||
@@ -724,21 +701,9 @@ class PmsReservation(models.Model):
|
||||
}
|
||||
)
|
||||
|
||||
# Constraints and onchanges
|
||||
@api.constrains("adults")
|
||||
def _check_adults(self):
|
||||
for record in self:
|
||||
extra_bed = record.service_ids.filtered(
|
||||
lambda r: r.product_id.is_extra_bed is True
|
||||
)
|
||||
if record.adults > record.room_id.get_capacity(len(extra_bed)):
|
||||
raise ValidationError(_("Persons can't be higher than room capacity"))
|
||||
if record.adults == 0:
|
||||
raise ValidationError(_("Reservation has no adults"))
|
||||
|
||||
# TODO: Use default values on checkin /checkout is empty
|
||||
@api.constrains(
|
||||
"reservation_line_ids.date", "state", "room_id", "overbooking", "reselling"
|
||||
"checkin", "checkout", "state", "room_id", "overbooking", "reselling"
|
||||
)
|
||||
def check_dates(self):
|
||||
"""
|
||||
@@ -746,16 +711,16 @@ class PmsReservation(models.Model):
|
||||
Checkout date should be greater than the checkin date.
|
||||
3.-Check the reservation dates are not occuped
|
||||
"""
|
||||
_logger.info("check_dates")
|
||||
if fields.Date.from_string(self.checkin) >= fields.Date.from_string(
|
||||
self.checkout
|
||||
):
|
||||
raise ValidationError(
|
||||
_(
|
||||
"Room line Check In Date Should be \
|
||||
less than the Check Out Date!"
|
||||
for record in self:
|
||||
if fields.Date.from_string(record.checkin) >= fields.Date.from_string(
|
||||
record.checkout
|
||||
):
|
||||
raise ValidationError(
|
||||
_(
|
||||
"Room line Check In Date Should be \
|
||||
less than the Check Out Date!"
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
@api.constrains("checkin_partner_ids")
|
||||
def _max_checkin_partner_ids(self):
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
from datetime import timedelta
|
||||
|
||||
import logging
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -88,17 +90,31 @@ class PmsReservationLine(models.Model):
|
||||
# Compute and Search methods
|
||||
@api.depends(
|
||||
"reservation_id.adults",
|
||||
"reservation_id.room_type_id",
|
||||
"reservation_id.room_id")
|
||||
"reservation_id.room_type_id",)
|
||||
def _compute_room_id(self):
|
||||
lines_no_room = self.filtered_domain([("room_id", "=", False)])
|
||||
lines_with_room = self - lines_no_room
|
||||
for line in lines_no_room:
|
||||
if line.reservation_id.room_id:
|
||||
line.room_id = line.reservation_id.room_id
|
||||
# TODO: check_split reservation
|
||||
# TODO: Allow with confirmation message to
|
||||
# change de room if the user change the room_type?
|
||||
for line in self:
|
||||
if line.reservation_id.room_type_id:
|
||||
preferred_room = line.reservation_id.room_id
|
||||
rooms_available = self.env["pms.room.type.availability"].rooms_available(
|
||||
checkin=line.date,
|
||||
checkout=line.date + timedelta(1),
|
||||
room_type_id=self.reservation_id.room_type_id.id or False,
|
||||
current_lines=line._origin.id,
|
||||
)
|
||||
if rooms_available:
|
||||
if preferred_room.id in rooms_available.ids:
|
||||
room_chosen = preferred_room
|
||||
else:
|
||||
room_chosen = rooms_available[0]
|
||||
line.room_id = room_chosen
|
||||
else:
|
||||
line.room_id = False
|
||||
raise ValidationError(
|
||||
_("%s: No rooms available") % (self.reservation_id.room_type_id.name)
|
||||
)
|
||||
line._check_adults()
|
||||
else:
|
||||
line.room_id = False
|
||||
|
||||
@api.depends(
|
||||
"reservation_id",
|
||||
@@ -267,3 +283,13 @@ class PmsReservationLine(models.Model):
|
||||
# negative discounts (= surcharge) are included in the display price
|
||||
return max(base_price, final_price)
|
||||
|
||||
@api.constrains("reservation_id.adults", "room_id")
|
||||
def _check_adults(self):
|
||||
for record in self.filtered("room_id"):
|
||||
extra_bed = record.reservation_id.service_ids.filtered(
|
||||
lambda r: r.product_id.is_extra_bed is True
|
||||
)
|
||||
if record.reservation_id.adults > record.room_id.get_capacity(len(extra_bed)):
|
||||
raise ValidationError(_("Persons can't be higher than room capacity"))
|
||||
#if record.reservation_id.adults == 0:
|
||||
# raise ValidationError(_("Reservation has no adults"))
|
||||
|
||||
@@ -66,25 +66,6 @@ class PmsRoomTypeAvailability(models.Model):
|
||||
free_rooms = free_rooms & rooms_linked
|
||||
return free_rooms.sorted(key=lambda r: r.sequence)
|
||||
|
||||
@api.model
|
||||
def room_types_available(self, checkin, checkout, room_type_id=False, current_lines=False):
|
||||
domain = self._get_domain_reservations_occupation(
|
||||
dfrom=checkin,
|
||||
dto=checkout - timedelta(1),
|
||||
current_lines=current_lines,
|
||||
)
|
||||
reservation_lines = self.env['pms.reservation.line'].search(domain)
|
||||
reservations_rooms = reservation_lines.mapped("room_id.id")
|
||||
free_rooms = self.env["pms.room"].search(
|
||||
[("id", "not in", reservations_rooms)]
|
||||
)
|
||||
if room_type_id:
|
||||
rooms_linked = (
|
||||
self.env["pms.room.type"].search([("id", "=", room_type_id)]).room_ids
|
||||
)
|
||||
free_rooms = free_rooms & rooms_linked
|
||||
return free_rooms.sorted(key=lambda r: r.sequence)
|
||||
|
||||
@api.model
|
||||
def _get_domain_reservations_occupation(self, dfrom, dto, current_lines=False):
|
||||
domain = [
|
||||
|
||||
Reference in New Issue
Block a user