From 9bcc9bde479438d8f11c365d4592015d5cb89b47 Mon Sep 17 00:00:00 2001 From: QS5ELkMu Date: Wed, 5 Dec 2018 19:02:53 +0100 Subject: [PATCH] [IMP] Channel Connector --- hotel_calendar/__manifest__.py | 1 + hotel_calendar/data/menus.xml | 5 +++ hotel_calendar/models/__init__.py | 1 + hotel_calendar/models/hotel_calendar.py | 15 +++++++ .../models/hotel_calendar_management.py | 14 +++--- .../models/inherited_hotel_reservation.py | 27 ++++++------ ...erited_hotel_room_type_restriction_item.py | 8 ---- hotel_calendar/security/ir.model.access.csv | 1 + .../calendar/hotel_calendar_controller.js | 25 ++++++----- .../js/views/calendar/hotel_calendar_model.js | 4 +- .../views/calendar/hotel_calendar_renderer.js | 3 +- .../hotel_calendar_management_controller.js | 8 ++-- .../static/src/lib/hcalendar/js/hcalendar.js | 39 ++++++++-------- hotel_calendar/views/actions.xml | 7 +++ hotel_calendar/views/hotel_calendar_views.xml | 36 +++++++++++++++ .../views/hotel_reservation.xml | 3 +- .../models/hotel_reservation/common.py | 35 ++++++++------- .../models/hotel_room_type/common.py | 7 ++- .../hotel_room_type_restriction/common.py | 18 ++++---- .../common.py | 20 +++++++++ .../models/inherited_hotel_room_type_class.py | 25 +++++++++++ .../models/product_pricelist/common.py | 20 ++++----- .../models/product_pricelist_item/common.py | 17 +++++++ .../views/inherited_hotel_folio_views.xml | 4 +- .../inherited_hotel_reservation_views.xml | 10 ++--- .../__manifest__.py | 1 + .../components/backend_adapter.py | 18 ++++---- .../data/records.xml | 44 +++++++++++++++++++ .../models/__init__.py | 1 + .../models/channel_backend/common.py | 2 +- .../models/hotel_reservation/common.py | 39 +++++++--------- .../models/hotel_room_type/exporter.py | 12 +++-- .../models/hotel_room_type/importer.py | 11 +++++ .../hotel_room_type_availability/exporter.py | 7 ++- .../exporter.py | 8 +++- .../importer.py | 14 ++++-- .../models/inherited_hotel_room_type_class.py | 25 +++++++++++ 37 files changed, 378 insertions(+), 157 deletions(-) create mode 100644 hotel_calendar/models/hotel_calendar.py create mode 100644 hotel_calendar/views/hotel_calendar_views.xml create mode 100644 hotel_channel_connector/models/inherited_hotel_room_type_class.py create mode 100644 hotel_channel_connector_wubook/data/records.xml create mode 100644 hotel_channel_connector_wubook/models/inherited_hotel_room_type_class.py diff --git a/hotel_calendar/__manifest__.py b/hotel_calendar/__manifest__.py index 5a0b0ec24..e8577a3db 100644 --- a/hotel_calendar/__manifest__.py +++ b/hotel_calendar/__manifest__.py @@ -28,6 +28,7 @@ 'views/room_pricelist_cached_views.xml', 'views/hotel_reservation_views.xml', 'views/hotel_calendar_management_views.xml', + 'views/hotel_calendar_views.xml', 'data/menus.xml', 'security/ir.model.access.csv', ], diff --git a/hotel_calendar/data/menus.xml b/hotel_calendar/data/menus.xml index 1c440156d..6ef1e3d96 100644 --- a/hotel_calendar/data/menus.xml +++ b/hotel_calendar/data/menus.xml @@ -25,4 +25,9 @@ + + diff --git a/hotel_calendar/models/__init__.py b/hotel_calendar/models/__init__.py index ab6021fe4..7aa6dfff6 100644 --- a/hotel_calendar/models/__init__.py +++ b/hotel_calendar/models/__init__.py @@ -1,5 +1,6 @@ # Copyright 2018 Alexandre Díaz # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from . import hotel_calendar from . import bus_hotel_calendar from . import room_pricelist_cached from . import hotel_calendar_management diff --git a/hotel_calendar/models/hotel_calendar.py b/hotel_calendar/models/hotel_calendar.py new file mode 100644 index 000000000..6adfdea37 --- /dev/null +++ b/hotel_calendar/models/hotel_calendar.py @@ -0,0 +1,15 @@ +# Copyright 2018 Alexandre Díaz +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models, api, _, fields +from odoo.exceptions import ValidationError + + +class HotelCalendar(models.Model): + _name = 'hotel.calendar' + + name = fields.Char('Name', required=True) + segmentation_ids = fields.Many2many('hotel.room.type.class', string='Segmentation') + location_ids = fields.Many2many('hotel.floor', string='Location') + amenity_ids = fields.Many2many('hotel.amenity', string='Amenity') + room_type_ids = fields.Many2many('hotel.room.type', string='Room Type') diff --git a/hotel_calendar/models/hotel_calendar_management.py b/hotel_calendar/models/hotel_calendar_management.py index 2ee906533..cfbf50f47 100644 --- a/hotel_calendar/models/hotel_calendar_management.py +++ b/hotel_calendar/models/hotel_calendar_management.py @@ -122,13 +122,13 @@ class HotelCalendarManagement(models.TransientModel): def _hcalendar_room_json_data(self, rooms): json_data = [] for room in rooms: - json_data.append(( - room.id, - room.name, - room.get_capacity(), - room.list_price, - room.total_rooms_count, - )) + json_data.append({ + 'id': room.id, + 'name': room.name, + 'capacity': room.get_capacity(), + 'price': room.list_price, + 'total_rooms': room.total_rooms_count, + }) return json_data @api.model diff --git a/hotel_calendar/models/inherited_hotel_reservation.py b/hotel_calendar/models/inherited_hotel_reservation.py index cb2baecc9..b7d2c2e85 100644 --- a/hotel_calendar/models/inherited_hotel_reservation.py +++ b/hotel_calendar/models/inherited_hotel_reservation.py @@ -64,19 +64,20 @@ class HotelReservation(models.Model): pricelist_id = int(pricelist_id) json_rooms = [] for room in rooms: - json_rooms.append(( - room.id, - room.name, - room.capacity, - '', # Reserved for type code - room.shared_room, - room.room_type_id - and ['pricelist', room.room_type_id.id, pricelist_id, - room.room_type_id.name] - or 0, - room.room_type_id.name, - room.room_type_id.id, - room.floor_id.id)) + json_rooms.append({ + 'id': room.id, + 'name': room.name, + 'capacity': room.capacity, + 'class_id': room.room_type_id.class_id.id, + 'shared': room.shared_room, + 'price': room.room_type_id + and ['pricelist', room.room_type_id.id, pricelist_id, + room.room_type_id.name] or 0, + 'room_type_name': room.room_type_id.name, + 'room_type_id': room.room_type_id.id, + 'floor_id': room.floor_id.id, + 'amentity_ids': room.room_type_id.room_amenity_ids.ids, + }) return json_rooms @api.model diff --git a/hotel_calendar/models/inherited_hotel_room_type_restriction_item.py b/hotel_calendar/models/inherited_hotel_room_type_restriction_item.py index 8e9f6b85e..cfcde6493 100644 --- a/hotel_calendar/models/inherited_hotel_room_type_restriction_item.py +++ b/hotel_calendar/models/inherited_hotel_room_type_restriction_item.py @@ -33,17 +33,9 @@ class HotelRoomTypeResrtrictionItem(models.Model): @api.multi def write(self, vals): - restrictions_default_id = self.env['ir.default'].sudo().get( - 'res.config.settings', 'default_restriction_id') - if restrictions_default_id: - restrictions_default_id = int(restrictions_default_id) ret_vals = super(HotelRoomTypeResrtrictionItem, self).write(vals) - bus_hotel_calendar_obj = self.env['bus.hotel.calendar'] for record in self: - if record.restriction_id.id != restrictions_default_id or \ - record.applied_on != '0_room_type': - continue bus_hotel_calendar_obj.send_restriction_notification({ 'restriction_id': record.restriction_id.id, 'date': record.date, diff --git a/hotel_calendar/security/ir.model.access.csv b/hotel_calendar/security/ir.model.access.csv index 95627661a..66ba9fac2 100644 --- a/hotel_calendar/security/ir.model.access.csv +++ b/hotel_calendar/security/ir.model.access.csv @@ -3,3 +3,4 @@ access_room_price_cache_user,hotel_calendar.model_room_pricelist_cached_user,hot access_room_price_cache_call,hotel_calendar.model_room_pricelist_cached_call,hotel_calendar.model_room_pricelist_cached,hotel.group_hotel_call,1,1,1,1 access_hotel_product_pricelist_item_call,hotel_calendar.pricelist_item_call,hotel_calendar.model_product_pricelist_item,hotel.group_hotel_call,1,1,1,1 access_hotel_product_pricelist_item_user,hotel_calendar.pricelist_item_use,hotel_calendar.model_product_pricelist_item,hotel.group_hotel_user,1,1,1,1 +access_hotel_calendar,access_hotel_calendar,model_hotel_calendar,base.group_user,1,0,0,0 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 dcb1e8266..4dd69b277 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 @@ -110,18 +110,19 @@ var PMSCalendarController = AbstractController.extend({ var rooms = []; for (var r of results['rooms']) { var nroom = new HRoom( - r[0], // Id - r[1], // Name - r[2], // Capacity - r[3], // Category - r[4], // Shared Room - r[5] // Price + r['id'], + r['name'], + r['capacity'], + r['class_id'], + r['shared'], + r['price'] ); nroom.addUserData({ - 'room_type_name': r[6], - 'room_type_id': r[7], - 'floor_id': r[8], - 'amenities': r[9] + 'room_type_name': r['room_type_name'], + 'room_type_id': r['room_type_id'], + 'floor_id': r['floor_id'], + 'amenities': r['amenity_ids'], + 'class_id': r['class_id'] }); rooms.push(nroom); } @@ -236,10 +237,10 @@ var PMSCalendarController = AbstractController.extend({ _onLoadViewFilters: function (ev) { var self = this; $.when( - this.model.get_room_types(), + this.model.get_room_type_class(), this.model.get_floors(), this.model.get_amenities(), - this.model.get_rooms() + this.model.get_room_types() ).then(function(a1, a2, a3, a4){ self.renderer.loadViewFilters(a1, a2, a3, a4); }); diff --git a/hotel_calendar/static/src/js/views/calendar/hotel_calendar_model.js b/hotel_calendar/static/src/js/views/calendar/hotel_calendar_model.js index 9b59fb25f..095d4daf3 100644 --- a/hotel_calendar/static/src/js/views/calendar/hotel_calendar_model.js +++ b/hotel_calendar/static/src/js/views/calendar/hotel_calendar_model.js @@ -79,9 +79,9 @@ return AbstractModel.extend({ context: Session.user_context, }); }, - get_rooms: function() { + get_room_type_class: function() { return this._rpc({ - model: 'hotel.room.type', + model: 'hotel.room.type.class', method: 'search_read', args: [false, ['id','name']], context: Session.user_context, diff --git a/hotel_calendar/static/src/js/views/calendar/hotel_calendar_renderer.js b/hotel_calendar/static/src/js/views/calendar/hotel_calendar_renderer.js index 5675f894d..b9b96b69b 100644 --- a/hotel_calendar/static/src/js/views/calendar/hotel_calendar_renderer.js +++ b/hotel_calendar/static/src/js/views/calendar/hotel_calendar_renderer.js @@ -30,6 +30,7 @@ var HotelCalendarView = AbstractRenderer.extend({ _reserv_tooltips: {}, _days_tooltips: [], _last_dates: [false, false], + _hcalendars: [], /** VIEW METHODS **/ @@ -771,7 +772,7 @@ var HotelCalendarView = AbstractRenderer.extend({ var virtual = _.map(this.$el.find('#pms-search #virtual_list').val(), function(item){ return +item; }); var domain = []; if (category && category.length > 0) { - domain.push(['categ_id', 'in', category]); + domain.push(['class_id', 'in', category]); } if (floor && floor.length > 0) { domain.push(['floor_id', 'in', floor]); diff --git a/hotel_calendar/static/src/js/views/calendar_management/hotel_calendar_management_controller.js b/hotel_calendar/static/src/js/views/calendar_management/hotel_calendar_management_controller.js index 17b33d88c..dab9aec38 100644 --- a/hotel_calendar/static/src/js/views/calendar_management/hotel_calendar_management_controller.js +++ b/hotel_calendar/static/src/js/views/calendar_management/hotel_calendar_management_controller.js @@ -89,10 +89,10 @@ var MPMSCalendarController = AbstractController.extend({ var rooms = []; for (var r of results['rooms']) { var nroom = new HRoomType( - r[0], // Id - r[1], // Name - r[2], // Capacity - r[3], // Price + r['id'], + r['name'], + r['capacity'], + r['price'], ); rooms.push(nroom); } diff --git a/hotel_calendar/static/src/lib/hcalendar/js/hcalendar.js b/hotel_calendar/static/src/lib/hcalendar/js/hcalendar.js index c7c260b72..ccad0a273 100644 --- a/hotel_calendar/static/src/lib/hcalendar/js/hcalendar.js +++ b/hotel_calendar/static/src/lib/hcalendar/js/hcalendar.js @@ -41,23 +41,23 @@ function HotelCalendar(/*String*/querySelector, /*Dictionary*/options, /*List*/p }; /** Options **/ - options = options || {}; - this.options = { - startDate: ((options.startDate && HotelCalendar.toMomentUTC(options.startDate)) || moment(new Date()).utc()).subtract('1', 'd'), - days: (options.days || ((options.startDate && HotelCalendar.toMomentUTC(options.startDate)) || moment(new Date())).clone().local().daysInMonth()), - rooms: options.rooms || [], - allowInvalidActions: options.allowInvalidActions || false, - assistedMovement: options.assistedMovement || false, - endOfWeek: options.endOfWeek || 6, - endOfWeekOffset: options.endOfWeekOffset || 0, - divideRoomsByCapacity: options.divideRoomsByCapacity || false, - currencySymbol: options.currencySymbol || '€', - showPricelist: options.showPricelist || false, - showAvailability: options.showAvailability || false, - showNumRooms: options.showNumRooms || 0, - paginatorStepsMin: options.paginatorAdv || 1, - paginatorStepsMax: options.paginatorAdv || 15, - }; + this.options = _.extend({ + startDate: moment(new Date()).utc(), + days: moment(new Date()).local().daysInMonth(), + rooms: [], + allowInvalidActions: false, + assistedMovement: false, + endOfWeek: 6, + endOfWeekOffset: 0, + divideRoomsByCapacity: false, + currencySymbol: '€', + showPricelist: false, + showAvailability: false, + showNumRooms: 0, + paginatorStepsMin: 1, + paginatorStepsMax: 15, + }, options); + this.options.startDate.subtract('1', 'd'); // Check correct values if (this.options.rooms.length > 0 && !(this.options.rooms[0] instanceof HRoom)) { @@ -104,14 +104,15 @@ HotelCalendar.prototype = { //==== CALENDAR setStartDate: function(/*String,MomentObject*/date, /*Int?*/days, /*Bool*/fullUpdate, /*Functions*/callback) { if (moment.isMoment(date)) { - this.options.startDate = date.subtract('1','d'); + this.options.startDate = date; } else if (typeof date === 'string'){ - this.options.startDate = HotelCalendar.toMomentUTC(date).subtract('1','d'); + this.options.startDate = HotelCalendar.toMomentUTC(date); } else { console.warn("[Hotel Calendar][setStartDate] Invalid date format!"); return; } + this.options.startDate.subtract('1','d'); if (typeof days !== 'undefined') { this.options.days = days; } diff --git a/hotel_calendar/views/actions.xml b/hotel_calendar/views/actions.xml index a60864446..2dd031c3b 100644 --- a/hotel_calendar/views/actions.xml +++ b/hotel_calendar/views/actions.xml @@ -24,4 +24,11 @@ tree,form + + Hotel Calendar + hotel.calendar + form + tree,form + + diff --git a/hotel_calendar/views/hotel_calendar_views.xml b/hotel_calendar/views/hotel_calendar_views.xml new file mode 100644 index 000000000..113ae062a --- /dev/null +++ b/hotel_calendar/views/hotel_calendar_views.xml @@ -0,0 +1,36 @@ + + + + + + hotel.calendar.form + hotel.calendar + +
+ + + + + + + + + + + +
+
+
+ + + + hotel.calendar.tree + hotel.calendar + + + + + + + +
diff --git a/hotel_calendar_channel_connector/views/hotel_reservation.xml b/hotel_calendar_channel_connector/views/hotel_reservation.xml index 13cf82c6b..99aa93d4a 100644 --- a/hotel_calendar_channel_connector/views/hotel_reservation.xml +++ b/hotel_calendar_channel_connector/views/hotel_reservation.xml @@ -73,8 +73,7 @@