mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP] Adapt to hotel changes
This commit is contained in:
@@ -113,7 +113,6 @@ class BusHotelCalendar(models.TransientModel):
|
||||
vals['room_type_id']: {
|
||||
date_dt.strftime("%d/%m/%Y"): [
|
||||
vals['avail'],
|
||||
vals['no_ota'],
|
||||
vals['id'],
|
||||
],
|
||||
},
|
||||
|
||||
@@ -40,7 +40,6 @@ class HotelCalendarManagement(models.TransientModel):
|
||||
avail['date'], avail['date'], room_type_id=room_type.id))
|
||||
ravail = min(cavail, room_type.total_rooms_count, int(avail['avail']))
|
||||
vals = {
|
||||
'no_ota': avail['no_ota'],
|
||||
'avail': ravail,
|
||||
}
|
||||
return vals
|
||||
@@ -170,11 +169,20 @@ class HotelCalendarManagement(models.TransientModel):
|
||||
})
|
||||
return json_data
|
||||
|
||||
@api.model
|
||||
def _generate_avalaibility_data(self, room_type, date, avail):
|
||||
return {
|
||||
'id': avail and avail.id or False,
|
||||
'date': avail and avail.date or date,
|
||||
'avail': avail and avail.avail or room_type.total_rooms_count,
|
||||
}
|
||||
|
||||
@api.model
|
||||
def _hcalendar_availability_json_data(self, dfrom, dto):
|
||||
date_start = fields.Date.from_string(dfrom)
|
||||
date_end = fields.Date.from_string(dto)
|
||||
date_diff = abs((date_end - date_start).days) + 1
|
||||
hotel_room_type_avail_obj = self.env['hotel.room.type.availability']
|
||||
room_types = self.env['hotel.room.type'].search([])
|
||||
json_data = {}
|
||||
|
||||
@@ -183,24 +191,12 @@ class HotelCalendarManagement(models.TransientModel):
|
||||
for i in range(0, date_diff):
|
||||
cur_date = date_start + timedelta(days=i)
|
||||
cur_date_str = cur_date.strftime(DEFAULT_SERVER_DATE_FORMAT)
|
||||
avail = self.env['hotel.room.type.availability'].search([
|
||||
avail = hotel_room_type_avail_obj.search([
|
||||
('date', '=', cur_date_str),
|
||||
('room_type_id', '=', room_type.id)
|
||||
])
|
||||
if avail:
|
||||
json_data[room_type.id].append({
|
||||
'id': avail.id,
|
||||
'date': avail.date,
|
||||
'avail': avail.avail,
|
||||
'no_ota': avail.no_ota,
|
||||
})
|
||||
else:
|
||||
json_data[room_type.id].append({
|
||||
'id': False,
|
||||
'date': cur_date_str,
|
||||
'avail': room_type.total_rooms_count,
|
||||
'no_ota': False,
|
||||
})
|
||||
json_data[room_type.id].append(
|
||||
self._generate_avalaibility_data(room_type, cur_date_str, avail))
|
||||
return json_data
|
||||
|
||||
@api.model
|
||||
|
||||
@@ -6,16 +6,20 @@ from odoo import models, fields, api
|
||||
class HotelRoomTypeAvailability(models.Model):
|
||||
_inherit = 'hotel.room.type.availability'
|
||||
|
||||
def _prepare_notif_values(self, record):
|
||||
return {
|
||||
'date': record.date,
|
||||
'avail': record.avail,
|
||||
'room_type_id': record.room_type_id.id,
|
||||
'id': record.id,
|
||||
}
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
res = super(HotelRoomTypeAvailability, self).create(vals)
|
||||
self.env['bus.hotel.calendar'].send_availability_notification({
|
||||
'date': res.date,
|
||||
'avail': res.avail,
|
||||
'no_ota': res.no_ota,
|
||||
'room_type_id': res.room_type_id.id,
|
||||
'id': res.id,
|
||||
})
|
||||
self.env['bus.hotel.calendar'].send_availability_notification(
|
||||
self._prepare_notif_values(res)
|
||||
)
|
||||
return res
|
||||
|
||||
@api.multi
|
||||
@@ -23,13 +27,9 @@ class HotelRoomTypeAvailability(models.Model):
|
||||
ret_vals = super(HotelRoomTypeAvailability, self).write(vals)
|
||||
bus_hotel_calendar_obj = self.env['bus.hotel.calendar']
|
||||
for record in self:
|
||||
bus_hotel_calendar_obj.send_availability_notification({
|
||||
'date': record.date,
|
||||
'avail': record.avail,
|
||||
'no_ota': record.no_ota,
|
||||
'room_type_id': record.room_type_id.id,
|
||||
'id': record.id,
|
||||
})
|
||||
bus_hotel_calendar_obj.send_availability_notification(
|
||||
self._prepare_notif_values(record)
|
||||
)
|
||||
return ret_vals
|
||||
|
||||
@api.multi
|
||||
@@ -37,13 +37,9 @@ class HotelRoomTypeAvailability(models.Model):
|
||||
# Construct dictionary with relevant info of removed records
|
||||
unlink_vals = []
|
||||
for record in self:
|
||||
unlink_vals.append({
|
||||
'date': record.date,
|
||||
'avail': record.room_type_id.total_rooms_count,
|
||||
'room_type_id': record.room_type_id.id,
|
||||
'no_ota': False,
|
||||
'id': record.id,
|
||||
})
|
||||
unlink_vals.append(
|
||||
self._prepare_notif_values(record)
|
||||
)
|
||||
res = super(HotelRoomTypeAvailability, self).unlink()
|
||||
bus_hotel_calendar_obj = self.env['bus.hotel.calendar']
|
||||
for uval in unlink_vals:
|
||||
|
||||
Reference in New Issue
Block a user