diff --git a/hotel_channel_connector/models/channel_backend/common.py b/hotel_channel_connector/models/channel_backend/common.py index 33a30b9ce..bad5d6132 100644 --- a/hotel_channel_connector/models/channel_backend/common.py +++ b/hotel_channel_connector/models/channel_backend/common.py @@ -231,6 +231,16 @@ class ChannelBackend(models.Model): title="Export Pricelists") return True + @api.multi + def close_online_sales(self): + channel_hotel_restr_item_obj = self.env['channel.hotel.room.type.restriction.item'] + for backend in self: + res = channel_hotel_restr_item_obj.close_online_sales(backend) + if not res and self.env.context.get('show_notify', True): + self.env.user.notify_warning("Error closing online sales", + title="Export Restrictions") + return True + @api.model def cron_push_changes(self): backends = self.env[self._name].search([]) @@ -241,3 +251,9 @@ class ChannelBackend(models.Model): @api.model def cron_import_reservations(self): self.env[self._name].search([]).import_reservations() + + + @api.model + def cron_close_online_sales(self, status=True): + backends = self.env[self._name].search([]) + backends.close_online_sales() diff --git a/hotel_channel_connector/models/hotel_room_type_restriction_item/common.py b/hotel_channel_connector/models/hotel_room_type_restriction_item/common.py index b9b97ff63..2329d9241 100644 --- a/hotel_channel_connector/models/hotel_room_type_restriction_item/common.py +++ b/hotel_channel_connector/models/hotel_room_type_restriction_item/common.py @@ -37,6 +37,14 @@ class ChannelHotelRoomTypeRestrictionItem(models.Model): exporter = work.component(usage='hotel.room.type.restriction.item.exporter') return exporter.push_restriction() + @job(default_channel='root.channel') + @api.model + def close_online_sales(self, backend): + with backend.work_on(self._name) as work: + exporter = work.component(usage='hotel.room.type.restriction.item.exporter') + return exporter.close_online_sales() + + class HotelRoomTypeRestrictionItem(models.Model): _inherit = 'hotel.room.type.restriction.item' diff --git a/hotel_channel_connector/models/hotel_room_type_restriction_item/exporter.py b/hotel_channel_connector/models/hotel_room_type_restriction_item/exporter.py index 5aa7e00d7..ac35da677 100644 --- a/hotel_channel_connector/models/hotel_room_type_restriction_item/exporter.py +++ b/hotel_channel_connector/models/hotel_room_type_restriction_item/exporter.py @@ -14,3 +14,7 @@ class HotelRoomTypeRestrictionItemExporter(Component): @api.model def push_restriction(self): raise NotImplementedError + + @api.model + def close_online_sales(self): + raise NotImplementedError \ No newline at end of file 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 26dec0c7b..cc0a64684 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 @@ -88,3 +88,42 @@ class HotelRoomTypeRestrictionItemExporter(Component): 'sync_date': fields.Datetime.now(), }) return True + + @api.model + def close_online_sales(self): + channel_rest_plan = self.env['channel.hotel.room.type.restriction'].search([ + ('backend_id', '=', self.backend_record.id), + ]) + channel_rest_item = self.env['channel.hotel.room.type.restriction.item'] + channel_room_types = self.env['channel.hotel.room.type'].search([ + ('external_id', '!=', ''), + ]) + for channel_room_type in channel_room_types: + today_restrictions = channel_rest_item.search([ + ('backend_id', '=', self.backend_record.id), + ('room_type_id', '=', channel_room_type.odoo_id.id), + ('date', '=', fields.Date.today()) + ]) + if today_restrictions: + today_restrictions.closed = True + else: + self.env['hotel.room.type.restriction.item'].with_context( + {'connector_no_export': True} + ).create({ + 'restriction_id': channel_rest_plan.odoo_id.id, + 'room_type_id': channel_room_type.odoo_id.id, + 'date': fields.Date.today(), + 'closed_departure': 0, + 'max_stay_arrival': 0, + 'min_stay': 0, + 'max_stay': 0, + 'min_stay_arrival': 0, + 'closed_arrival': 0, + 'closed': True, + 'channel_bind_ids': [(0, False, { + 'channel_pushed': False, + 'backend_id': self.backend_record.id, + })] + }) + + return self.push_restriction()