[ADD] import reservations in a date range

This commit is contained in:
Pablo
2019-03-12 08:05:33 +01:00
committed by Dario Lodeiros
parent 409883f276
commit e5d2b19819
7 changed files with 81 additions and 1 deletions

View File

@@ -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

View File

@@ -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']

View File

@@ -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):

View File

@@ -17,3 +17,6 @@ class HotelReservationImporter(Component):
def fetch_new_bookings(self):
raise NotImplementedError
def fetch_bookings(self, dfrom, dto):
raise NotImplementedError

View File

@@ -48,6 +48,17 @@
string="Import in background"/>
</div>
</group>
<group>
<label string="Import Reservations in a Range" class="oe_inline"/>
<div>
<field name="reservation_from" class="oe_inline" nolabel="1"/>
<field name="reservation_to" class="oe_inline" nolabel="1"/>
<button name="import_reservations_range"
type="object"
class="oe_highlight"
string="Import in background"/>
</div>
</group>
<group>
<label string="Import Reservation" class="oe_inline"/>
<div>

View File

@@ -287,13 +287,26 @@ class WuBookAdapter(AbstractComponent):
})
return results
def fetch_bookings(self, dfrom, dto):
rcode, results = self._server.fetch_bookings(
self._session_info[0],
self._session_info[1],
fields.Date.from_string(dfrom).strftime(DEFAULT_WUBOOK_DATE_FORMAT),
fields.Date.from_string(dto).strftime(DEFAULT_WUBOOK_DATE_FORMAT),
0) # When oncreated is 0, the filter is applied against the arrival date
if rcode != 0:
raise ChannelConnectorError(_("Can't process reservations from wubook"), {
'message': results,
})
return results
def fetch_booking(self, channel_reservation_id):
rcode, results = self._server.fetch_booking(
self._session_info[0],
self._session_info[1],
channel_reservation_id)
if rcode != 0:
raise ChannelConnectorError(_("Can't process reservation from wubook"), {
raise ChannelConnectorError(_("Can't process reservations from wubook"), {
'message': results,
})
return results

View File

@@ -70,6 +70,30 @@ class HotelReservationImporter(Component):
checkout_utc_dt.strftime(DEFAULT_SERVER_DATE_FORMAT))
return count
def fetch_bookings(self, dfrom, dto):
count = 0
try:
results = self.backend_adapter.fetch_bookings(dfrom, dto)
except ChannelConnectorError as err:
self.create_issue(
section='reservation',
internal_message=str(err),
channel_message=err.data['message'])
else:
if any(results):
processed_rids, errors, checkin_utc_dt, checkout_utc_dt = \
self._generate_reservations(results)
if any(processed_rids):
uniq_rids = list(set(processed_rids))
count = len(uniq_rids)
# Update Odoo availability (don't wait for wubook)
# FIXME: This cause abuse service in first import!!
if checkin_utc_dt and checkout_utc_dt:
self.backend_adapter.fetch_rooms_values(
checkin_utc_dt.strftime(DEFAULT_SERVER_DATE_FORMAT),
checkout_utc_dt.strftime(DEFAULT_SERVER_DATE_FORMAT))
return count
@api.model
def _generate_booking_vals(self, broom, crcode, rcode, room_type_bind,
split_booking, dates_checkin, dates_checkout, real_checkin, real_checkout, book):