From 84fcd13c7c15eac27be8ecf1792253079a3af547 Mon Sep 17 00:00:00 2001 From: Pablo Quesada Barriuso Date: Sat, 28 Jul 2018 12:15:31 +0200 Subject: [PATCH] [WIP] Refactoring occupied function --- hotel/models/hotel_reservation.py | 22 +++++++++++----------- hotel/models/hotel_room_type.py | 16 ++++++++++++---- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/hotel/models/hotel_reservation.py b/hotel/models/hotel_reservation.py index c77a85ab8..0f5c8da8a 100644 --- a/hotel/models/hotel_reservation.py +++ b/hotel/models/hotel_reservation.py @@ -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), diff --git a/hotel/models/hotel_room_type.py b/hotel/models/hotel_room_type.py index 654e8dd9c..3ab86f464 100644 --- a/hotel/models/hotel_room_type.py +++ b/hotel/models/hotel_room_type.py @@ -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: