mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[WIP][IMP] hotel channel connector
This commit is contained in:
@@ -4,5 +4,5 @@
|
|||||||
from . import core
|
from . import core
|
||||||
from . import backend_adapter
|
from . import backend_adapter
|
||||||
from . import binder
|
from . import binder
|
||||||
from . import exporter
|
|
||||||
from . import importer
|
from . import importer
|
||||||
|
from . import exporter
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
# Copyright 2018 Alexandre Díaz <dev@redneboa.es>
|
# Copyright 2018 Alexandre Díaz <dev@redneboa.es>
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
import xmlrpclib
|
||||||
from odoo import _
|
from odoo import _
|
||||||
from odoo.exceptions import ValidationError
|
from odoo.exceptions import ValidationError
|
||||||
from odoo.addons.component.core import AbstractComponent
|
from odoo.addons.component.core import AbstractComponent
|
||||||
@@ -179,7 +180,7 @@ class HotelChannelInterfaceAdapter(AbstractComponent):
|
|||||||
@property
|
@property
|
||||||
def _server(self):
|
def _server(self):
|
||||||
try:
|
try:
|
||||||
channel_server = getattr(self.work, 'hotel_channel_server')
|
channel_server = getattr(self.work, 'channel_api')
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
raise AttributeError(
|
raise AttributeError(
|
||||||
'You must provide a hotel_channel_server attribute with a '
|
'You must provide a hotel_channel_server attribute with a '
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from odoo import api
|
|||||||
class BaseHotelChannelConnectorComponent(AbstractComponent):
|
class BaseHotelChannelConnectorComponent(AbstractComponent):
|
||||||
_name = 'base.hotel.channel.connector'
|
_name = 'base.hotel.channel.connector'
|
||||||
_inherit = 'base.connector'
|
_inherit = 'base.connector'
|
||||||
_collection = 'hotel.channel.backend'
|
_collection = 'channel.backend'
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def create_issue(self, section, message, channel_message, channel_object_id=False,
|
def create_issue(self, section, message, channel_message, channel_object_id=False,
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
# Copyright 2018 Alexandre Díaz <dev@redneboa.es>
|
# Copyright 2018 Alexandre Díaz <dev@redneboa.es>
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from . import channel_backend
|
|
||||||
from . import channel_binding
|
from . import channel_binding
|
||||||
|
|
||||||
|
from . import channel_backend
|
||||||
from . import res_config
|
from . import res_config
|
||||||
from . import hotel_room_type
|
from . import hotel_room_type
|
||||||
from . import product_pricelist
|
from . import product_pricelist
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ class ChannelHotelReservation(models.Model):
|
|||||||
required=True,
|
required=True,
|
||||||
ondelete='cascade')
|
ondelete='cascade')
|
||||||
channel_reservation_id = fields.Char("Channel Reservation ID", readonly=True, old_name='wrid')
|
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',
|
string='Channel OTA ID',
|
||||||
readonly=True,
|
readonly=True,
|
||||||
old_name='wchannel_id')
|
old_name='wchannel_id')
|
||||||
@@ -53,7 +53,7 @@ class ChannelHotelReservation(models.Model):
|
|||||||
@api.model
|
@api.model
|
||||||
def import_reservations(self, backend):
|
def import_reservations(self, backend):
|
||||||
with backend.work_on(self._name) as work:
|
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()
|
return importer.fetch_new_bookings()
|
||||||
|
|
||||||
@api.depends('channel_reservation_id', 'ota_id')
|
@api.depends('channel_reservation_id', 'ota_id')
|
||||||
@@ -271,7 +271,15 @@ class HotelReservation(models.Model):
|
|||||||
if not self.is_from_ota:
|
if not self.is_from_ota:
|
||||||
return super().on_change_checkin_checkout_product_id()
|
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'
|
_name = 'channel.binding.hotel.reservation.listener'
|
||||||
_inherit = 'base.connector.listener'
|
_inherit = 'base.connector.listener'
|
||||||
_apply_on = ['channel.hotel.reservation']
|
_apply_on = ['channel.hotel.reservation']
|
||||||
|
|||||||
@@ -14,3 +14,30 @@ class HotelReservationImporter(Component):
|
|||||||
_inherit = 'hotel.channel.importer'
|
_inherit = 'hotel.channel.importer'
|
||||||
_apply_on = ['channel.hotel.reservation']
|
_apply_on = ['channel.hotel.reservation']
|
||||||
_usage = 'hotel.reservation.importer'
|
_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
|
||||||
|
|||||||
Reference in New Issue
Block a user