diff --git a/hotel/models/hotel_reservation.py b/hotel/models/hotel_reservation.py
index ad112e417..efe4c7044 100644
--- a/hotel/models/hotel_reservation.py
+++ b/hotel/models/hotel_reservation.py
@@ -1117,7 +1117,7 @@ class HotelReservation(models.Model):
@return: array with the reservations _confirmed_ between both dates `dfrom` and `dto`
"""
domain = self._get_domain_reservations_occupation(dfrom, dto)
- _logger.info(domain)
+ # _logger.info(domain)
return self.env['hotel.reservation'].search(domain)
@api.model
diff --git a/hotel_channel_connector/__manifest__.py b/hotel_channel_connector/__manifest__.py
index 51ac74bb6..b2e1571da 100644
--- a/hotel_channel_connector/__manifest__.py
+++ b/hotel_channel_connector/__manifest__.py
@@ -38,6 +38,8 @@
'views/channel_ota_info_views.xml',
'wizard/inherited_massive_changes.xml',
'data/menus.xml',
+ 'data/cron_jobs.xml',
+ 'data/email_availability_watchdog.xml',
'security/ir.model.access.csv',
#'security/wubook_security.xml',
# 'views/res_config.xml'
diff --git a/hotel_channel_connector/data/cron_jobs.xml b/hotel_channel_connector/data/cron_jobs.xml
new file mode 100644
index 000000000..633e421af
--- /dev/null
+++ b/hotel_channel_connector/data/cron_jobs.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+ Watchdog Free Rooms and Channel Availability
+ 1
+ days
+ -1
+
+
+
+ code
+ model.with_context({'email_to': 'watchdog@roomdoo.com'}).cron_channel_availability_watchdog()
+
+
+
diff --git a/hotel_channel_connector/data/email_availability_watchdog.xml b/hotel_channel_connector/data/email_availability_watchdog.xml
new file mode 100644
index 000000000..a94eeeec4
--- /dev/null
+++ b/hotel_channel_connector/data/email_availability_watchdog.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+ Channel Availability Watchdog by Email
+ Channel availability mismatch ${object.username}
+
+
+ Channel Availability Watchdog by Email
+
+
+
diff --git a/hotel_channel_connector/models/channel_backend/common.py b/hotel_channel_connector/models/channel_backend/common.py
index bad5d6132..4797d3c4d 100644
--- a/hotel_channel_connector/models/channel_backend/common.py
+++ b/hotel_channel_connector/models/channel_backend/common.py
@@ -3,7 +3,9 @@
import os
import binascii
+import logging
from odoo import models, api, fields
+_logger = logging.getLogger(__name__)
class ChannelBackend(models.Model):
@@ -241,6 +243,40 @@ class ChannelBackend(models.Model):
title="Export Restrictions")
return True
+ @api.multi
+ def channel_availability_watchdog(self):
+ # search all availability to the future TODO: It not prepared for multiple backends
+ availabilities = self.env['hotel.room.type.availability'].search([
+ ('date', '>=', fields.Date.today())
+ ])
+ email_values = {'body_html': ''}
+ for record in availabilities:
+ room_type_id = record.room_type_id.id
+ date = record.date
+ free_rooms = len(self.env['hotel.room.type'].check_availability_room_type(date, date, room_type_id))
+ channel_avail = availabilities.filtered(
+ lambda r: r.room_type_id.id == room_type_id and r.date == date).channel_bind_ids.channel_avail
+ if free_rooms < channel_avail:
+ # the channel binding availability listener will update this record as 'channel_pushed': False
+ record.channel_bind_ids.update({
+ 'channel_avail': free_rooms,
+ })
+ msg = "Channel availability mismatch for room type %s." % self.env['hotel.room.type'].browse(
+ room_type_id).name
+ msg = msg + " " + "Free [%s] :: Channel [%s] on %s." % (free_rooms, channel_avail, date)
+ _logger.warning(msg)
+
+ email_values.update({'body_html': email_values['body_html'] + msg + '
'})
+
+ if len(email_values['body_html']) > 0:
+ template = self.env.ref('hotel_channel_connector.mail_template_hotel_availability_watchdog')
+ email_values.update({'email_to': self._context['email_to']})
+ template.send_mail(self.id, email_values=email_values)
+ # push availability on demand
+ self.with_context({'show_notify': False}).push_availability()
+
+ return True
+
@api.model
def cron_push_changes(self):
backends = self.env[self._name].search([])
@@ -252,8 +288,12 @@ class ChannelBackend(models.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()
+
+ @api.model
+ def cron_channel_availability_watchdog(self):
+ backends = self.env[self._name].search([])
+ backends.channel_availability_watchdog()
\ No newline at end of file