diff --git a/hotel_channel_connector/models/channel_backend/common.py b/hotel_channel_connector/models/channel_backend/common.py index c6bc55c84..b11494172 100644 --- a/hotel_channel_connector/models/channel_backend/common.py +++ b/hotel_channel_connector/models/channel_backend/common.py @@ -20,17 +20,11 @@ class ChannelBackend(models.Model): """ return [] - def _get_default_server(self): - return '' - name = fields.Char('Name') version = fields.Selection(selection='select_versions', required=True) username = fields.Char('Channel Service Username') passwd = fields.Char('Channel Service Password') - lcode = fields.Char('Channel Service lcode') - server = fields.Char('Channel Service Server', - default=_get_default_server) - pkey = fields.Char('Channel Service PKey') + server = fields.Char('Channel Service Server') security_token = fields.Char('Channel Service Security Token') reservation_id_str = fields.Char('Channel Reservation ID') diff --git a/hotel_channel_connector_wubook/controllers/main.py b/hotel_channel_connector_wubook/controllers/main.py index 6801dfb1f..caf5c2ffc 100644 --- a/hotel_channel_connector_wubook/controllers/main.py +++ b/hotel_channel_connector_wubook/controllers/main.py @@ -1,7 +1,6 @@ # Copyright 2018 Alexandre Díaz # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -import logging from datetime import datetime from odoo import http, _ from odoo.http import request @@ -9,23 +8,17 @@ from odoo.exceptions import ValidationError from odoo.addons.hotel_channel_connector_wubook.components.backend_adapter import ( DEFAULT_WUBOOK_DATE_FORMAT) from odoo.tools import DEFAULT_SERVER_DATE_FORMAT -_logger = logging.getLogger(__name__) class WubookPushURL(http.Controller): # Called when created a reservation in wubook @http.route(['/wubook/push/reservations/'], type='http', cors="*", auth="public", methods=['POST'], - website=True, csrf=True) + website=True, csrf=False) def wubook_push_reservations(self, security_token, **kwargs): rcode = kwargs.get('rcode') lcode = kwargs.get('lcode') - _logger.info("====== PUSH RESERVATION") - _logger.info(rcode) - _logger.info(lcode) - _logger.info(security_token) - # Correct Input? if not lcode or not rcode or not security_token: raise ValidationError(_('Invalid Input Parameters!')) diff --git a/hotel_channel_connector_wubook/models/channel_backend/common.py b/hotel_channel_connector_wubook/models/channel_backend/common.py index f07d986d7..b9d0da3fe 100644 --- a/hotel_channel_connector_wubook/models/channel_backend/common.py +++ b/hotel_channel_connector_wubook/models/channel_backend/common.py @@ -20,11 +20,12 @@ class ChannelBackend(models.Model): return [('1.2', '1.2+')] def _get_default_server(self): - super(ChannelBackend, self)._get_default_server() return 'https://wired.wubook.net/xrws/' lcode = fields.Char('Channel Service lcode') pkey = fields.Char('Channel Service PKey') + server = fields.Char('Channel Service Server', + default=_get_default_server) @contextmanager @api.multi diff --git a/hotel_channel_connector_wubook/models/channel_ota_info/importer.py b/hotel_channel_connector_wubook/models/channel_ota_info/importer.py index 2cb0dd9db..c1c012fe1 100644 --- a/hotel_channel_connector_wubook/models/channel_ota_info/importer.py +++ b/hotel_channel_connector_wubook/models/channel_ota_info/importer.py @@ -4,7 +4,7 @@ from odoo.addons.component.core import Component from odoo.addons.connector.components.mapper import mapping from odoo.addons.hotel_channel_connector.components.core import ChannelConnectorError -from odoo import api +from odoo import api, fields from odoo.tools import ( DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT) @@ -78,3 +78,7 @@ class ChannelOtaInfoImportMapper(Component): @mapping def backend_id(self, record): return {'backend_id': self.backend_record.id} + + @mapping + def sync_date(self, record): + return {'sync_date': fields.Datetime.now()} diff --git a/hotel_channel_connector_wubook/models/hotel_reservation/importer.py b/hotel_channel_connector_wubook/models/hotel_reservation/importer.py index eaafcd8ed..31b8e0e40 100644 --- a/hotel_channel_connector_wubook/models/hotel_reservation/importer.py +++ b/hotel_channel_connector_wubook/models/hotel_reservation/importer.py @@ -119,16 +119,16 @@ class HotelReservationImporter(Component): 'reservation_lines': reservation_lines, 'price_unit': tprice, 'to_assign': True, - 'wrid': rcode, + 'external_id': rcode, 'ota_id': ota_id and ota_id.id, - 'wchannel_reservation_code': crcode, + 'ota_reservation_id': crcode, 'channel_status': str(book['status']), 'to_read': True, 'state': is_cancellation and 'cancelled' or 'draft', 'room_type_id': room_type_bind.odoo_id.id, 'splitted': split_booking, - 'wbook_json': json.dumps(book), - 'wmodified': book['was_modified'], + 'channel_raw_data': json.dumps(book), + 'channel_modified': book['was_modified'], 'product_id': room_type_bind and room_type_bind.product_id.id, 'name': room_type_bind and room_type_bind.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 a01e8a2ee..2faf77a92 100644 --- a/hotel_channel_connector_wubook/models/hotel_room_type/exporter.py +++ b/hotel_channel_connector_wubook/models/hotel_room_type/exporter.py @@ -44,7 +44,6 @@ class HotelRoomTypeExporter(Component): channel_message=err.data['message']) else: binding.write({ - 'external_id': external_id, '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 549c9f6d0..242fbe044 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 @@ -51,5 +51,8 @@ class HotelRoomTypeAvailabilityExporter(Component): channel_message=err.data['message']) return False else: - channel_room_type_avails.write({'channel_pushed': True}) + channel_room_type_avails.write({ + 'channel_pushed': True, + 'sync_date': fields.Datetime.now(), + }) return True diff --git a/hotel_channel_connector_wubook/models/hotel_room_type_availability/importer.py b/hotel_channel_connector_wubook/models/hotel_room_type_availability/importer.py index a3a9aefbd..2509c451f 100644 --- a/hotel_channel_connector_wubook/models/hotel_room_type_availability/importer.py +++ b/hotel_channel_connector_wubook/models/hotel_room_type_availability/importer.py @@ -101,3 +101,7 @@ class HotelRoomTypeAvailabilityImportMapper(Component): @mapping def room_type_id(self, record): return {'room_type_id': record['room_type_id']} + + @mapping + def sync_date(self, record): + return {'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 c4294ebcc..dc2bcccad 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 @@ -31,5 +31,4 @@ class HotelRoomTypeRestrictionExporter(Component): internal_message=str(err), channel_message=err.data['message']) else: - binding.external_id = external_id self.binder.bind(external_id, binding) diff --git a/hotel_channel_connector_wubook/models/hotel_room_type_restriction/importer.py b/hotel_channel_connector_wubook/models/hotel_room_type_restriction/importer.py index 896079d5a..dd507321e 100644 --- a/hotel_channel_connector_wubook/models/hotel_room_type_restriction/importer.py +++ b/hotel_channel_connector_wubook/models/hotel_room_type_restriction/importer.py @@ -31,13 +31,14 @@ class HotelRoomTypeRestrictionImporter(Component): ('external_id', '=', str(plan['id'])), ], limit=1) if not plan_bind: - channel_restriction_obj.with_context({ + plan_bind = channel_restriction_obj.with_context({ 'connector_no_export': True, 'rules': plan.get('rules'), }).create(plan_record.values(for_create=True)) else: plan_bind.with_context({'connector_no_export':True}).write( plan_record.values()) + self.binder(str(plan['id']), plan_bind) count = count + 1 return count 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 e33eccd46..e6e82afa2 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 @@ -75,5 +75,8 @@ class HotelRoomTypeRestrictionItemExporter(Component): internal_message=str(err), channel_message=err.data['message']) else: - unpushed.write({'channel_pushed': True}) + unpushed.write({ + 'channel_pushed': True, + 'sync_date': fields.Datetime.now(), + }) return True diff --git a/hotel_channel_connector_wubook/models/hotel_room_type_restriction_item/importer.py b/hotel_channel_connector_wubook/models/hotel_room_type_restriction_item/importer.py index d1d6f53ee..5ad3e05a0 100644 --- a/hotel_channel_connector_wubook/models/hotel_room_type_restriction_item/importer.py +++ b/hotel_channel_connector_wubook/models/hotel_room_type_restriction_item/importer.py @@ -9,7 +9,7 @@ from odoo.addons.connector.components.mapper import mapping, only_create from odoo.addons.hotel_channel_connector_wubook.components.backend_adapter import ( DEFAULT_WUBOOK_DATE_FORMAT) from odoo.tools import DEFAULT_SERVER_DATE_FORMAT -from odoo import api +from odoo import api, fields _logger = logging.getLogger(__name__) @@ -117,3 +117,7 @@ class HotelRoomTypeRestrictionItemImportMapper(Component): @mapping def backend_id(self, record): return {'backend_id': self.backend_record.id} + + @mapping + def sync_date(self, record): + return {'sync_date': fields.Datetime.now()} diff --git a/hotel_channel_connector_wubook/models/product_pricelist/importer.py b/hotel_channel_connector_wubook/models/product_pricelist/importer.py index 5def26f5d..34dee1acb 100644 --- a/hotel_channel_connector_wubook/models/product_pricelist/importer.py +++ b/hotel_channel_connector_wubook/models/product_pricelist/importer.py @@ -33,13 +33,14 @@ class ProductPricelistImporter(Component): ('external_id', '=', str(plan['id'])), ], limit=1) if not plan_bind: - channel_product_listprice_obj.with_context({ + plan_bind = channel_product_listprice_obj.with_context({ 'connector_no_export': True, }).create(plan_record.values(for_create=True)) else: - channel_product_listprice_obj.with_context({ + plan_bind.with_context({ 'connector_no_export': True, }).write(plan_record.values()) + self.binder(str(plan['id']), plan_bind) count = count + 1 return count 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 fd6171ed5..e600c8e68 100644 --- a/hotel_channel_connector_wubook/models/product_pricelist_item/exporter.py +++ b/hotel_channel_connector_wubook/models/product_pricelist_item/exporter.py @@ -72,5 +72,8 @@ class ProductPricelistItemExporter(Component): internal_message=str(err), channel_message=err.data['message']) else: - channel_unpushed.write({'channel_pushed': True}) + channel_unpushed.write({ + 'channel_pushed': True, + 'sync_date': fields.Datetime.now(), + }) return True diff --git a/hotel_channel_connector_wubook/models/product_pricelist_item/importer.py b/hotel_channel_connector_wubook/models/product_pricelist_item/importer.py index cebd7262e..c801c36f2 100644 --- a/hotel_channel_connector_wubook/models/product_pricelist_item/importer.py +++ b/hotel_channel_connector_wubook/models/product_pricelist_item/importer.py @@ -28,7 +28,6 @@ class ProductPricelistItemImporter(Component): usage='import.mapper', model_name='channel.product.pricelist.item') if pricelist_bind: - _logger.info("==== PASA BIND") channel_pricelist_item_obj = self.env['channel.product.pricelist.item'] dfrom_dt = fields.Date.from_string(date_from) dto_dt = fields.Date.from_string(date_to) @@ -59,7 +58,6 @@ class ProductPricelistItemImporter(Component): ('product_tmpl_id', '=', channel_room_type.product_id.product_tmpl_id.id) ], limit=1) - _logger.info("=== ESCRIBEINDO") if pricelist_item: pricelist_item.with_context({ 'connector_no_export': True, @@ -139,3 +137,7 @@ class ProductPricelistItemImportMapper(Component): @mapping def backend_id(self, record): return {'backend_id': self.backend_record.id} + + @mapping + def sync_date(self, record): + return {'sync_date': fields.Datetime.now()} diff --git a/hotel_node_helper/models/inherited_hotel_room_type.py b/hotel_node_helper/models/inherited_hotel_room_type.py index 3247a2035..6bf42d41a 100644 --- a/hotel_node_helper/models/inherited_hotel_room_type.py +++ b/hotel_node_helper/models/inherited_hotel_room_type.py @@ -10,16 +10,6 @@ class HotelRoomType(models.Model): _inherit = 'hotel.room.type' - @api.model - def check_availability_room_ids(self, dfrom, dto, - room_type_id=False, notthis=[]): - """ - Check availability for all or specific room types between dates - @return: A list of `ids` with free rooms - """ - free_rooms = super().check_availability_room_type(dfrom, dto, room_type_id, notthis) - return free_rooms.ids - @api.model def get_room_type_availability(self, dfrom, dto, room_type_id): free_rooms = self.check_availability_room_type(dfrom, dto) @@ -62,3 +52,13 @@ class HotelRoomType(models.Model): min_stay = max([r['min_stay'] for r in restrictions_plan]) return min_stay + + @api.model + def get_room_type_planning(self, dfrom, dto, room_type_id): + availability = self.get_room_type_availability(dfrom, dto, room_type_id) + + price_unit = self.get_room_type_price_unit(dfrom, dto, room_type_id) + + restrictions = self.get_room_type_restrictions(dfrom, dto, room_type_id) + + return {'availability': availability, 'price_unit': price_unit, 'restrictions': restrictions}