From 8ba37941669952f234a4fc90dcf64d591ee4254f Mon Sep 17 00:00:00 2001 From: Pablo Date: Tue, 6 Aug 2019 11:54:07 +0200 Subject: [PATCH 1/3] [FIX] availability in cancelled modifications --- .../models/hotel_reservation/importer.py | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/hotel_channel_connector_wubook/models/hotel_reservation/importer.py b/hotel_channel_connector_wubook/models/hotel_reservation/importer.py index 48230ee94..c1cd15d1e 100644 --- a/hotel_channel_connector_wubook/models/hotel_reservation/importer.py +++ b/hotel_channel_connector_wubook/models/hotel_reservation/importer.py @@ -252,6 +252,18 @@ class HotelReservationImporter(Component): return (checkin_utc_dt, checkout_utc_dt) + def _force_update_availability_wubook(self, binding): + # WuBook always add +1 in the channel manager for cancelled reservation + # However, the quota in Odoo has preference in the availability + cancelled_dates = binding.reservation_line_ids.mapped('date') + channel_availability = self.env['channel.hotel.room.type.availability'].search([ + ('backend_id', '=', binding.backend_id.id), + ('date', 'in', cancelled_dates) + ]) + channel_availability.write({'channel_pushed': False}) + # Force an update with the correct availability + channel_availability.push_availability(binding.backend_id) + def _update_reservation_binding(self, binding, book): is_cancellation = book['status'] in WUBOOK_STATUS_BAD binding.with_context({'connector_no_export': True}).write({ @@ -270,16 +282,7 @@ class HotelReservationImporter(Component): binding.odoo_id.with_context({ 'connector_no_export': True, 'ota_limits': False}).action_cancel() - # WuBook always add +1 in the channel manager for cancelled reservation - # However, the quota in Odoo has preference in the availability - cancelled_dates = binding.reservation_line_ids.mapped('date') - channel_availability = self.env['channel.hotel.room.type.availability'].search([ - ('backend_id', '=', binding.backend_id.id), - ('date', 'in', cancelled_dates) - ]) - channel_availability.write({'channel_pushed': False}) - # Force an update with the correct availability - channel_availability.push_availability(binding.backend_id) + self._force_update_availability_wubook(binding) elif binding.state == 'cancelled': binding.with_context({ 'connector_no_export': True, @@ -336,6 +339,8 @@ class HotelReservationImporter(Component): reservations -= reservation else: new_books.append(broom) + # Review quota if new reservation is a modification not recognized in this method + # because quota is __always__ decreased when creating reservation, even in the overlapped days return new_books, reservations @@ -410,6 +415,7 @@ class HotelReservationImporter(Component): 'connector_no_export': True, 'ota_limits': False, 'no_penalty': True}).action_cancel() + self._force_update_availability_wubook(res.odoo_id) if len(new_books) == 0: processed_rids.append(rcode) continue From 7dbc2ca735d04c313ddcfbee84eb0924ffa68e33 Mon Sep 17 00:00:00 2001 From: Pablo Date: Tue, 6 Aug 2019 11:54:07 +0200 Subject: [PATCH 2/3] [FIX] availability in cancelled modifications --- .../models/hotel_reservation/importer.py | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/hotel_channel_connector_wubook/models/hotel_reservation/importer.py b/hotel_channel_connector_wubook/models/hotel_reservation/importer.py index 48230ee94..d24512ec5 100644 --- a/hotel_channel_connector_wubook/models/hotel_reservation/importer.py +++ b/hotel_channel_connector_wubook/models/hotel_reservation/importer.py @@ -252,6 +252,18 @@ class HotelReservationImporter(Component): return (checkin_utc_dt, checkout_utc_dt) + def _force_update_availability_wubook(self, binding): + # WuBook always add +1 in the channel manager for cancelled reservation + # However, the quota in Odoo has preference in the availability + cancelled_dates = binding.reservation_line_ids.mapped('date') + channel_availability = self.env['channel.hotel.room.type.availability'].search([ + ('backend_id', '=', binding.backend_id.id), + ('date', 'in', cancelled_dates) + ]) + channel_availability.write({'channel_pushed': False}) + # Force an update with the correct availability + channel_availability.push_availability(binding.backend_id) + def _update_reservation_binding(self, binding, book): is_cancellation = book['status'] in WUBOOK_STATUS_BAD binding.with_context({'connector_no_export': True}).write({ @@ -270,16 +282,7 @@ class HotelReservationImporter(Component): binding.odoo_id.with_context({ 'connector_no_export': True, 'ota_limits': False}).action_cancel() - # WuBook always add +1 in the channel manager for cancelled reservation - # However, the quota in Odoo has preference in the availability - cancelled_dates = binding.reservation_line_ids.mapped('date') - channel_availability = self.env['channel.hotel.room.type.availability'].search([ - ('backend_id', '=', binding.backend_id.id), - ('date', 'in', cancelled_dates) - ]) - channel_availability.write({'channel_pushed': False}) - # Force an update with the correct availability - channel_availability.push_availability(binding.backend_id) + self._force_update_availability_wubook(binding) elif binding.state == 'cancelled': binding.with_context({ 'connector_no_export': True, @@ -336,6 +339,8 @@ class HotelReservationImporter(Component): reservations -= reservation else: new_books.append(broom) + # Review quota if new reservation is a modification not recognized in this method + # because quota is __always__ decreased when creating reservation, even in the overlapped days return new_books, reservations @@ -410,6 +415,7 @@ class HotelReservationImporter(Component): 'connector_no_export': True, 'ota_limits': False, 'no_penalty': True}).action_cancel() + self._force_update_availability_wubook(res.channel_bind_ids[0]) if len(new_books) == 0: processed_rids.append(rcode) continue From 92920b3e3f2b80838442ad43bf4efc46e3551722 Mon Sep 17 00:00:00 2001 From: Pablo Date: Wed, 7 Aug 2019 10:13:06 +0200 Subject: [PATCH 3/3] [FIX] Adjust Board Services price with OTA capacity in WuBook --- .../models/hotel_room_type/exporter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 757a12380..c6eb2c00b 100644 --- a/hotel_channel_connector_wubook/models/hotel_room_type/exporter.py +++ b/hotel_channel_connector_wubook/models/hotel_room_type/exporter.py @@ -23,7 +23,7 @@ class HotelRoomTypeExporter(Component): boards.update( {board.channel_service: { 'dtype': 2 if board.price_type == 'fixed' else 1, - 'value': board.amount}} + 'value': board.amount * binding.ota_capacity}} ) and board.channel_service return self.backend_adapter.modify_room( binding.external_id, @@ -59,7 +59,7 @@ class HotelRoomTypeExporter(Component): boards.update( {board.channel_service: { 'dtype': 2 if board.price_type == 'fixed' else 1, - 'value': board.amount}} + 'value': board.amount * binding.ota_capacity}} ) and board.channel_service external_id = self.backend_adapter.create_room( short_code,