mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[WIP] Refactoring occupied function
This commit is contained in:
@@ -1190,7 +1190,7 @@ class HotelReservation(models.Model):
|
||||
if self.overbooking:
|
||||
return
|
||||
checkout_dt = date_utils.get_datetime(self.checkout)
|
||||
occupied = self.env['hotel.reservation'].occupied(
|
||||
occupied = self.env['hotel.reservation'].get_reservations(
|
||||
self.checkin,
|
||||
checkout_dt.strftime(DEFAULT_SERVER_DATE_FORMAT)).filtered(
|
||||
lambda r: r.id != self._origin.id)
|
||||
@@ -1281,15 +1281,16 @@ class HotelReservation(models.Model):
|
||||
Checkout date should be greater than the checkin date.
|
||||
3.-Check the reservation dates are not occuped
|
||||
"""
|
||||
chkin_utc_dt = date_utils.get_datetime(self.checkin)
|
||||
chkout_utc_dt = date_utils.get_datetime(self.checkout)
|
||||
if chkin_utc_dt >= chkout_utc_dt:
|
||||
# chkin_utc_dt = date_utils.get_datetime(self.checkin)
|
||||
# chkout_utc_dt = date_utils.get_datetime(self.checkout)
|
||||
if self.checkin >= self.checkout:
|
||||
raise ValidationError(_('Room line Check In Date Should be \
|
||||
less than the Check Out Date!'))
|
||||
if not self.overbooking and not self._context.get("ignore_avail_restrictions", False):
|
||||
occupied = self.env['hotel.reservation'].occupied(
|
||||
occupied = self.env['hotel.reservation'].get_reservations(
|
||||
self.checkin,
|
||||
chkout_utc_dt.strftime(DEFAULT_SERVER_DATE_FORMAT))
|
||||
self.checkout)
|
||||
# chkout_utc_dt.strftime(DEFAULT_SERVER_DATE_FORMAT))
|
||||
occupied = occupied.filtered(
|
||||
lambda r: r.room_id.id == self.room_id.id
|
||||
and r.id != self.id)
|
||||
@@ -1307,13 +1308,12 @@ class HotelReservation(models.Model):
|
||||
return super(HotelReservation, self).unlink()
|
||||
|
||||
@api.model
|
||||
# TODO change function name to get_reservations(self, dfrom, dto):
|
||||
def occupied(self, dfrom, dto):
|
||||
def get_reservations(self, dfrom, dto):
|
||||
"""
|
||||
@param self: The object pointer
|
||||
@param dfrom: starting range date from
|
||||
@param dto: starting range date to
|
||||
@return: array with the reservations confirmed between dfrom and dto
|
||||
@param dfrom: range date from
|
||||
@param dto: range date to
|
||||
@return: array with the reservations _confirmed_ between dfrom and dto
|
||||
"""
|
||||
domain = [('reservation_line_ids.date', '>=', dfrom),
|
||||
('reservation_line_ids.date', '<=', dto),
|
||||
|
||||
@@ -73,16 +73,24 @@ class HotelRoomType(models.Model):
|
||||
# return any(capacities) and min(capacities) or 0
|
||||
|
||||
@api.model
|
||||
def check_availability_virtual_room(self, checkin, checkout,
|
||||
# TODO Rename to check_availability_room_type
|
||||
def check_availability_virtual_room(self, dfrom, dto,
|
||||
room_type_id=False, notthis=[]):
|
||||
"""
|
||||
Check the avalability for an specific type of room
|
||||
@param self: The object pointer
|
||||
@param dfrom: Range date from
|
||||
@param dto: Range date to
|
||||
@param room_type_id: Room Type
|
||||
@param notthis: Array excluding Room Types
|
||||
@return: A recordset of free rooms ?
|
||||
"""
|
||||
occupied = self.env['hotel.reservation'].occupied(checkin, checkout)
|
||||
rooms_occupied = occupied.mapped('product_id.id')
|
||||
# occupied = self.env['hotel.reservation'].get_reservations(dfrom, dto)
|
||||
# rooms_occupied = occupied.mapped('product_id.id')
|
||||
reservations = self.env['hotel.reservation'].get_reservations(dfrom, dto)
|
||||
reservations_rooms = reservations.mapped('room_id.id')
|
||||
free_rooms = self.env['hotel.room'].search([
|
||||
('product_id.id', 'not in', rooms_occupied),
|
||||
('id', 'not in', reservations_rooms),
|
||||
('id', 'not in', notthis)
|
||||
])
|
||||
if room_type_id:
|
||||
|
||||
Reference in New Issue
Block a user