[WIP][IMP] hotel channel connector

This commit is contained in:
QS5ELkMu
2018-09-20 01:59:45 +02:00
parent e7faa8476b
commit b1e76e4417
6 changed files with 44 additions and 7 deletions

View File

@@ -4,5 +4,5 @@
from . import core
from . import backend_adapter
from . import binder
from . import exporter
from . import importer
from . import exporter

View File

@@ -1,6 +1,7 @@
# Copyright 2018 Alexandre Díaz <dev@redneboa.es>
# 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 '

View File

@@ -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,

View File

@@ -1,8 +1,9 @@
# Copyright 2018 Alexandre Díaz <dev@redneboa.es>
# 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

View File

@@ -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']

View File

@@ -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