diff --git a/hotel_channel_connector/components/backend_adapter.py b/hotel_channel_connector/components/backend_adapter.py index 4cf04d669..068d87c36 100644 --- a/hotel_channel_connector/components/backend_adapter.py +++ b/hotel_channel_connector/components/backend_adapter.py @@ -44,6 +44,9 @@ class HotelChannelInterfaceAdapter(AbstractComponent): def fetch_new_bookings(self): raise NotImplementedError + def fetch_bookings(self, dfrom, dto): + raise NotImplementedError + def fetch_booking(self, channel_reservation_id): raise NotImplementedError diff --git a/hotel_channel_connector/models/channel_backend/common.py b/hotel_channel_connector/models/channel_backend/common.py index b11494172..33a30b9ce 100644 --- a/hotel_channel_connector/models/channel_backend/common.py +++ b/hotel_channel_connector/models/channel_backend/common.py @@ -27,6 +27,8 @@ class ChannelBackend(models.Model): server = fields.Char('Channel Service Server') security_token = fields.Char('Channel Service Security Token') + reservation_from = fields.Date('Reservation From') + reservation_to = fields.Date('Reservation To') reservation_id_str = fields.Char('Channel Reservation ID') avail_from = fields.Date('Availability From') @@ -76,6 +78,23 @@ class ChannelBackend(models.Model): title="Import Reservations") return True + @api.multi + def import_reservations_range(self): + channel_hotel_reservation_obj = self.env['channel.hotel.reservation'] + for backend in self: + count = channel_hotel_reservation_obj.import_reservations_range( + backend, + backend.reservation_from, + backend.reservation_to) + if self.env.context.get('show_notify', True): + if count == 0: + self.env.user.notify_info("No reservations to import. All done :)", + title="Import Reservations") + else: + self.env.user.notify_info("%d reservations successfully imported" % count, + title="Import Reservations") + return True + @api.multi def import_reservation(self): channel_hotel_reservation_obj = self.env['channel.hotel.reservation'] diff --git a/hotel_channel_connector/models/hotel_reservation/common.py b/hotel_channel_connector/models/hotel_reservation/common.py index 6dd98e33b..2fa037b52 100644 --- a/hotel_channel_connector/models/hotel_reservation/common.py +++ b/hotel_channel_connector/models/hotel_reservation/common.py @@ -71,6 +71,13 @@ class ChannelHotelReservation(models.Model): importer = work.component(usage='hotel.reservation.importer') return importer.fetch_new_bookings() + @job(default_channel='root.channel') + @api.model + def import_reservations_range(self, backend, dfrom, dto): + with backend.work_on(self._name) as work: + importer = work.component(usage='hotel.reservation.importer') + return importer.fetch_bookings(dfrom, dto) + @job(default_channel='root.channel') @api.multi def cancel_reservation(self): diff --git a/hotel_channel_connector/models/hotel_reservation/importer.py b/hotel_channel_connector/models/hotel_reservation/importer.py index 712afa718..8405a8d56 100644 --- a/hotel_channel_connector/models/hotel_reservation/importer.py +++ b/hotel_channel_connector/models/hotel_reservation/importer.py @@ -17,3 +17,6 @@ class HotelReservationImporter(Component): def fetch_new_bookings(self): raise NotImplementedError + + def fetch_bookings(self, dfrom, dto): + raise NotImplementedError diff --git a/hotel_channel_connector/views/channel_connector_backend_views.xml b/hotel_channel_connector/views/channel_connector_backend_views.xml index 8d8fa36fc..a49ee5db2 100644 --- a/hotel_channel_connector/views/channel_connector_backend_views.xml +++ b/hotel_channel_connector/views/channel_connector_backend_views.xml @@ -48,6 +48,17 @@ string="Import in background"/> + +