diff --git a/hotel/models/hotel_reservation.py b/hotel/models/hotel_reservation.py index 4176a79a5..cb998ffff 100644 --- a/hotel/models/hotel_reservation.py +++ b/hotel/models/hotel_reservation.py @@ -515,8 +515,15 @@ class HotelReservation(models.Model): room_type_id = values.get('room_type_id') if checkin and checkout and room_type_id: if 'overbooking' not in values: - room_chosen = self.env['hotel.room.type'].check_availability_room_type(checkin, checkout, room_type_id)[0] - # Check room_chosen exist + room_chosen = self.env['hotel.room.type'].\ + check_availability_room_type( + checkin, + (fields.Date.from_string(checkout) - + timedelta(days=1)).strftime( + DEFAULT_SERVER_DATE_FORMAT + ), + room_type_id)[0] + # Check room_chosen exist else: room_chosen = self.env['hotel.room.type'].browse(room_type_id).room_ids[0] res.update({ diff --git a/hotel/models/hotel_room_type.py b/hotel/models/hotel_room_type.py index ae87b5e44..8f2831a88 100644 --- a/hotel/models/hotel_room_type.py +++ b/hotel/models/hotel_room_type.py @@ -68,7 +68,7 @@ class HotelRoomType(models.Model): @api.model def check_availability_room_type(self, dfrom, dto, - room_type_id=False, notthis=[]): + room_type_id=False, notthis=[]): """ Check the avalability for an specific type of room @param self: The object pointer @@ -78,7 +78,8 @@ class HotelRoomType(models.Model): @param notthis: Array excluding Rooms @return: A recordset of free rooms ? """ - reservations = self.env['hotel.reservation'].get_reservations(dfrom, dto) + reservations = self.env['hotel.reservation'].get_reservations(dfrom, + dto) reservations_rooms = reservations.mapped('room_id.id') free_rooms = self.env['hotel.room'].search([ ('id', 'not in', reservations_rooms), diff --git a/hotel/wizard/duplicate_reservation.py b/hotel/wizard/duplicate_reservation.py index 3af205cf9..5ed9929f7 100644 --- a/hotel/wizard/duplicate_reservation.py +++ b/hotel/wizard/duplicate_reservation.py @@ -2,7 +2,9 @@ # Copyright 2018 Alexandre Díaz # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from openerp.exceptions import ValidationError +from datetime import timedelta from openerp import models, fields, api, _ +from odoo.tools import DEFAULT_SERVER_DATE_FORMAT class DuplicateReservationWizard(models.TransientModel): @@ -34,7 +36,10 @@ class DuplicateReservationWizard(models.TransientModel): # Check Input avails = hotel_room_type_obj.check_availability_room_type( reservation_id.checkin, - reservation_id.checkout, + (fields.Date.from_string(reservation_id.checkout) - + timedelta(days=1)).strftime( + DEFAULT_SERVER_DATE_FORMAT + ), room_type_id=reservation_id.room_type_id.id) total_free_rooms = len(avails) @@ -45,7 +50,10 @@ class DuplicateReservationWizard(models.TransientModel): for i in range(0, self.num): free_rooms = hotel_room_type_obj.check_availability_room_type( reservation_id.checkin, - reservation_id.checkout, + (fields.Date.from_string(reservation_id.checkout) - + timedelta(days=1)).strftime( + DEFAULT_SERVER_DATE_FORMAT + ), room_type_id=reservation_id.room_type_id.id) if any(free_rooms): new_reservation_id = hotel_reservation_obj.create({ diff --git a/hotel/wizard/wizard_reservation.py b/hotel/wizard/wizard_reservation.py index 0f2650996..610f9bb28 100644 --- a/hotel/wizard/wizard_reservation.py +++ b/hotel/wizard/wizard_reservation.py @@ -339,7 +339,10 @@ class HotelRoomTypeWizards(models.TransientModel): ]) real_max = len(res.room_type_id.check_availability_room_type( res.checkin, - res.checkout, + (fields.Date.from_string(res.checkout) - + timedelta(days=1)).strftime( + DEFAULT_SERVER_DATE_FORMAT + ), res.room_type_id.id)) res.real_avail = real_max avail = 100000 diff --git a/hotel_channel_connector_wubook/models/hotel_reservation/importer.py b/hotel_channel_connector_wubook/models/hotel_reservation/importer.py index cfa17d5ae..04f408309 100644 --- a/hotel_channel_connector_wubook/models/hotel_reservation/importer.py +++ b/hotel_channel_connector_wubook/models/hotel_reservation/importer.py @@ -388,7 +388,10 @@ class HotelReservationImporter(Component): free_rooms = room_type_bind.odoo_id.check_availability_room_type( vals['checkin'], - vals['checkout'], + (fields.Date.from_string(vals['checkout']) - + timedelta(days=1)).strftime( + DEFAULT_SERVER_DATE_FORMAT + ), room_type_id=room_type_bind.odoo_id.id, notthis=used_rooms) if any(free_rooms):