diff --git a/hotel_channel_connector/components/__init__.py b/hotel_channel_connector/components/__init__.py index 0d9ff44a4..45964d6bc 100644 --- a/hotel_channel_connector/components/__init__.py +++ b/hotel_channel_connector/components/__init__.py @@ -4,5 +4,5 @@ from . import core from . import backend_adapter from . import binder -from . import exporter from . import importer +from . import exporter diff --git a/hotel_channel_connector/components/backend_adapter.py b/hotel_channel_connector/components/backend_adapter.py index ea5fd6836..c06a33570 100644 --- a/hotel_channel_connector/components/backend_adapter.py +++ b/hotel_channel_connector/components/backend_adapter.py @@ -1,6 +1,7 @@ # Copyright 2018 Alexandre Díaz # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +import xmlrpclib from odoo import _ from odoo.exceptions import ValidationError from odoo.addons.component.core import AbstractComponent @@ -179,7 +180,7 @@ class HotelChannelInterfaceAdapter(AbstractComponent): @property def _server(self): try: - channel_server = getattr(self.work, 'hotel_channel_server') + channel_server = getattr(self.work, 'channel_api') except AttributeError: raise AttributeError( 'You must provide a hotel_channel_server attribute with a ' diff --git a/hotel_channel_connector/components/core.py b/hotel_channel_connector/components/core.py index d47d6b2fc..4590f6a2b 100644 --- a/hotel_channel_connector/components/core.py +++ b/hotel_channel_connector/components/core.py @@ -7,7 +7,7 @@ from odoo import api class BaseHotelChannelConnectorComponent(AbstractComponent): _name = 'base.hotel.channel.connector' _inherit = 'base.connector' - _collection = 'hotel.channel.backend' + _collection = 'channel.backend' @api.model def create_issue(self, section, message, channel_message, channel_object_id=False, diff --git a/hotel_channel_connector/models/__init__.py b/hotel_channel_connector/models/__init__.py index 96726f45d..70cca8a96 100644 --- a/hotel_channel_connector/models/__init__.py +++ b/hotel_channel_connector/models/__init__.py @@ -1,8 +1,9 @@ # Copyright 2018 Alexandre Díaz # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from . import channel_backend from . import channel_binding + +from . import channel_backend from . import res_config from . import hotel_room_type from . import product_pricelist diff --git a/hotel_channel_connector/models/hotel_reservation/common.py b/hotel_channel_connector/models/hotel_reservation/common.py index bf92a9bca..dd8254d48 100644 --- a/hotel_channel_connector/models/hotel_reservation/common.py +++ b/hotel_channel_connector/models/hotel_reservation/common.py @@ -26,7 +26,7 @@ class ChannelHotelReservation(models.Model): required=True, ondelete='cascade') channel_reservation_id = fields.Char("Channel Reservation ID", readonly=True, old_name='wrid') - ota_id = fields.Many2one('channel.ota.info', + ota_id = fields.Many2one('hotel.channel.connector.ota.info', string='Channel OTA ID', readonly=True, old_name='wchannel_id') @@ -53,7 +53,7 @@ class ChannelHotelReservation(models.Model): @api.model def import_reservations(self, backend): with backend.work_on(self._name) as work: - importer = work.component(usage='channel.hotel.reservation.importer') + importer = work.component(usage='hotel.reservation.importer') return importer.fetch_new_bookings() @api.depends('channel_reservation_id', 'ota_id') @@ -271,7 +271,15 @@ class HotelReservation(models.Model): if not self.is_from_ota: return super().on_change_checkin_checkout_product_id() -class ChannelBindingProductListener(Component): +class HotelReservationAdapter(Component): + _name = 'channel.hotel.reservation.adapter' + _inherit = 'wubook.adapter' + _apply_on = 'channel.hotel.reservation' + + def fetch_new_bookings(self): + return super(HotelReservationAdapter, self).fetch_new_bookings() + +class ChannelBindingHotelReservationListener(Component): _name = 'channel.binding.hotel.reservation.listener' _inherit = 'base.connector.listener' _apply_on = ['channel.hotel.reservation'] diff --git a/hotel_channel_connector/models/hotel_reservation/importer.py b/hotel_channel_connector/models/hotel_reservation/importer.py index e4e673b1d..203fc4d05 100644 --- a/hotel_channel_connector/models/hotel_reservation/importer.py +++ b/hotel_channel_connector/models/hotel_reservation/importer.py @@ -14,3 +14,30 @@ class HotelReservationImporter(Component): _inherit = 'hotel.channel.importer' _apply_on = ['channel.hotel.reservation'] _usage = 'hotel.reservation.importer' + + def fetch_new_bookings(self): + try: + results = self.backend_adapter.fetch_new_bookings() + processed_rids, errors, checkin_utc_dt, checkout_utc_dt = \ + self._generate_reservations(results) + if any(processed_rids): + uniq_rids = list(set(processed_rids)) + rcodeb, resultsb = self.backend_adapter.mark_bookings(uniq_rids) + if rcodeb != 0: + self.create_issue( + 'wubook', + _("Problem trying mark bookings (%s)") % str(processed_rids), + '') + # Update Odoo availability (don't wait for wubook) + # This cause abuse service in first import!! + if checkin_utc_dt and checkout_utc_dt: + self.backend_adapter.fetch_rooms_values( + checkin_utc_dt.strftime(DEFAULT_SERVER_DATE_FORMAT), + checkout_utc_dt.strftime(DEFAULT_SERVER_DATE_FORMAT)) + except ValidationError: + self.create_issue( + 'reservation', + _("Can't process reservations from wubook"), + results) + return False + return True