[ADD] Channel availability Watchdog

This commit is contained in:
Pablo
2019-06-14 17:57:07 +02:00
parent dacd8773ac
commit 56ddc1848e
5 changed files with 74 additions and 2 deletions

View File

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

View File

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

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<!-- Scheduler For Watchdog Free Rooms and Channel Availability -->
<record model="ir.cron" id="channel_availability_watchdog">
<field name="name">Watchdog Free Rooms and Channel Availability</field>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field name="nextcall" eval="(DateTime.now() + timedelta(days=1)).strftime('%Y-%m-%d 03:00:00')"/>
<field name="doall" eval="False" />
<field name="model_id" ref="model_channel_backend" />
<field name="state">code</field>
<field name="code">model.with_context({'email_to': 'watchdog@roomdoo.com'}).cron_channel_availability_watchdog()</field>
</record>
</data>
</odoo>

View File

@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<odoo>
<data noupdate="1">
<!-- Email Template For Channel Availability Watchdog -->
<record id="mail_template_hotel_availability_watchdog" model="mail.template">
<field name="name">Channel Availability Watchdog by Email</field>
<field name="subject">Channel availability mismatch ${object.username}</field>
<field name="model_id" ref="hotel_channel_connector.model_channel_backend"/>
<field name="auto_delete" eval="False" />
<field name="body_html">Channel Availability Watchdog by Email</field>
</record>
</data>
</odoo>

View File

@@ -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 + '<br/>'})
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()