mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[FIX] Quota and Avail
This commit is contained in:
@@ -92,30 +92,6 @@ class ChannelHotelRoomTypeAvailability(models.Model):
|
|||||||
channel_pushed = fields.Boolean("Channel Pushed", readonly=True,
|
channel_pushed = fields.Boolean("Channel Pushed", readonly=True,
|
||||||
default=False)
|
default=False)
|
||||||
|
|
||||||
@api.constrains('max_avail')
|
|
||||||
def _check_avail(self):
|
|
||||||
room_type_obj = self.env['hotel.room.type']
|
|
||||||
issue_obj = self.env['hotel.channel.connector.issue']
|
|
||||||
for record in self:
|
|
||||||
cavail = len(room_type_obj.check_availability_room_type(
|
|
||||||
record.date,
|
|
||||||
record.date,
|
|
||||||
room_type_id=record.room_type_id.id))
|
|
||||||
max_avail = min(cavail, record.room_type_id.total_rooms_count)
|
|
||||||
if record.avail > max_avail:
|
|
||||||
issue_obj.sudo().create({
|
|
||||||
'section': 'avail',
|
|
||||||
'internal_message': _(r"The new availability can't be \
|
|
||||||
greater than the max. availability \
|
|
||||||
(%s) [Input: %d\Max: %d]") % (record.room_type_id.name,
|
|
||||||
record.avail,
|
|
||||||
max_avail),
|
|
||||||
'date_start': record.date,
|
|
||||||
'date_end': record.date,
|
|
||||||
})
|
|
||||||
# Auto-Fix channel availability
|
|
||||||
self._event('on_fix_channel_availability').notify(record)
|
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def refresh_availability(self, checkin, checkout, backend_id, room_id=False,
|
def refresh_availability(self, checkin, checkout, backend_id, room_id=False,
|
||||||
room_type_id=False, from_channel=False):
|
room_type_id=False, from_channel=False):
|
||||||
@@ -180,17 +156,17 @@ class ChannelHotelRoomTypeAvailability(models.Model):
|
|||||||
room_type_avail_id.write(vals_avail)
|
room_type_avail_id.write(vals_avail)
|
||||||
|
|
||||||
# Auto-Fix channel quota and max availability
|
# Auto-Fix channel quota and max availability
|
||||||
vals_avail = {}
|
# vals_avail = {}
|
||||||
# TODO: reduce quota by one instead of adjust to current channel availability
|
# # TODO: reduce quota by one instead of adjust to current channel availability
|
||||||
if room_type_avail_id.quota > avail:
|
# if room_type_avail_id.quota > avail:
|
||||||
vals_avail.update({'quota': avail})
|
# vals_avail.update({'quota': avail})
|
||||||
_logger.info(vals_avail)
|
# _logger.info(vals_avail)
|
||||||
if room_type_avail_id.max_avail > avail:
|
# if room_type_avail_id.max_avail > avail:
|
||||||
vals_avail.update({'max_avail': avail})
|
# vals_avail.update({'max_avail': avail})
|
||||||
if vals_avail:
|
# if vals_avail:
|
||||||
room_type_avail_id.with_context(
|
# room_type_avail_id.with_context(
|
||||||
{'connector_no_export': True}
|
# {'connector_no_export': True}
|
||||||
).write(vals_avail)
|
# ).write(vals_avail)
|
||||||
else:
|
else:
|
||||||
self.env['hotel.room.type.availability'].with_context(
|
self.env['hotel.room.type.availability'].with_context(
|
||||||
{'connector_no_export': True}
|
{'connector_no_export': True}
|
||||||
@@ -246,36 +222,36 @@ class BindingHotelRoomTypeAvailabilityListener(Component):
|
|||||||
binding.backend_id.id,
|
binding.backend_id.id,
|
||||||
room_type_id=record.room_type_id.id)
|
room_type_id=record.room_type_id.id)
|
||||||
|
|
||||||
# @skip_if(lambda self, record, **kwargs: self.no_connector_export(record))
|
@skip_if(lambda self, record, **kwargs: self.no_connector_export(record))
|
||||||
# def on_record_create(self, record, fields=None):
|
def on_record_create(self, record, fields=None):
|
||||||
# if not any(record.channel_bind_ids):
|
if not any(record.channel_bind_ids):
|
||||||
# channel_room_type_avail_obj = self.env[
|
channel_room_type_avail_obj = self.env[
|
||||||
# 'channel.hotel.room.type.availability']
|
'channel.hotel.room.type.availability']
|
||||||
# backends = self.env['channel.backend'].search([])
|
backends = self.env['channel.backend'].search([])
|
||||||
# for backend in backends:
|
for backend in backends:
|
||||||
# # REVIEW :: If you create directly channel_binding, this search
|
# REVIEW :: If you create directly channel_binding, this search
|
||||||
# # return empty
|
# return empty
|
||||||
# avail_bind = channel_room_type_avail_obj.search([
|
avail_bind = channel_room_type_avail_obj.search([
|
||||||
# ('odoo_id', '=', record.id),
|
('odoo_id', '=', record.id),
|
||||||
# ('backend_id', '=', backend.id),
|
('backend_id', '=', backend.id),
|
||||||
# ])
|
])
|
||||||
# if not avail_bind:
|
if not avail_bind:
|
||||||
# # REVIEW :: WARNING :: This create triggers on_record_write above
|
# REVIEW :: WARNING :: This create triggers on_record_write above
|
||||||
# avail_bind = channel_room_type_avail_obj.create({
|
avail_bind = channel_room_type_avail_obj.create({
|
||||||
# 'odoo_id': record.id,
|
'odoo_id': record.id,
|
||||||
# 'channel_pushed': False,
|
'channel_pushed': False,
|
||||||
# 'backend_id': backend.id,
|
'backend_id': backend.id,
|
||||||
# })
|
})
|
||||||
# _logger.info("==[on_record_create] :: hotel.room.type.availability==")
|
_logger.info("==[on_record_create] :: hotel.room.type.availability==")
|
||||||
# _logger.info(avail_bind)
|
_logger.info(avail_bind)
|
||||||
# else:
|
else:
|
||||||
# avail_bind.refresh_availability(
|
avail_bind.refresh_availability(
|
||||||
# record.date,
|
record.date,
|
||||||
# (datetime.strptime(record.date, DEFAULT_SERVER_DATE_FORMAT).date() +
|
(datetime.strptime(record.date, DEFAULT_SERVER_DATE_FORMAT).date() +
|
||||||
# timedelta(days=1)).strftime(DEFAULT_SERVER_DATE_FORMAT),
|
timedelta(days=1)).strftime(DEFAULT_SERVER_DATE_FORMAT),
|
||||||
# backend.id,
|
backend.id,
|
||||||
# # room_type_id=record.room_type_id.channel_bind_ids.id,
|
# room_type_id=record.room_type_id.channel_bind_ids.id,
|
||||||
# room_type_id=record.room_type_id.id)
|
room_type_id=record.room_type_id.id)
|
||||||
|
|
||||||
|
|
||||||
class ChannelBindingHotelRoomTypeAvailabilityListener(Component):
|
class ChannelBindingHotelRoomTypeAvailabilityListener(Component):
|
||||||
|
|||||||
@@ -84,12 +84,13 @@ class BindingHotelReservationListener(Component):
|
|||||||
fields_to_check = ('state', )
|
fields_to_check = ('state', )
|
||||||
fields_checked = [elm for elm in fields_to_check if elm in fields]
|
fields_checked = [elm for elm in fields_to_check if elm in fields]
|
||||||
if any(fields_checked):
|
if any(fields_checked):
|
||||||
for record in self:
|
if any(record.channel_bind_ids):
|
||||||
# Only can cancel reservations created directly in wubook
|
# Only can cancel reservations created directly in wubook
|
||||||
for binding in record.channel_bind_ids:
|
for binding in record.channel_bind_ids:
|
||||||
if binding.external_id and not binding.ota_id and \
|
if binding.external_id and not binding.ota_id and \
|
||||||
int(binding.channel_status) in WUBOOK_STATUS_GOOD:
|
int(binding.channel_status) in WUBOOK_STATUS_GOOD:
|
||||||
binding.sudo().cancel_reservation()
|
if record.state in ('cancelled'):
|
||||||
|
binding.sudo().cancel_reservation()
|
||||||
# self.env['channel.hotel.reservation']._event('on_record_cancel').notify(binding)
|
# self.env['channel.hotel.reservation']._event('on_record_cancel').notify(binding)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user