From 233735bb48869b49fc7360482f2afacfc51932cc Mon Sep 17 00:00:00 2001 From: QS5ELkMu Date: Fri, 9 Nov 2018 20:10:18 +0100 Subject: [PATCH 1/8] [IMP] Adapt to hotel changes --- hotel_calendar/models/bus_hotel_calendar.py | 1 - .../models/hotel_calendar_management.py | 28 ++++++-------- .../inherited_hotel_room_type_availability.py | 38 +++++++++---------- .../views/hotel_calendar_management_views.xml | 2 +- .../views/hotel_reservation_views.xml | 2 +- .../views/inherited_hotel_room_type_views.xml | 2 +- .../views/inherited_hotel_room_views.xml | 4 +- .../views/inherited_res_users_views.xml | 2 +- hotel_calendar/views/res_config_views.xml | 2 +- .../views/room_pricelist_cached_views.xml | 4 +- .../models/inherited_bus_hotel_calendar.py | 24 +++++++----- .../inherited_hotel_calendar_management.py | 15 +++++++- .../views/hotel_reservation.xml | 4 +- .../hotel_room_type_availability/common.py | 12 +++++- .../views/channel_connector_backend_views.xml | 4 +- .../views/channel_hotel_reservation_views.xml | 2 +- ...nel_hotel_room_type_availability_views.xml | 8 +++- ...hotel_room_type_restriction_item_views.xml | 4 +- ...nnel_hotel_room_type_restriction_views.xml | 4 +- .../views/channel_hotel_room_type_views.xml | 4 +- .../views/channel_ota_info_views.xml | 4 +- .../channel_product_pricelist_item_views.xml | 4 +- .../views/channel_product_pricelist_views.xml | 4 +- .../inherited_hotel_reservation_views.xml | 12 +++--- ...hotel_room_type_restriction_item_views.xml | 2 +- ...ited_hotel_room_type_restriction_views.xml | 2 +- .../views/inherited_hotel_room_type_views.xml | 2 +- .../inherited_product_pricelist_views.xml | 2 +- .../views/inherited_res_partner_views.xml | 2 +- 29 files changed, 111 insertions(+), 89 deletions(-) diff --git a/hotel_calendar/models/bus_hotel_calendar.py b/hotel_calendar/models/bus_hotel_calendar.py index 9314f95ed..8928cce33 100644 --- a/hotel_calendar/models/bus_hotel_calendar.py +++ b/hotel_calendar/models/bus_hotel_calendar.py @@ -113,7 +113,6 @@ class BusHotelCalendar(models.TransientModel): vals['room_type_id']: { date_dt.strftime("%d/%m/%Y"): [ vals['avail'], - vals['no_ota'], vals['id'], ], }, diff --git a/hotel_calendar/models/hotel_calendar_management.py b/hotel_calendar/models/hotel_calendar_management.py index 523162ca7..72c71f54d 100644 --- a/hotel_calendar/models/hotel_calendar_management.py +++ b/hotel_calendar/models/hotel_calendar_management.py @@ -40,7 +40,6 @@ class HotelCalendarManagement(models.TransientModel): avail['date'], avail['date'], room_type_id=room_type.id)) ravail = min(cavail, room_type.total_rooms_count, int(avail['avail'])) vals = { - 'no_ota': avail['no_ota'], 'avail': ravail, } return vals @@ -170,11 +169,20 @@ class HotelCalendarManagement(models.TransientModel): }) return json_data + @api.model + def _generate_avalaibility_data(self, room_type, date, avail): + return { + 'id': avail and avail.id or False, + 'date': avail and avail.date or date, + 'avail': avail and avail.avail or room_type.total_rooms_count, + } + @api.model def _hcalendar_availability_json_data(self, dfrom, dto): date_start = fields.Date.from_string(dfrom) date_end = fields.Date.from_string(dto) date_diff = abs((date_end - date_start).days) + 1 + hotel_room_type_avail_obj = self.env['hotel.room.type.availability'] room_types = self.env['hotel.room.type'].search([]) json_data = {} @@ -183,24 +191,12 @@ class HotelCalendarManagement(models.TransientModel): for i in range(0, date_diff): cur_date = date_start + timedelta(days=i) cur_date_str = cur_date.strftime(DEFAULT_SERVER_DATE_FORMAT) - avail = self.env['hotel.room.type.availability'].search([ + avail = hotel_room_type_avail_obj.search([ ('date', '=', cur_date_str), ('room_type_id', '=', room_type.id) ]) - if avail: - json_data[room_type.id].append({ - 'id': avail.id, - 'date': avail.date, - 'avail': avail.avail, - 'no_ota': avail.no_ota, - }) - else: - json_data[room_type.id].append({ - 'id': False, - 'date': cur_date_str, - 'avail': room_type.total_rooms_count, - 'no_ota': False, - }) + json_data[room_type.id].append( + self._generate_avalaibility_data(room_type, cur_date_str, avail)) return json_data @api.model diff --git a/hotel_calendar/models/inherited_hotel_room_type_availability.py b/hotel_calendar/models/inherited_hotel_room_type_availability.py index 4a001c4a9..edca3a8e8 100644 --- a/hotel_calendar/models/inherited_hotel_room_type_availability.py +++ b/hotel_calendar/models/inherited_hotel_room_type_availability.py @@ -6,16 +6,20 @@ from odoo import models, fields, api class HotelRoomTypeAvailability(models.Model): _inherit = 'hotel.room.type.availability' + def _prepare_notif_values(self, record): + return { + 'date': record.date, + 'avail': record.avail, + 'room_type_id': record.room_type_id.id, + 'id': record.id, + } + @api.model def create(self, vals): res = super(HotelRoomTypeAvailability, self).create(vals) - self.env['bus.hotel.calendar'].send_availability_notification({ - 'date': res.date, - 'avail': res.avail, - 'no_ota': res.no_ota, - 'room_type_id': res.room_type_id.id, - 'id': res.id, - }) + self.env['bus.hotel.calendar'].send_availability_notification( + self._prepare_notif_values(res) + ) return res @api.multi @@ -23,13 +27,9 @@ class HotelRoomTypeAvailability(models.Model): ret_vals = super(HotelRoomTypeAvailability, self).write(vals) bus_hotel_calendar_obj = self.env['bus.hotel.calendar'] for record in self: - bus_hotel_calendar_obj.send_availability_notification({ - 'date': record.date, - 'avail': record.avail, - 'no_ota': record.no_ota, - 'room_type_id': record.room_type_id.id, - 'id': record.id, - }) + bus_hotel_calendar_obj.send_availability_notification( + self._prepare_notif_values(record) + ) return ret_vals @api.multi @@ -37,13 +37,9 @@ class HotelRoomTypeAvailability(models.Model): # Construct dictionary with relevant info of removed records unlink_vals = [] for record in self: - unlink_vals.append({ - 'date': record.date, - 'avail': record.room_type_id.total_rooms_count, - 'room_type_id': record.room_type_id.id, - 'no_ota': False, - 'id': record.id, - }) + unlink_vals.append( + self._prepare_notif_values(record) + ) res = super(HotelRoomTypeAvailability, self).unlink() bus_hotel_calendar_obj = self.env['bus.hotel.calendar'] for uval in unlink_vals: diff --git a/hotel_calendar/views/hotel_calendar_management_views.xml b/hotel_calendar/views/hotel_calendar_management_views.xml index da3c3aef3..6d12c3abb 100644 --- a/hotel_calendar/views/hotel_calendar_management_views.xml +++ b/hotel_calendar/views/hotel_calendar_management_views.xml @@ -1,7 +1,7 @@ - + hotel.calendar.management.mpms hotel.calendar.management diff --git a/hotel_calendar/views/hotel_reservation_views.xml b/hotel_calendar/views/hotel_reservation_views.xml index f07778c81..6c32e0a8b 100644 --- a/hotel_calendar/views/hotel_reservation_views.xml +++ b/hotel_calendar/views/hotel_reservation_views.xml @@ -1,7 +1,7 @@ - + hotel.reservation.pms hotel.reservation diff --git a/hotel_calendar/views/inherited_hotel_room_type_views.xml b/hotel_calendar/views/inherited_hotel_room_type_views.xml index e508524a3..9726a0d71 100644 --- a/hotel_calendar/views/inherited_hotel_room_type_views.xml +++ b/hotel_calendar/views/inherited_hotel_room_type_views.xml @@ -3,7 +3,7 @@ hotel.room.type - + diff --git a/hotel_calendar/views/inherited_hotel_room_views.xml b/hotel_calendar/views/inherited_hotel_room_views.xml index c0198d112..3d84684cb 100644 --- a/hotel_calendar/views/inherited_hotel_room_views.xml +++ b/hotel_calendar/views/inherited_hotel_room_views.xml @@ -1,9 +1,9 @@ - + hotel.room - + diff --git a/hotel_calendar/views/inherited_res_users_views.xml b/hotel_calendar/views/inherited_res_users_views.xml index 0d94cd57a..074265932 100644 --- a/hotel_calendar/views/inherited_res_users_views.xml +++ b/hotel_calendar/views/inherited_res_users_views.xml @@ -1,7 +1,7 @@ - + res.users diff --git a/hotel_calendar/views/res_config_views.xml b/hotel_calendar/views/res_config_views.xml index 0047838ad..d79b2bbcb 100644 --- a/hotel_calendar/views/res_config_views.xml +++ b/hotel_calendar/views/res_config_views.xml @@ -2,7 +2,7 @@ - + res.config.settings.view.form.inherit.hotel res.config.settings diff --git a/hotel_calendar/views/room_pricelist_cached_views.xml b/hotel_calendar/views/room_pricelist_cached_views.xml index 0ed327c7c..9ff9d3348 100644 --- a/hotel_calendar/views/room_pricelist_cached_views.xml +++ b/hotel_calendar/views/room_pricelist_cached_views.xml @@ -2,7 +2,7 @@ - + hotel.room.pricelist.cached.form room.pricelist.cached @@ -19,7 +19,7 @@ - + hotel.room.pricelist.cached.tree room.pricelist.cached diff --git a/hotel_calendar_channel_connector/models/inherited_bus_hotel_calendar.py b/hotel_calendar_channel_connector/models/inherited_bus_hotel_calendar.py index f3bc09eac..940fdc5fc 100644 --- a/hotel_calendar_channel_connector/models/inherited_bus_hotel_calendar.py +++ b/hotel_calendar_channel_connector/models/inherited_bus_hotel_calendar.py @@ -1,8 +1,8 @@ # Copyright 2018 Alexandre Díaz # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from datetime import datetime -from openerp.tools import DEFAULT_SERVER_DATE_FORMAT -from openerp import models, api +from odoo.tools import DEFAULT_SERVER_DATE_FORMAT +from odoo import models, api from odoo.addons.hotel_calendar.controllers.bus import HOTEL_BUS_CHANNEL_ID @@ -30,15 +30,21 @@ class BusHotelCalendar(models.TransientModel): def _generate_reservation_notif(self, vals): json = super(BusHotelCalendar, self)._generate_reservation_notif(vals) json['reservation'].update({ - 'wrid': vals['wrid'], + 'external_id': vals['external_id'], }) return json @api.model - def send_issue_notification(self, ntype, title, issue_id, section, - message): - notif = self._generate_issue_notification(ntype, title, issue_id, - section, message) + def _generate_availability_notification(self, vals): + date_dt = datetime.strptime(vals['date'], DEFAULT_SERVER_DATE_FORMAT) + json = super(BusHotelCalendar, self)._generate_availability_notification(vals) + json['availability'][vals['room_type_id']][date_dt.strftime("%d/%m/%Y")].append( + vals['no_ota']) + return json + + @api.model + def send_issue_notification(self, ntype, title, issue_id, section, message): + notif = self._generate_issue_notification(ntype, title, issue_id, section, message) self.env['bus.bus'].sendone( - (self._cr.dbname, 'hotel.reservation', - HOTEL_BUS_CHANNEL_ID), notif) + (self._cr.dbname, 'hotel.reservation', + HOTEL_BUS_CHANNEL_ID), notif) diff --git a/hotel_calendar_channel_connector/models/inherited_hotel_calendar_management.py b/hotel_calendar_channel_connector/models/inherited_hotel_calendar_management.py index 969076aa9..4ff07ee0f 100644 --- a/hotel_calendar_channel_connector/models/inherited_hotel_calendar_management.py +++ b/hotel_calendar_channel_connector/models/inherited_hotel_calendar_management.py @@ -10,7 +10,20 @@ class HotelCalendarManagement(models.TransientModel): def _get_availability_values(self, avail, room_type): vals = super(HotelCalendarManagement, self)._get_availability_values( avail, room_type) - vals.update({'wmax_avail': vals['avail']}) + vals.update({ + 'wmax_avail': vals['avail'], + 'no_ota': vals['no_ota'], + 'booked': vals['booked'], + }) + return vals + + @api.model + def _generate_avalaibility_data(self, room_type, date, avail): + vals = super(HotelCalendarManagement, self)._generate_avalaibility_data( + room_type, date, avail) + vals.update({ + 'no_ota': avail and avail.no_ota or False, + }) return vals @api.multi diff --git a/hotel_calendar_channel_connector/views/hotel_reservation.xml b/hotel_calendar_channel_connector/views/hotel_reservation.xml index 981f0ba31..42011bdef 100644 --- a/hotel_calendar_channel_connector/views/hotel_reservation.xml +++ b/hotel_calendar_channel_connector/views/hotel_reservation.xml @@ -3,7 +3,7 @@ - + hotel.toassign.reservation.tree hotel.reservation @@ -68,7 +68,7 @@ hotel.reservation - +