From 5652dfd1b432b9a46fbb73a23f0eea7d6a516e40 Mon Sep 17 00:00:00 2001 From: Pablo Date: Thu, 14 Feb 2019 18:29:08 +0100 Subject: [PATCH] [WIP] creating room type with channel arguments --- .../models/hotel_room_type/common.py | 6 +++++- .../views/inherited_hotel_room_type_views.xml | 2 ++ .../components/backend_adapter.py | 16 ++++++++++------ .../models/hotel_room_type/common.py | 6 ++++-- .../models/hotel_room_type/exporter.py | 15 ++++++++++++++- 5 files changed, 35 insertions(+), 10 deletions(-) diff --git a/hotel_channel_connector/models/hotel_room_type/common.py b/hotel_channel_connector/models/hotel_room_type/common.py index ff5b3da4f..31c80c506 100644 --- a/hotel_channel_connector/models/hotel_room_type/common.py +++ b/hotel_channel_connector/models/hotel_room_type/common.py @@ -53,7 +53,7 @@ class ChannelHotelRoomType(models.Model): @api.constrains('channel_short_code') def _check_channel_short_code(self): for record in self: - if len(record.channel_short_code) > 4: # Wubook scode max. length + if self.channel_short_code and len(record.channel_short_code) > 4: # Wubook scode max. length raise ValidationError(_("Chanel short code can't be longer than 4 characters")) @job(default_channel='root.channel') @@ -123,6 +123,10 @@ class HotelRoomType(models.Model): # WARNING: more than one binding is currently not expected action['domain'] = [('id', 'in', channel_bind_ids.ids)] else: + action['context'] = {'default_odoo_id': self.id, + 'default_name': self.name, + 'default_ota_capacity': self.capacity, + 'default_list_price': self.list_price} action['target'] = 'new' return action diff --git a/hotel_channel_connector/views/inherited_hotel_room_type_views.xml b/hotel_channel_connector/views/inherited_hotel_room_type_views.xml index 1721a1731..ad551bb39 100644 --- a/hotel_channel_connector/views/inherited_hotel_room_type_views.xml +++ b/hotel_channel_connector/views/inherited_hotel_room_type_views.xml @@ -17,6 +17,8 @@ + + diff --git a/hotel_channel_connector_wubook/components/backend_adapter.py b/hotel_channel_connector_wubook/components/backend_adapter.py index f822fb2d9..8fa3a0953 100644 --- a/hotel_channel_connector_wubook/components/backend_adapter.py +++ b/hotel_channel_connector_wubook/components/backend_adapter.py @@ -121,9 +121,8 @@ class WuBookAdapter(AbstractComponent): return rcode_a == 0 and results_b == 0 # === ROOMS - def create_room(self, shortcode, name, capacity, price, availability, defboard, rtype): - import wdb; - wdb.set_trace() + def create_room(self, shortcode, name, capacity, price, availability, defboard, + names, descriptions, boards, min_price, max_price, rtype): rcode, results = self._server.new_room( self._session_info[0], self._session_info[1], @@ -132,9 +131,14 @@ class WuBookAdapter(AbstractComponent): capacity, price, availability, - shortcode[:4], + shortcode, defboard, - rtype + names, + descriptions, + boards, + int(rtype), + # min_price, + # max_price, ) if rcode != 0: raise ChannelConnectorError(_("Can't create room in WuBook"), { @@ -160,7 +164,7 @@ class WuBookAdapter(AbstractComponent): min_price, max_price, int(rtype), - False, + 0, ) if rcode != 0: raise ChannelConnectorError(_("Can't modify room in WuBook"), { diff --git a/hotel_channel_connector_wubook/models/hotel_room_type/common.py b/hotel_channel_connector_wubook/models/hotel_room_type/common.py index 8540d6eb6..061b93ab7 100644 --- a/hotel_channel_connector_wubook/models/hotel_room_type/common.py +++ b/hotel_channel_connector_wubook/models/hotel_room_type/common.py @@ -9,9 +9,11 @@ class HotelRoomTypeAdapter(Component): _inherit = 'wubook.adapter' _apply_on = 'channel.hotel.room.type' - def create_room(self, shortcode, name, capacity, price, availability, defboard, rtype): + def create_room(self, shortcode, name, capacity, price, availability, defboard, + names, descriptions, boards, min_price, max_price, rtype): return super(HotelRoomTypeAdapter, self).create_room( - shortcode, name, capacity, price, availability, defboard, rtype) + shortcode, name, capacity, price, availability, defboard, + names, descriptions, boards, min_price, max_price, rtype) def fetch_rooms(self): return super(HotelRoomTypeAdapter, self).fetch_rooms() 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 12328a36a..f269ad080 100644 --- a/hotel_channel_connector_wubook/models/hotel_room_type/exporter.py +++ b/hotel_channel_connector_wubook/models/hotel_room_type/exporter.py @@ -49,6 +49,13 @@ class HotelRoomTypeExporter(Component): seq_obj = self.env['ir.sequence'] short_code = seq_obj.next_by_code('hotel.room.type')[:4] try: + boards = {} + for board in binding.board_service_room_type_ids: + boards.update( + {board.channel_service: { + 'dtype': 2 if board.price_type == 'fixed' else 1, + 'value': board.amount}} + ) external_id = self.backend_adapter.create_room( short_code, binding.name, @@ -56,7 +63,13 @@ class HotelRoomTypeExporter(Component): binding.list_price, binding.total_rooms_count, 'nb', - binding.class_id and binding.class_id.code_class or False) + {}, + {}, + boards, + binding.min_price, + binding.max_price, + binding.class_id and binding.class_id.code_class or False, + ) except ChannelConnectorError as err: self.create_issue( section='room',