From e7301ed2d7f8ad8d2e5a14ac23ba90721d21a90e Mon Sep 17 00:00:00 2001 From: QS5ELkMu Date: Fri, 7 Dec 2018 14:46:15 +0100 Subject: [PATCH] [FIX] Connector --- .../models/hotel_reservation/common.py | 8 +++++-- .../models/hotel_room_type/common.py | 5 ++++- .../hotel_room_type_availability/common.py | 22 ++++++++++++++++++- .../models/product_pricelist/common.py | 2 ++ .../models/hotel_reservation/exporter.py | 5 ++++- .../models/hotel_room_type/exporter.py | 8 +++++-- .../hotel_room_type_availability/exporter.py | 4 +++- .../hotel_room_type_restriction/exporter.py | 5 ++++- .../exporter.py | 6 ++++- .../models/product_pricelist/exporter.py | 5 ++++- .../models/product_pricelist_item/exporter.py | 4 +++- 11 files changed, 62 insertions(+), 12 deletions(-) diff --git a/hotel_channel_connector/models/hotel_reservation/common.py b/hotel_channel_connector/models/hotel_reservation/common.py index b02e04cf8..68bff4ecc 100644 --- a/hotel_channel_connector/models/hotel_reservation/common.py +++ b/hotel_channel_connector/models/hotel_reservation/common.py @@ -234,11 +234,15 @@ class ChannelBindingHotelReservationListener(Component): @skip_if(lambda self, record, **kwargs: self.no_connector_export(record)) def on_record_write(self, record, fields=None): - record.push_availability() + fields_to_check = ('room_id', 'state', 'checkin', 'checkout', 'room_type_id', + 'reservation_line_ids', 'splitted', 'overbooking') + fields_checked = [elm for elm in fields_to_check if elm in fields] + if any(fields_checked): + record.refresh_availability() @skip_if(lambda self, record, **kwargs: self.no_connector_export(record)) def on_record_unlink(self, record, fields=None): - record.push_availability() + record.refresh_availability() @skip_if(lambda self, record, **kwargs: self.no_connector_export(record)) def on_record_cancel(self, record, fields=None): diff --git a/hotel_channel_connector/models/hotel_room_type/common.py b/hotel_channel_connector/models/hotel_room_type/common.py index 84252479c..8c500d877 100644 --- a/hotel_channel_connector/models/hotel_room_type/common.py +++ b/hotel_channel_connector/models/hotel_room_type/common.py @@ -136,4 +136,7 @@ class ChannelBindingRoomTypeListener(Component): @skip_if(lambda self, record, **kwargs: self.no_connector_export(record)) def on_record_write(self, record, fields=None): - record.modify_room() + fields_to_check = ('name', 'ota_capacity', 'list_price', 'total_rooms_count') + fields_checked = [elm for elm in fields_to_check if elm in fields] + if any(fields_checked): + record.modify_room() diff --git a/hotel_channel_connector/models/hotel_room_type_availability/common.py b/hotel_channel_connector/models/hotel_room_type_availability/common.py index 19dc1f5e1..318ade762 100644 --- a/hotel_channel_connector/models/hotel_room_type_availability/common.py +++ b/hotel_channel_connector/models/hotel_room_type_availability/common.py @@ -153,6 +153,24 @@ class BindingHotelRoomTypeAvailabilityListener(Component): if 'avail' in fields: record.channel_bind_ids.write({'channel_pushed': False}) + @skip_if(lambda self, record, **kwargs: self.no_connector_export(record)) + def on_record_create(self, record, fields=None): + if not any(record.channel_bind_ids): + channel_room_type_avail_obj = self.env[ + 'channel.room.type.availability'] + backends = self.env['channel.backend'].search([]) + for backend in backends: + avail_bind = channel_room_type_avail_obj.search([ + ('odoo_id', '=', record.id), + ('backend_id', '=', backend.id), + ]) + if not avail_bind: + channel_room_type_avail_obj.create({ + 'odoo_id': record.id, + 'channel_pushed': False, + 'backend_id': backend.id, + }) + class ChannelBindingHotelRoomTypeAvailabilityListener(Component): _name = 'channel.binding.hotel.room.type.availability.listener' _inherit = 'base.connector.listener' @@ -160,7 +178,9 @@ class ChannelBindingHotelRoomTypeAvailabilityListener(Component): @skip_if(lambda self, record, **kwargs: self.no_connector_export(record)) def on_record_write(self, record, fields=None): - if 'avail' in fields: + fields_to_check = ('avail', 'date') + fields_checked = [elm for elm in fields_to_check if elm in fields] + if any(fields_checked): record.channel_pushed = False @skip_if(lambda self, record, **kwargs: self.no_connector_export(record)) diff --git a/hotel_channel_connector/models/product_pricelist/common.py b/hotel_channel_connector/models/product_pricelist/common.py index 0b0e28224..618ff04e0 100644 --- a/hotel_channel_connector/models/product_pricelist/common.py +++ b/hotel_channel_connector/models/product_pricelist/common.py @@ -75,6 +75,8 @@ class ProductPricelist(models.Model): if pricelist_bind.external_id: new_name += ' (%s Backend)' % pricelist_bind.backend_id.name names.append((name[0], new_name)) + else: + names.append((name[0], name[1])) return names class BindingProductPricelistListener(Component): diff --git a/hotel_channel_connector_wubook/models/hotel_reservation/exporter.py b/hotel_channel_connector_wubook/models/hotel_reservation/exporter.py index 9c2f59acf..5250dee49 100644 --- a/hotel_channel_connector_wubook/models/hotel_reservation/exporter.py +++ b/hotel_channel_connector_wubook/models/hotel_reservation/exporter.py @@ -3,7 +3,7 @@ from odoo.addons.component.core import Component from odoo.addons.hotel_channel_connector.components.core import ChannelConnectorError -from odoo import api, _ +from odoo import api, _, fields class HotelReservationExporter(Component): _inherit = 'channel.hotel.reservation.exporter' @@ -12,6 +12,9 @@ class HotelReservationExporter(Component): def cancel_reservation(self, binding): user = self.env['res.user'].browse(self.env.uid) try: + binding.with_context({ + 'connector_no_export': True, + }).write({'sync_date': fields.Datetime.now()}) return self.backend_adapter.cancel_reservation( binding.external_id, _('Cancelled by %s') % user.partner_id.name) diff --git a/hotel_channel_connector_wubook/models/hotel_room_type/exporter.py b/hotel_channel_connector_wubook/models/hotel_room_type/exporter.py index c763d51cb..7b045fc28 100644 --- a/hotel_channel_connector_wubook/models/hotel_room_type/exporter.py +++ b/hotel_channel_connector_wubook/models/hotel_room_type/exporter.py @@ -12,7 +12,9 @@ class HotelRoomTypeExporter(Component): @api.model def modify_room(self, binding): try: - binding.sync_date = fields.Datetime.now() + binding.with_context({ + 'connector_no_export': True, + }).write({'sync_date': fields.Datetime.now()}) return self.backend_adapter.modify_room( binding.external_id, binding.name, @@ -47,7 +49,9 @@ class HotelRoomTypeExporter(Component): internal_message=str(err), channel_message=err.data['message']) else: - binding.write({ + binding.with_context({ + 'connector_no_export': True, + }).write({ 'channel_short_code': short_code, }) self.binder.bind(external_id, binding) diff --git a/hotel_channel_connector_wubook/models/hotel_room_type_availability/exporter.py b/hotel_channel_connector_wubook/models/hotel_room_type_availability/exporter.py index 3698419a5..b104fd8c7 100644 --- a/hotel_channel_connector_wubook/models/hotel_room_type_availability/exporter.py +++ b/hotel_channel_connector_wubook/models/hotel_room_type_availability/exporter.py @@ -56,7 +56,9 @@ class HotelRoomTypeAvailabilityExporter(Component): channel_message=err.data['message']) return False else: - channel_room_type_avails.write({ + channel_room_type_avails.with_context({ + 'connector_no_export': True, + }).write({ 'channel_pushed': True, 'sync_date': fields.Datetime.now(), }) diff --git a/hotel_channel_connector_wubook/models/hotel_room_type_restriction/exporter.py b/hotel_channel_connector_wubook/models/hotel_room_type_restriction/exporter.py index dc2bcccad..793a041f9 100644 --- a/hotel_channel_connector_wubook/models/hotel_room_type_restriction/exporter.py +++ b/hotel_channel_connector_wubook/models/hotel_room_type_restriction/exporter.py @@ -3,7 +3,7 @@ from odoo.addons.component.core import Component from odoo.addons.hotel_channel_connector.components.core import ChannelConnectorError -from odoo import api +from odoo import api, fields class HotelRoomTypeRestrictionExporter(Component): @@ -12,6 +12,9 @@ class HotelRoomTypeRestrictionExporter(Component): @api.model def rename_rplan(self, binding): try: + binding.with_context({ + 'connector_no_export': True, + }).write({'sync_date': fields.Datetime.now()}) return self.backend_adapter.rename_rplan( binding.external_id, binding.name) diff --git a/hotel_channel_connector_wubook/models/hotel_room_type_restriction_item/exporter.py b/hotel_channel_connector_wubook/models/hotel_room_type_restriction_item/exporter.py index 2f5c39bc4..26dec0c7b 100644 --- a/hotel_channel_connector_wubook/models/hotel_room_type_restriction_item/exporter.py +++ b/hotel_channel_connector_wubook/models/hotel_room_type_restriction_item/exporter.py @@ -1,11 +1,13 @@ # Copyright 2018 Alexandre Díaz # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +import logging from datetime import timedelta from odoo.addons.component.core import Component from odoo.addons.hotel_channel_connector.components.core import ChannelConnectorError from odoo.tools import DEFAULT_SERVER_DATE_FORMAT from odoo import api,fields +_logger = logging.getLogger(__name__) class HotelRoomTypeRestrictionItemExporter(Component): @@ -79,7 +81,9 @@ class HotelRoomTypeRestrictionItemExporter(Component): internal_message=str(err), channel_message=err.data['message']) else: - unpushed.write({ + unpushed.with_context({ + 'connector_no_export': True, + }).write({ 'channel_pushed': True, 'sync_date': fields.Datetime.now(), }) diff --git a/hotel_channel_connector_wubook/models/product_pricelist/exporter.py b/hotel_channel_connector_wubook/models/product_pricelist/exporter.py index 0d5e00137..4ca694f9d 100644 --- a/hotel_channel_connector_wubook/models/product_pricelist/exporter.py +++ b/hotel_channel_connector_wubook/models/product_pricelist/exporter.py @@ -3,7 +3,7 @@ from odoo.addons.component.core import Component from odoo.addons.hotel_channel_connector.components.core import ChannelConnectorError -from odoo import api, _ +from odoo import api, _, fields class ProductPricelistExporter(Component): @@ -12,6 +12,9 @@ class ProductPricelistExporter(Component): @api.model def rename_plan(self, binding): try: + binding.with_context({ + 'connector_no_export': True, + }).write({'sync_date': fields.Datetime.now()}) return self.backend_adapter.rename_plan( binding.external_id, binding.name) diff --git a/hotel_channel_connector_wubook/models/product_pricelist_item/exporter.py b/hotel_channel_connector_wubook/models/product_pricelist_item/exporter.py index e600c8e68..fb22d61ea 100644 --- a/hotel_channel_connector_wubook/models/product_pricelist_item/exporter.py +++ b/hotel_channel_connector_wubook/models/product_pricelist_item/exporter.py @@ -72,7 +72,9 @@ class ProductPricelistItemExporter(Component): internal_message=str(err), channel_message=err.data['message']) else: - channel_unpushed.write({ + channel_unpushed.with_context({ + 'connector_no_export': True, + }).write({ 'channel_pushed': True, 'sync_date': fields.Datetime.now(), })