mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP] real avail compute on hcalendar management
This commit is contained in:
@@ -1088,10 +1088,13 @@ class HotelReservation(models.Model):
|
|||||||
@return: array with the reservations _confirmed_ between both dates `dfrom` and `dto`
|
@return: array with the reservations _confirmed_ between both dates `dfrom` and `dto`
|
||||||
"""
|
"""
|
||||||
domain = self._get_domain_reservations_occupation(dfrom, dto)
|
domain = self._get_domain_reservations_occupation(dfrom, dto)
|
||||||
|
_logger.info(domain)
|
||||||
return self.env['hotel.reservation'].search(domain)
|
return self.env['hotel.reservation'].search(domain)
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _get_domain_reservations_occupation(self, dfrom, dto):
|
def _get_domain_reservations_occupation(self, dfrom, dto):
|
||||||
|
#WARNING If add or remove domain items, update _hcalendar_get_count_reservations_json_data
|
||||||
|
# in calendar module hotel_calendar_management.py
|
||||||
domain = [('reservation_line_ids.date', '>=', dfrom),
|
domain = [('reservation_line_ids.date', '>=', dfrom),
|
||||||
('reservation_line_ids.date', '<=', dto),
|
('reservation_line_ids.date', '<=', dto),
|
||||||
('state', '!=', 'cancelled'),
|
('state', '!=', 'cancelled'),
|
||||||
|
|||||||
@@ -179,14 +179,31 @@ class HotelCalendarManagement(models.TransientModel):
|
|||||||
for i in range(0, date_diff):
|
for i in range(0, date_diff):
|
||||||
cur_date = date_start + timedelta(days=i)
|
cur_date = date_start + timedelta(days=i)
|
||||||
cur_date_str = cur_date.strftime(DEFAULT_SERVER_DATE_FORMAT)
|
cur_date_str = cur_date.strftime(DEFAULT_SERVER_DATE_FORMAT)
|
||||||
|
self.env.cr.execute('''
|
||||||
|
SELECT
|
||||||
|
hrl.id
|
||||||
|
FROM hotel_reservation_line AS hrl
|
||||||
|
WHERE date = %s
|
||||||
|
''', ((cur_date_str),))
|
||||||
|
line_ids = [r[0] for r in self.env.cr.fetchall()]
|
||||||
|
reservation_ids = self.env['hotel.reservation.line'].browse(line_ids).\
|
||||||
|
mapped('reservation_id.id')
|
||||||
|
reservations = self.env['hotel.reservation'].\
|
||||||
|
browse(reservation_ids).filtered(
|
||||||
|
lambda r: r.state != 'cancelled'
|
||||||
|
and not r.overbooking and not r.reselling
|
||||||
|
)
|
||||||
|
reservations_rooms = reservations.mapped('room_id.id')
|
||||||
|
free_rooms = self.env['hotel.room'].search([
|
||||||
|
('id', 'not in', reservations_rooms),
|
||||||
|
])
|
||||||
|
rooms_linked = self.env['hotel.room.type'].search([
|
||||||
|
('id', '=', room_type.id)
|
||||||
|
]).room_ids
|
||||||
|
free_rooms = free_rooms & rooms_linked
|
||||||
json_data.setdefault(room_type.id, []).append({
|
json_data.setdefault(room_type.id, []).append({
|
||||||
'date': cur_date_str,
|
'date': cur_date_str,
|
||||||
'num': len(
|
'num': len(free_rooms),
|
||||||
room_type_obj.check_availability_room_type(
|
|
||||||
cur_date_str,
|
|
||||||
cur_date_str,
|
|
||||||
room_type_id=room_type.id)),
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return json_data
|
return json_data
|
||||||
|
|||||||
Reference in New Issue
Block a user