From 647add666c86402fc4930603107136d19004ca3f Mon Sep 17 00:00:00 2001 From: Pablo Date: Mon, 11 Feb 2019 17:31:07 +0100 Subject: [PATCH] [FIX] notify calendar with channel connector information --- .../models/inherited_bus_hotel_calendar.py | 21 +++++++++++++++++++ .../models/inherited_hotel_reservation.py | 15 +++++++++++++ 2 files changed, 36 insertions(+) diff --git a/hotel_calendar_channel_connector/models/inherited_bus_hotel_calendar.py b/hotel_calendar_channel_connector/models/inherited_bus_hotel_calendar.py index dce4784a5..3f17225ec 100644 --- a/hotel_calendar_channel_connector/models/inherited_bus_hotel_calendar.py +++ b/hotel_calendar_channel_connector/models/inherited_bus_hotel_calendar.py @@ -1,14 +1,35 @@ # Copyright 2018-2019 Alexandre Díaz # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +import logging from datetime import datetime from odoo.tools import DEFAULT_SERVER_DATE_FORMAT from odoo import models, api from odoo.addons.hotel_calendar.controllers.bus import HOTEL_BUS_CHANNEL_ID +_logger = logging.getLogger(__name__) class BusHotelCalendar(models.TransientModel): _inherit = 'bus.hotel.calendar' + @api.model + def _generate_reservation_notif(self, vals): + notif = super(BusHotelCalendar, self)._generate_reservation_notif(vals) + reserv = self.env['hotel.reservation'].browse(vals['reserv_id']) + if any(reserv.channel_bind_ids): + notif['tooltip'].update({ + 'ota_name': reserv.channel_bind_ids[0].ota_id.name, + 'ota_reservation_id': reserv.channel_bind_ids[0].ota_reservation_id, + 'external_id': reserv.channel_bind_ids[0].external_id, + }) + elif reserv.splitted and reserv.parent_reservation.channel_bind_ids: + # chunks in splitted reservation has not channel_bind_ids + notif['tooltip'].update({ + 'ota_name': reserv.parent_reservation.channel_bind_ids[0].ota_id.name, + 'ota_reservation_id': reserv.parent_reservation.channel_bind_ids[0].ota_reservation_id, + 'external_id': reserv.parent_reservation.channel_bind_ids[0].external_id, + }) + return notif + @api.model def _generate_availability_notification(self, vals): date_dt = datetime.strptime(vals['date'], DEFAULT_SERVER_DATE_FORMAT) diff --git a/hotel_calendar_channel_connector/models/inherited_hotel_reservation.py b/hotel_calendar_channel_connector/models/inherited_hotel_reservation.py index 9ded708a7..c3ce0d635 100644 --- a/hotel_calendar_channel_connector/models/inherited_hotel_reservation.py +++ b/hotel_calendar_channel_connector/models/inherited_hotel_reservation.py @@ -25,14 +25,29 @@ class HotelReservation(models.Model): 'ota_reservation_id': reserv.channel_bind_ids[0].ota_reservation_id, 'external_id': reserv.channel_bind_ids[0].external_id, }) + elif reserv.splitted and reserv.parent_reservation.channel_bind_ids: + # chunks in splitted reservation has not channel_bind_ids + vals[1][reserv.id].update({ + 'ota_name': reserv.parent_reservation.channel_bind_ids[0].ota_id.name, + 'ota_reservation_id': reserv.parent_reservation.channel_bind_ids[0].ota_reservation_id, + 'external_id': reserv.parent_reservation.channel_bind_ids[0].external_id, + }) + # REVIEW: What happens if the reservation is splitted and no parent with channel_bind_ids ¿? return vals @api.multi def generate_bus_values(self, naction, ntype, ntitle=''): + self.ensure_one() vals = super(HotelReservation, self).generate_bus_values(naction, ntype, ntitle) vals.update({ 'fix_days': self.splitted or self.is_from_ota, }) + if any(self.channel_bind_ids): + vals.update({ + 'ota_name': self.channel_bind_ids[0].ota_id.name, + 'ota_reservation_id': self.channel_bind_ids[0].ota_reservation_id, + 'external_id': self.channel_bind_ids[0].external_id, + }) return vals @api.multi