mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[ADD] import reservations in a date range
This commit is contained in:
@@ -44,6 +44,9 @@ class HotelChannelInterfaceAdapter(AbstractComponent):
|
|||||||
def fetch_new_bookings(self):
|
def fetch_new_bookings(self):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def fetch_bookings(self, dfrom, dto):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
def fetch_booking(self, channel_reservation_id):
|
def fetch_booking(self, channel_reservation_id):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ class ChannelBackend(models.Model):
|
|||||||
server = fields.Char('Channel Service Server')
|
server = fields.Char('Channel Service Server')
|
||||||
security_token = fields.Char('Channel Service Security Token')
|
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')
|
reservation_id_str = fields.Char('Channel Reservation ID')
|
||||||
|
|
||||||
avail_from = fields.Date('Availability From')
|
avail_from = fields.Date('Availability From')
|
||||||
@@ -76,6 +78,23 @@ class ChannelBackend(models.Model):
|
|||||||
title="Import Reservations")
|
title="Import Reservations")
|
||||||
return True
|
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
|
@api.multi
|
||||||
def import_reservation(self):
|
def import_reservation(self):
|
||||||
channel_hotel_reservation_obj = self.env['channel.hotel.reservation']
|
channel_hotel_reservation_obj = self.env['channel.hotel.reservation']
|
||||||
|
|||||||
@@ -71,6 +71,13 @@ class ChannelHotelReservation(models.Model):
|
|||||||
importer = work.component(usage='hotel.reservation.importer')
|
importer = work.component(usage='hotel.reservation.importer')
|
||||||
return importer.fetch_new_bookings()
|
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')
|
@job(default_channel='root.channel')
|
||||||
@api.multi
|
@api.multi
|
||||||
def cancel_reservation(self):
|
def cancel_reservation(self):
|
||||||
|
|||||||
@@ -17,3 +17,6 @@ class HotelReservationImporter(Component):
|
|||||||
|
|
||||||
def fetch_new_bookings(self):
|
def fetch_new_bookings(self):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def fetch_bookings(self, dfrom, dto):
|
||||||
|
raise NotImplementedError
|
||||||
|
|||||||
@@ -48,6 +48,17 @@
|
|||||||
string="Import in background"/>
|
string="Import in background"/>
|
||||||
</div>
|
</div>
|
||||||
</group>
|
</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>
|
<group>
|
||||||
<label string="Import Reservation" class="oe_inline"/>
|
<label string="Import Reservation" class="oe_inline"/>
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@@ -287,13 +287,26 @@ class WuBookAdapter(AbstractComponent):
|
|||||||
})
|
})
|
||||||
return results
|
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):
|
def fetch_booking(self, channel_reservation_id):
|
||||||
rcode, results = self._server.fetch_booking(
|
rcode, results = self._server.fetch_booking(
|
||||||
self._session_info[0],
|
self._session_info[0],
|
||||||
self._session_info[1],
|
self._session_info[1],
|
||||||
channel_reservation_id)
|
channel_reservation_id)
|
||||||
if rcode != 0:
|
if rcode != 0:
|
||||||
raise ChannelConnectorError(_("Can't process reservation from wubook"), {
|
raise ChannelConnectorError(_("Can't process reservations from wubook"), {
|
||||||
'message': results,
|
'message': results,
|
||||||
})
|
})
|
||||||
return results
|
return results
|
||||||
|
|||||||
@@ -70,6 +70,30 @@ class HotelReservationImporter(Component):
|
|||||||
checkout_utc_dt.strftime(DEFAULT_SERVER_DATE_FORMAT))
|
checkout_utc_dt.strftime(DEFAULT_SERVER_DATE_FORMAT))
|
||||||
return count
|
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
|
@api.model
|
||||||
def _generate_booking_vals(self, broom, crcode, rcode, room_type_bind,
|
def _generate_booking_vals(self, broom, crcode, rcode, room_type_bind,
|
||||||
split_booking, dates_checkin, dates_checkout, real_checkin, real_checkout, book):
|
split_booking, dates_checkin, dates_checkout, real_checkin, real_checkout, book):
|
||||||
|
|||||||
Reference in New Issue
Block a user