[ADD] close online sales for scheduled actions

This commit is contained in:
Pablo
2019-03-13 02:01:37 +01:00
parent b9c294db6e
commit 269214cf12
4 changed files with 67 additions and 0 deletions

View File

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

View File

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

View File

@@ -14,3 +14,7 @@ class HotelRoomTypeRestrictionItemExporter(Component):
@api.model
def push_restriction(self):
raise NotImplementedError
@api.model
def close_online_sales(self):
raise NotImplementedError

View File

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