From bda76b216dc8e0cb54507ffbbca4a7d60362fdf7 Mon Sep 17 00:00:00 2001 From: QS5ELkMu Date: Sat, 15 Dec 2018 21:57:48 +0100 Subject: [PATCH] [IMP] Refactor Code --- hotel_calendar/models/bus_hotel_calendar.py | 29 ++-- .../models/inherited_hotel_reservation.py | 138 +++++++++--------- .../calendar/hotel_calendar_controller.js | 113 ++++++-------- .../static/src/js/widgets/MultiCalendar.js | 10 +- .../src/lib/hcalendar/css/hcalendar.css | 2 +- .../models/inherited_bus_hotel_calendar.py | 8 - .../models/inherited_hotel_reservation.py | 101 ++----------- .../src/js/views/hotel_calendar_controller.js | 6 + .../src/js/views/hotel_calendar_renderer.js | 6 - .../src/xml/hotel_calendar_templates.xml | 2 +- .../models/hotel_reservation/common.py | 33 ++--- 11 files changed, 174 insertions(+), 274 deletions(-) diff --git a/hotel_calendar/models/bus_hotel_calendar.py b/hotel_calendar/models/bus_hotel_calendar.py index 9fe5519a7..36a95166f 100644 --- a/hotel_calendar/models/bus_hotel_calendar.py +++ b/hotel_calendar/models/bus_hotel_calendar.py @@ -40,33 +40,34 @@ class BusHotelCalendar(models.TransientModel): 'userid': user_id.id, 'reservation': { 'room_id': vals['room_id'], - 'reserv_id': vals['reserv_id'], - 'partner_name': vals['partner_name'], + 'id': vals['reserv_id'], + 'name': vals['partner_name'], 'adults': vals['adults'], 'childer': vals['children'], 'checkin': vals['checkin'], 'checkout': vals['checkout'], 'folio_id': vals['folio_id'], - 'reserve_color': vals['reserve_color'], - 'reserve_color_text': vals['reserve_color_text'], + 'bgcolor': vals['reserve_color'], + 'color': vals['reserve_color_text'], 'splitted': vals['splitted'], 'parent_reservation': vals['parent_reservation'], 'room_name': vals['room_name'], 'state': vals['state'], 'only_read': False, 'fix_days': vals['fix_days'], - 'fix_rooms': False, + 'fix_room': False, 'overbooking': vals['overbooking'], + 'real_dates': vals['real_dates'], }, - 'tooltip': [ - vals['partner_name'], - vals['partner_phone'], - vals['checkin'], - num_split, - vals['price'], - vals['reservation_type'] if 'reservation_type' in vals else 'normal', - vals['out_service_description'] if 'out_service_description' in vals else _('No reason given'), - ] + 'tooltip': { + 'name': vals['partner_name'], + 'phone': vals['partner_phone'], + 'checkin': vals['checkin'], + 'num_split': num_split, + 'amount_total': vals['amount_total'], + 'type': vals['reservation_type'] if 'reservation_type' in vals else 'normal', + 'out_service_description': vals['out_service_description'] if 'out_service_description' in vals else _('No reason given'), + } } @api.model diff --git a/hotel_calendar/models/inherited_hotel_reservation.py b/hotel_calendar/models/inherited_hotel_reservation.py index 65217f47a..cf1a84ade 100644 --- a/hotel_calendar/models/inherited_hotel_reservation.py +++ b/hotel_calendar/models/inherited_hotel_reservation.py @@ -78,25 +78,25 @@ class HotelReservation(models.Model): json_reservations = [] json_reservation_tooltips = {} for reserv in reservations: - json_reservations.append([ - reserv.room_id.id, - reserv.id, - reserv.folio_id.closure_reason_id.name or _('Out of service') if reserv.folio_id.reservation_type == 'out' - else reserv.folio_id.partner_id.name, - reserv.adults, - reserv.children, - reserv.checkin, - reserv.checkout, - reserv.folio_id.id, - reserv.reserve_color, - reserv.reserve_color_text, - reserv.splitted, - reserv.parent_reservation and reserv.parent_reservation.id - or False, - False, # Read-Only - reserv.splitted, # Fix Days - False, # Fix Rooms - reserv.overbooking]) + json_reservations.append({ + 'room_id': reserv.room_id.id, + 'id': reserv.id, + 'name': reserv.folio_id.closure_reason_id.name or _('Out of service') if reserv.folio_id.reservation_type == 'out' + else reserv.folio_id.partner_id.name, + 'adults': reserv.adults, + 'childrens': reserv.children, + 'checkin': reserv.checkin, + 'checkout': reserv.checkout, + 'folio_id': reserv.folio_id.id, + 'bgcolor': reserv.reserve_color, + 'color': reserv.reserve_color_text, + 'splitted': reserv.splitted, + 'parent_reservation': reserv.parent_reservation and reserv.parent_reservation.id or False, + 'read_only': False, # Read-Only + 'fix_days': reserv.splitted, # Fix Days + 'fix_room': False, # Fix Rooms + 'overbooking': reserv.overbooking, + 'real_dates': reserv.get_real_checkin_checkout()}) num_split = 0 if reserv.splitted: master_reserv = reserv.parent_reservation or reserv @@ -107,16 +107,17 @@ class HotelReservation(models.Model): ('splitted', '=', True), ]) json_reservation_tooltips.update({ - reserv.id: [ - _('Out of service') if reserv.folio_id.reservation_type == 'out' else reserv.folio_id.partner_id.name, - reserv.folio_id.partner_id.mobile or - reserv.folio_id.partner_id.phone or _('Undefined'), - reserv.checkin, - num_split, - reserv.folio_id.amount_total, - reserv.reservation_type or 'normal', - reserv.out_service_description or _('No reason given'), - ] + reserv.id: { + 'name': _('Out of service') if reserv.folio_id.reservation_type == 'out' else reserv.folio_id.partner_id.name, + 'phone': reserv.folio_id.partner_id.mobile or + reserv.folio_id.partner_id.phone or _('Undefined'), + 'checkin': reserv.checkin, + 'num_split': num_split, + 'amount_total': reserv.folio_id.amount_total, + 'type': reserv.reservation_type or 'normal', + 'out_service_description': reserv.out_service_description or + _('No reason given'), + } }) return (json_reservations, json_reservation_tooltips) @@ -163,12 +164,12 @@ class HotelReservation(models.Model): def _hcalendar_event_data(self, events): json_events = [] for event in events: - json_events.append([ - event.id, - event.name, - event.start, - event.location, - ]) + json_events.append({ + 'id': event.id, + 'name': event.name, + 'date': event.start, + 'location': event.location, + }) return json_events @api.model @@ -341,39 +342,46 @@ class HotelReservation(models.Model): return vals + @api.multi + def generate_bus_values(self, naction, ntype, ntitle=''): + self.ensure_one() + return { + 'action': naction, + 'type': ntype, + 'title': ntitle, + 'room_id': self.room_id.id, + 'reserv_id': self.id, + 'partner_name': (self.closure_reason_id.name or _('Out of service')) + if self.reservation_type == 'out' else self.partner_id.name, + 'adults': self.adults, + 'children': self.children, + 'checkin': self.checkin, + 'checkout': self.checkout, + 'folio_id': self.folio_id.id, + 'reserve_color': self.reserve_color, + 'reserve_color_text': self.reserve_color_text, + 'splitted': self.splitted, + 'parent_reservation': self.parent_reservation and + self.parent_reservation.id or 0, + 'room_name': self.room_id.name, + 'partner_phone': self.partner_id.mobile + or self.partner_id.phone or _('Undefined'), + 'state': self.state, + 'fix_days': self.splitted, + 'overbooking': self.overbooking, + 'amount_total': self.folio_id.amount_total, + 'reservation_type': self.reservation_type or 'normal', + 'closure_reason_id': self.closure_reason_id, + 'out_service_description': self.out_service_description or _('No reason given'), + 'real_dates': self.get_real_checkin_checkout(), + } + @api.multi def send_bus_notification(self, naction, ntype, ntitle=''): hotel_cal_obj = self.env['bus.hotel.calendar'] for record in self: - hotel_cal_obj.send_reservation_notification({ - 'action': naction, - 'type': ntype, - 'title': ntitle, - 'room_id': record.room_id.id, - 'reserv_id': record.id, - 'partner_name': (record.closure_reason_id.name or _('Out of service')) - if record.reservation_type == 'out' else record.partner_id.name, - 'adults': record.adults, - 'children': record.children, - 'checkin': record.checkin, - 'checkout': record.checkout, - 'folio_id': record.folio_id.id, - 'reserve_color': record.reserve_color, - 'reserve_color_text': record.reserve_color_text, - 'splitted': record.splitted, - 'parent_reservation': record.parent_reservation and - record.parent_reservation.id or 0, - 'room_name': record.room_id.name, - 'partner_phone': record.partner_id.mobile - or record.partner_id.phone or _('Undefined'), - 'state': record.state, - 'fix_days': record.splitted, - 'overbooking': record.overbooking, - 'price': record.folio_id.amount_total, - 'reservation_type': record.reservation_type, - 'closure_reason_id': record.closure_reason_id, - 'out_service_description': record.out_service_description or _('No reason given'), - }) + hotel_cal_obj.send_reservation_notification( + record.generate_bus_values(naction, ntype, ntitle)) @api.model def swap_reservations(self, fromReservsIds, toReservsIds): @@ -431,9 +439,7 @@ class HotelReservation(models.Model): 'reserve_color' in vals or \ 'reserve_color_text' in vals or 'product_id' in vals or \ 'parent_reservation' in vals or 'overbooking' in vals: - _logger.info("PASA RESERV WRITE") for record in self: - _logger.info("PASA RESERV WRITE 22") record.send_bus_notification( 'write', (record.state == 'cancelled') and 'warn' or 'notify', diff --git a/hotel_calendar/static/src/js/views/calendar/hotel_calendar_controller.js b/hotel_calendar/static/src/js/views/calendar/hotel_calendar_controller.js index f47da36ba..810398a16 100644 --- a/hotel_calendar/static/src/js/views/calendar/hotel_calendar_controller.js +++ b/hotel_calendar/static/src/js/views/calendar/hotel_calendar_controller.js @@ -19,7 +19,6 @@ var PMSCalendarController = AbstractController.extend({ onLoadCalendarSettings: '_onLoadCalendarSettings', onLoadViewFilters: '_onLoadViewFilters', onUpdateButtonsCounter: '_onUpdateButtonsCounter', - onReloadCalendar: '_onReloadCalendar', onSwapReservations: '_onSwapReservations', onViewAttached: '_onViewAttached', onApplyFilters: '_onApplyFilters', @@ -118,29 +117,13 @@ var PMSCalendarController = AbstractController.extend({ rooms.push(nroom); } - // TODO: Not read this... do the change!! var reservs = []; for (var r of results['reservations']) { - var nreserv = new HReservation({ - 'id': r[1], - 'room_id': r[0], - 'title': r[2], - 'adults': r[3], - 'childrens': r[4], - 'startDate': HotelCalendar.toMomentUTC(r[5], HotelConstants.ODOO_DATETIME_MOMENT_FORMAT), - 'endDate': HotelCalendar.toMomentUTC(r[6], HotelConstants.ODOO_DATETIME_MOMENT_FORMAT), - 'color': r[8], - 'colorText': r[9], - 'splitted': r[10], - 'readOnly': r[12], - 'fixDays': r[13], - 'fixRooms': r[14], - 'unusedZone': false, - 'linkedId': false, - 'overbooking': r[15], + var nreserv = new HReservation(self._generate_reservation_obj_values(r)); + nreserv.addUserData({ + 'folio_id': r['folio_id'], + 'parent_reservation': r['parent_reservation'] }); - nreserv.addUserData({'folio_id': r[7]}); - nreserv.addUserData({'parent_reservation': r[11]}); reservs.push(nreserv); } @@ -210,26 +193,11 @@ var PMSCalendarController = AbstractController.extend({ this.model.get_calendar_data(oparams).then(function(results){ var reservs = []; for (var r of results['reservations']) { - var nreserv = new HReservation({ - 'id': r[1], - 'room_id': r[0], - 'title': r[2], - 'adults': r[3], - 'childrens': r[4], - 'startDate': HotelCalendar.toMomentUTC(r[5], HotelConstants.ODOO_DATETIME_MOMENT_FORMAT), - 'endDate': HotelCalendar.toMomentUTC(r[6], HotelConstants.ODOO_DATETIME_MOMENT_FORMAT), - 'color': r[8], - 'colorText': r[9], - 'splitted': r[10], - 'readOnly': r[12] || false, - 'fixDays': r[13] || false, - 'fixRooms': r[14] || false, - 'unusedZone': false, - 'linkedId': false, - 'overbooking': r[15], + var nreserv = new HReservation(self._generate_reservation_obj_values(r)); + nreserv.addUserData({ + 'folio_id': r['folio_id'], + 'parent_reservation': r['parent_reservation'] }); - nreserv.addUserData({'folio_id': r[7]}); - nreserv.addUserData({'parent_reservation': r[11]}); reservs.push(nreserv); } @@ -659,6 +627,28 @@ var PMSCalendarController = AbstractController.extend({ }); }, + _generate_reservation_obj_values: function(reserv) { + return { + 'id': reserv['id'], + 'room_id': reserv['room_id'], + 'title': reserv['name'], + 'adults': reserv['adults'], + 'childrens': reserv['childrens'], + 'startDate': HotelCalendar.toMomentUTC(reserv['checkin'], HotelConstants.ODOO_DATETIME_MOMENT_FORMAT), + 'endDate': HotelCalendar.toMomentUTC(reserv['checkout'], HotelConstants.ODOO_DATETIME_MOMENT_FORMAT), + 'color': reserv['bgcolor'], + 'colorText': reserv['color'], + 'splitted': reserv['splitted'] || false, + 'readOnly': reserv['read_only'] || false, + 'fixDays': reserv['fix_days'] || false, + 'fixRooms': reserv['fix_room'], + 'unusedZone': false, + 'linkedId': false, + 'overbooking': reserv['overbooking'], + 'realDates': reserv['real_dates'] + } + }, + _onBusNotification: function(notifications) { var need_reload_pricelists = false; var need_update_counters = false; @@ -687,34 +677,17 @@ var PMSCalendarController = AbstractController.extend({ // Create/Update/Delete reservation if (notif[1]['action'] === 'unlink' || reserv['state'] === 'cancelled') { - this._multi_calendar.remove_reservation(reserv['reserv_id']); - this._multi_calendar._reserv_tooltips = _.pick(this._multi_calendar._reserv_tooltips, function(value, key, obj){ return key != reserv['reserv_id']; }); - nreservs = _.reject(nreservs, function(item){ return item.id == reserv['reserv_id']; }); + this._multi_calendar.remove_reservation(reserv['id']); + this._multi_calendar._reserv_tooltips = _.pick(this._multi_calendar._reserv_tooltips, function(value, key, obj){ return key != reserv['id']; }); + nreservs = _.reject(nreservs, function(item){ return item.id == reserv['id']; }); } else { - nreservs = _.reject(nreservs, {'id': reserv['reserv_id']}); // Only like last changes - var nreserv = new HReservation({ - 'id': reserv['reserv_id'], - 'room_id': reserv['room_id'], - 'title': reserv['partner_name'], - 'adults': reserv['adults'], - 'childrens': reserv['children'], - 'startDate': HotelCalendar.toMomentUTC(reserv['checkin'], HotelConstants.ODOO_DATETIME_MOMENT_FORMAT), - 'endDate': HotelCalendar.toMomentUTC(reserv['checkout'], HotelConstants.ODOO_DATETIME_MOMENT_FORMAT), - 'color': reserv['reserve_color'], - 'colorText': reserv['reserve_color_text'], - 'splitted': reserv['splitted'], - 'readOnly': reserv['read_only'], - 'fixDays': reserv['fix_days'], - 'fixRooms': reserv['fix_rooms'], - 'unusedZone': false, - 'linkedId': false, - 'overbooking': reserv['overbooking'], - }); + nreservs = _.reject(nreservs, {'id': reserv['id']}); // Only like last changes + var nreserv = new HReservation(this._generate_reservation_obj_values(reserv)); nreserv.addUserData({ 'folio_id': reserv['folio_id'], 'parent_reservation': reserv['parent_reservation'], }); - this._multi_calendar._reserv_tooltips[reserv['reserv_id']] = notif[1]['tooltip']; + this._multi_calendar._reserv_tooltips[reserv['id']] = notif[1]['tooltip']; nreservs.push(nreserv); } need_update_counters = true; @@ -761,13 +734,13 @@ var PMSCalendarController = AbstractController.extend({ _generate_reservation_tooltip_dict: function(tp) { return { - 'name': tp[0], - 'phone': tp[1], - 'arrival_hour': HotelCalendar.toMomentUTC(tp[2], HotelConstants.ODOO_DATETIME_MOMENT_FORMAT).local().format('HH:mm'), - 'num_split': tp[3], - 'amount_total': Number(tp[4]).toLocaleString(), - 'reservation_type': tp[5], - 'out_service_description': tp[6] + 'name': tp['name'], + 'phone': tp['phone'], + 'arrival_hour': HotelCalendar.toMomentUTC(tp['checkin'], HotelConstants.ODOO_DATETIME_MOMENT_FORMAT).local().format('HH:mm'), + 'num_split': tp['num_split'], + 'amount_total': Number(tp['amount_total']).toLocaleString(), + 'reservation_type': tp['type'], + 'out_service_description': tp['out_service_description'] }; }, diff --git a/hotel_calendar/static/src/js/widgets/MultiCalendar.js b/hotel_calendar/static/src/js/widgets/MultiCalendar.js index 9f65bec65..c946a8f4b 100644 --- a/hotel_calendar/static/src/js/widgets/MultiCalendar.js +++ b/hotel_calendar/static/src/js/widgets/MultiCalendar.js @@ -214,7 +214,7 @@ odoo.define('hotel_calendar.MultiCalendar', function(require) { merge_days_tooltips: function(new_tooltips) { for (var nt of new_tooltips) { - var fnt = _.find(this._days_tooltips, function(item) { return item[0] === nt[0]}); + var fnt = _.find(this._days_tooltips, function(item) { return item['id'] === nt['id']}); if (fnt) { fnt = nt; } else { @@ -347,7 +347,7 @@ odoo.define('hotel_calendar.MultiCalendar', function(require) { var $elm = $(elm); var cdate = HotelCalendar.toMoment($elm.data('hcalDate'), HotelConstants.L10N_DATE_MOMENT_FORMAT); var data = _.filter(self._days_tooltips, function(item) { - var ndate = HotelCalendar.toMoment(item[2], HotelConstants.ODOO_DATE_MOMENT_FORMAT); + var ndate = HotelCalendar.toMoment(item['date'], HotelConstants.ODOO_DATE_MOMENT_FORMAT); return ndate.isSame(cdate, 'd'); }); if (data.length > 0) { @@ -360,9 +360,9 @@ odoo.define('hotel_calendar.MultiCalendar', function(require) { 'date': $this.data('hcalDate'), 'events': _.map(data, function(item){ return { - 'name': item[1], - 'date': item[2], - 'location': item[3] + 'name': item['name'], + 'date': item['date'], + 'location': item['location'] }; }) }; diff --git a/hotel_calendar/static/src/lib/hcalendar/css/hcalendar.css b/hotel_calendar/static/src/lib/hcalendar/css/hcalendar.css index 8aa8a192e..6ce765777 100644 --- a/hotel_calendar/static/src/lib/hcalendar/css/hcalendar.css +++ b/hotel_calendar/static/src/lib/hcalendar/css/hcalendar.css @@ -313,7 +313,7 @@ } .hcal-reservation-splitted { - border-width: 1px 6px; + border-width: 0 6px; border-style: solid; } 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 940fdc5fc..025fccbed 100644 --- a/hotel_calendar_channel_connector/models/inherited_bus_hotel_calendar.py +++ b/hotel_calendar_channel_connector/models/inherited_bus_hotel_calendar.py @@ -26,14 +26,6 @@ class BusHotelCalendar(models.TransientModel): }, } - @api.model - def _generate_reservation_notif(self, vals): - json = super(BusHotelCalendar, self)._generate_reservation_notif(vals) - json['reservation'].update({ - 'external_id': vals['external_id'], - }) - return json - @api.model def _generate_availability_notification(self, vals): date_dt = datetime.strptime(vals['date'], DEFAULT_SERVER_DATE_FORMAT) diff --git a/hotel_calendar_channel_connector/models/inherited_hotel_reservation.py b/hotel_calendar_channel_connector/models/inherited_hotel_reservation.py index fd211b699..318747ba0 100644 --- a/hotel_calendar_channel_connector/models/inherited_hotel_reservation.py +++ b/hotel_calendar_channel_connector/models/inherited_hotel_reservation.py @@ -1,106 +1,35 @@ # Copyright 2018 Alexandre Díaz # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). import logging -from datetime import datetime, timedelta -from odoo import models, fields, api, _ -from odoo.tools import ( - DEFAULT_SERVER_DATE_FORMAT, - DEFAULT_SERVER_DATETIME_FORMAT) +from odoo import models, api _logger = logging.getLogger(__name__) class HotelReservation(models.Model): _inherit = "hotel.reservation" - @api.model - def _generate_reservation_notif(self, action, ntype, title, - id, reserv_id, partner_name, - adults, children, checkin, checkout, - folio_id, color, color_text, splitted, - parent_reservation, room_name, - partner_phone, state, fix_days): - vals = super(HotelReservation, self)._generate_reservation_notif( - action, ntype, title, id, - reserv_id, partner_name, adults, - children, checkin, checkout, - folio_id, color, color_text, splitted, parent_reservation, - room_name, partner_phone, state, fix_days) - reserv = self.env['hotel.reservation'].browse(vals['reserv_id']) - vals['reservation'].update({ - 'fix_days': (any(reserv.channel_bind_ids) and - reserv.channel_bind_ids[0].external_id) or fix_days, - 'ota_id': (any(reserv.channel_bind_ids) and - reserv.channel_bind_ids[0].ota_id and - reserv.channel_bind_ids[0].ota_id.name), - }) - return vals - @api.multi def _hcalendar_reservation_data(self, reservations): vals = super(HotelReservation, self)._hcalendar_reservation_data(reservations) hotel_reservation_obj = self.env['hotel.reservation'] - json_reservations = [] for v_rval in vals[0]: - reserv = hotel_reservation_obj.browse(v_rval[1]) - json_reservations.append(( - reserv.room_id.id, - reserv.id, - reserv.folio_id.partner_id.name, - reserv.adults, - reserv.children, - reserv.checkin, - reserv.checkout, - reserv.folio_id.id, - reserv.reserve_color, - reserv.reserve_color_text, - reserv.splitted, - reserv.parent_reservation.id, - # Read-Only - False, - # Fix Days - (any(reserv.channel_bind_ids) and - reserv.channel_bind_ids[0].external_id) or reserv.splitted, - # Fix Rooms - False, - reserv.overbooking)) + reserv = hotel_reservation_obj.browse(v_rval['id']) + v_rval.update({ + 'fix_days': reserv.splitted or reserv.is_from_ota, + }) # Update tooltips - if any(reserv.channel_bind_ids): - vals[1][reserv.id].append(reserv.channel_bind_ids[0].ota_id.name) - else: - vals[1][reserv.id].append(False) - return (json_reservations, vals[1]) + vals[1][reserv.id].update({ + 'ota_name': reserv.channel_bind_ids[0].ota_id.name if any(reserv.channel_bind_ids) else False + }) + return vals @api.multi - def send_bus_notification(self, naction, ntype, ntitle=''): - hotel_cal_obj = self.env['bus.hotel.calendar'] - for record in self: - hotel_cal_obj.send_reservation_notification({ - 'action': naction, - 'type': ntype, - 'title': ntitle, - 'room_id': record.room_id.id, - 'reserv_id': record.id, - 'partner_name': record.partner_id.name, - 'adults': record.adults, - 'children': record.children, - 'checkin': record.checkin, - 'checkout': record.checkout, - 'folio_id': record.folio_id.id, - 'reserve_color': record.reserve_color, - 'reserve_color_text': record.reserve_color_text, - 'splitted': record.splitted, - 'parent_reservation': record.parent_reservation and - record.parent_reservation.id or 0, - 'room_name': record.room_id.name, - 'partner_phone': record.partner_id.mobile or - record.partner_id.phone or _('Undefined'), - 'state': record.state, - 'fix_days': record.splitted or record.is_from_ota, - 'overbooking': record.overbooking, - 'price': record.folio_id.amount_total, - 'external_id': (any(record.channel_bind_ids) and - record.channel_bind_ids[0].external_id), - }) + def generate_bus_values(self, naction, ntype, ntitle=''): + vals = super(HotelReservation, self).generate_bus_values(naction, ntype, ntitle) + vals.update({ + 'fix_days': self.splitted or self.is_from_ota, + }) + return vals @api.multi def confirm(self): diff --git a/hotel_calendar_channel_connector/static/src/js/views/hotel_calendar_controller.js b/hotel_calendar_channel_connector/static/src/js/views/hotel_calendar_controller.js index da3f84e30..4bcca6cc0 100644 --- a/hotel_calendar_channel_connector/static/src/js/views/hotel_calendar_controller.js +++ b/hotel_calendar_channel_connector/static/src/js/views/hotel_calendar_controller.js @@ -31,6 +31,12 @@ var PMSHotelCalendarControllerChannelConnector = PMSCalendarController.include({ this._sounds[SoundID].play(); }, + _generate_reservation_tooltip_dict: function(tp) { + var qdict = this._super(tp); + qdict['ota_name'] = tp['ota_name']; + return qdict; + }, + //-------------------------------------------------------------------------- // Handlers //-------------------------------------------------------------------------- diff --git a/hotel_calendar_channel_connector/static/src/js/views/hotel_calendar_renderer.js b/hotel_calendar_channel_connector/static/src/js/views/hotel_calendar_renderer.js index d3892ed69..1a0d63ea4 100644 --- a/hotel_calendar_channel_connector/static/src/js/views/hotel_calendar_renderer.js +++ b/hotel_calendar_channel_connector/static/src/js/views/hotel_calendar_renderer.js @@ -38,12 +38,6 @@ odoo.define('hotel_calendar_channel_connector.PMSHotelCalendarRendererChannelCon }); }, - _generate_reservation_tooltip_dict: function(tp) { - var qdict = this._super(tp); - qdict['channel_name'] = tp[5]; - return qdict; - }, - _generate_bookings_domain: function(tsearch) { var domain = this._super(tsearch); domain.splice(0, 0, '|'); diff --git a/hotel_calendar_channel_connector/static/src/xml/hotel_calendar_templates.xml b/hotel_calendar_channel_connector/static/src/xml/hotel_calendar_templates.xml index f03900f73..e4382ec4e 100644 --- a/hotel_calendar_channel_connector/static/src/xml/hotel_calendar_templates.xml +++ b/hotel_calendar_channel_connector/static/src/xml/hotel_calendar_templates.xml @@ -7,7 +7,7 @@ -
  • Channel:
  • +
  • OTA:
  • diff --git a/hotel_channel_connector/models/hotel_reservation/common.py b/hotel_channel_connector/models/hotel_reservation/common.py index 68bff4ecc..b362714d0 100644 --- a/hotel_channel_connector/models/hotel_reservation/common.py +++ b/hotel_channel_connector/models/hotel_reservation/common.py @@ -180,21 +180,20 @@ class HotelReservation(models.Model): vals.update({'to_read': True}) return super(HotelReservation, self).create(vals) - # @api.multi - # def generate_copy_values(self, checkin=False, checkout=False): - # self.ensure_one() - # res = super().generate_copy_values(checkin=checkin, checkout=checkout) - # res.update({ - # 'channel_reservation_id': self.channel_reservation_id, - # 'ota_id': self.ota_id and self.ota_id.id or False, - # 'ota_reservation_code': self.ota_reservation_code, - # 'is_from_ota': self.is_from_ota, - # 'to_read': self.to_read, - # 'wstatus': self.wstatus, - # 'wstatus_reason': self.wstatus_reason, - # 'customer_notes': self.customer_notes, - # }) - # return res + @api.multi + def generate_copy_values(self, checkin=False, checkout=False): + self.ensure_one() + res = super().generate_copy_values(checkin=checkin, checkout=checkout) + commands = [] + for bind_id in self.channel_bind_ids.ids: + commands.append((4, bind_id, False)) + res.update({ + 'channel_bind_ids': commands, + 'customer_notes': self.customer_notes, + 'is_from_ota': self.is_from_ota, + 'to_read': self.to_read, + }) + return res @api.multi def action_reservation_checkout(self): @@ -208,8 +207,8 @@ class HotelReservation(models.Model): reserv_obj = self.env['hotel.reservation'] for reserv in json_reservs: - reservation = reserv_obj.browse(reserv[1]) - reserv[13] = reservation.splitted or reservation.is_from_ota + reservation = reserv_obj.browse(reserv['id']) + reserv['fix_days'] = reservation.splitted or reservation.is_from_ota return (json_reservs, json_tooltips)