From 8c7a5aa93b6386c1079b8be8c219ba58da1b9702 Mon Sep 17 00:00:00 2001 From: Cybrosys Technologies Date: Thu, 12 Dec 2024 15:12:05 +0530 Subject: [PATCH] Dec 12: [FIX] Bug Fixed 'hotel_management_odoo' --- hotel_management_odoo/__manifest__.py | 2 +- hotel_management_odoo/doc/RELEASE_NOTES.md | 6 ++++ hotel_management_odoo/models/room_booking.py | 2 +- .../models/room_booking_line.py | 31 ++++++++++++++++++- .../views/room_booking_views.xml | 1 - 5 files changed, 38 insertions(+), 4 deletions(-) diff --git a/hotel_management_odoo/__manifest__.py b/hotel_management_odoo/__manifest__.py index 047e16103..1a4945e8a 100644 --- a/hotel_management_odoo/__manifest__.py +++ b/hotel_management_odoo/__manifest__.py @@ -21,7 +21,7 @@ ############################################################################### { 'name': 'Hotel Management', - 'version': '18.0.1.0.0', + 'version': '18.0.1.1.0', 'category': 'Industries', 'summary': """A complete Hotel Management System that cover all areas of Hotel services""" , diff --git a/hotel_management_odoo/doc/RELEASE_NOTES.md b/hotel_management_odoo/doc/RELEASE_NOTES.md index e6c8567d2..338dd90b6 100644 --- a/hotel_management_odoo/doc/RELEASE_NOTES.md +++ b/hotel_management_odoo/doc/RELEASE_NOTES.md @@ -4,3 +4,9 @@ #### Version 18.0.1.0.0 #### ADD - Initial commit for Hotel Management + + +#### 11.12.2024 +#### Version 18.0.1.1.0 +#### UPDT +- Fixed the issue Room reservation based on check in and check out date. \ No newline at end of file diff --git a/hotel_management_odoo/models/room_booking.py b/hotel_management_odoo/models/room_booking.py index 74c66955b..d8177a91b 100644 --- a/hotel_management_odoo/models/room_booking.py +++ b/hotel_management_odoo/models/room_booking.py @@ -735,4 +735,4 @@ class RoomBooking(models.Model): 'pending_payment': round(pending_payment, 2), 'currency_symbol': self.env.user.company_id.currency_id.symbol, 'currency_position': self.env.user.company_id.currency_id.position - } + } \ No newline at end of file diff --git a/hotel_management_odoo/models/room_booking_line.py b/hotel_management_odoo/models/room_booking_line.py index 1cae38336..30bd44929 100644 --- a/hotel_management_odoo/models/room_booking_line.py +++ b/hotel_management_odoo/models/room_booking_line.py @@ -45,7 +45,6 @@ class RoomBookingLine(models.Model): " Otherwise sets to current Date", required=True) room_id = fields.Many2one('hotel.room', string="Room", - domain=[('status', '=', 'available')], help="Indicates the Room", required=True) uom_qty = fields.Float(string="Duration", @@ -137,3 +136,33 @@ class RoomBookingLine(models.Model): 'currency_id': self.currency_id, }, ) + + @api.onchange('checkin_date', 'checkout_date', 'room_id') + def onchange_checkin_date(self): + """On change of check-in date, check-out date, or room ID, + this method validates if the selected room is available + for the given dates. It searches for existing bookings + in the 'reserved' or 'check_in' state and checks for date + conflicts. If a conflict is found, a ValidationError is raised.""" + records = self.env['room.booking'].search( + [('state', 'in', ['reserved', 'check_in'])]) + for rec in records: + rec_room_id = rec.room_line_ids.room_id + rec_checkin_date = rec.room_line_ids.checkin_date + rec_checkout_date = rec.room_line_ids.checkout_date + if rec_room_id and rec_checkin_date and rec_checkout_date: + # Check for conflicts with existing room lines + for line in self: + if line.id != rec.id and line.room_id == rec_room_id: + # Check if the dates overlap + if (rec_checkin_date <= line.checkin_date <= rec_checkout_date or + rec_checkin_date <= line.checkout_date <= rec_checkout_date): + raise ValidationError( + _("Sorry, You cannot create a reservation for " + "this date since it overlaps with another " + "reservation..!!")) + if rec_checkout_date <= line.checkout_date and rec_checkin_date >= line.checkin_date: + raise ValidationError( + "Sorry You cannot create a reservation for this" + "date due to an existing reservation between " + "this date") diff --git a/hotel_management_odoo/views/room_booking_views.xml b/hotel_management_odoo/views/room_booking_views.xml index 27e83589b..6495f1ed3 100644 --- a/hotel_management_odoo/views/room_booking_views.xml +++ b/hotel_management_odoo/views/room_booking_views.xml @@ -91,7 +91,6 @@