From d2363b7736b2918bdc0a6b460aadcc591f7e7f6d Mon Sep 17 00:00:00 2001 From: QS5ELkMu Date: Mon, 3 Sep 2018 15:42:23 +0200 Subject: [PATCH] [WIP][MIG][11.0] Hotel Calendar --- hotel/models/hotel_reservation.py | 33 ++++---- hotel/tests/common.py | 6 +- hotel_calendar/models/bus_hotel_calendar.py | 2 +- .../models/hotel_calendar_management.py | 4 +- .../models/inherited_hotel_reservation.py | 81 ++++++++----------- ...ted_hotel_virtual_room_restriction_item.py | 6 +- .../calendar/hotel_calendar_controller.js | 57 ++++++++++--- .../js/views/calendar/hotel_calendar_model.js | 2 +- .../views/calendar/hotel_calendar_renderer.js | 78 ++++++++---------- .../js/views/calendar/hotel_calendar_view.js | 2 - .../src/xml/hotel_calendar_templates.xml | 10 +-- .../tests/test_reservations_calendar.py | 4 +- hotel_calendar/wizard/wizard_reservation.py | 28 +++---- .../models/inherited_hotel_reservation.py | 4 +- .../components/importer.py | 6 +- hotel_channel_connector/controllers/main.py | 4 +- hotel_channel_connector/models/res_config.py | 4 +- .../wizard/wubook_installer.py | 4 +- 18 files changed, 166 insertions(+), 169 deletions(-) diff --git a/hotel/models/hotel_reservation.py b/hotel/models/hotel_reservation.py index 225d01af1..3e90907e8 100644 --- a/hotel/models/hotel_reservation.py +++ b/hotel/models/hotel_reservation.py @@ -203,7 +203,7 @@ class HotelReservation(models.Model): parent_reservation = fields.Many2one('hotel.reservation', 'Parent Reservation') overbooking = fields.Boolean('Is Overbooking', default=False) - + nights = fields.Integer('Nights', compute='_computed_nights', store=True) channel_type = fields.Selection([ ('door', 'Door'), @@ -286,7 +286,11 @@ class HotelReservation(models.Model): #~ 'reserve_color_text': colors[1], }) if self.compute_price_out_vals(vals): - vals.update(self.env['hotel.reservation'].prepare_reservation_lines(vals)) + days_diff = (fields.Date.from_string(vals['checkout']) - fields.Date.from_string(vals['checkin'])).days + vals.update(record.prepare_reservation_lines( + vals['checkin'], + days_diff, + vals = vals)) #REVISAR el unlink record = super(HotelReservation, self).create(vals) #~ if (record.state == 'draft' and record.folio_id.state == 'sale') or \ #~ record.preconfirm: @@ -303,7 +307,7 @@ class HotelReservation(models.Model): if record.compute_price_out_vals(vals): days_diff = (fields.Date.from_string(record.checkout) - fields.Date.from_string(record.checkin)).days record.update(record.prepare_reservation_lines( - record.checkin, + vals['checkin'], days_diff, vals = vals)) #REVISAR el unlink if ('checkin' in vals and record.checkin != vals['checkin']) or \ @@ -337,7 +341,7 @@ class HotelReservation(models.Model): 'to_assign' in vals: return True return False - + @api.multi def overbooking_button(self): self.ensure_one() @@ -411,7 +415,7 @@ class HotelReservation(models.Model): #TODO: Change parity pricelist by default pricelist values = { 'pricelist_id': self.partner_id.property_product_pricelist and self.partner_id.property_product_pricelist.id or \ - self.env['ir.default'].sudo().get('hotel.config.settings', 'parity_pricelist_id'), + self.env['ir.default'].sudo().get('res.config.settings', 'parity_pricelist_id'), } self.update(values) @@ -442,8 +446,8 @@ class HotelReservation(models.Model): self.checkin, days_diff, update_old_prices = False)) - - + + @api.onchange('checkin', 'checkout', 'room_type_id') def onchange_compute_reservation_description(self): @@ -686,7 +690,7 @@ class HotelReservation(models.Model): 'room_type_id' in vals or 'pricelist_id' in vals)): return True return False - + @api.depends('reservation_line_ids', 'reservation_line_ids.discount', 'tax_id') def _compute_amount_reservation(self): """ @@ -707,10 +711,9 @@ class HotelReservation(models.Model): }) @api.multi - def prepare_reservation_lines(self, dfrom, days, vals=False, - update_old_prices=False): + def prepare_reservation_lines(self, dfrom, days, vals=False, update_old_prices=False): total_price = 0.0 - cmds = [] + cmds = [(5, 0, 0)] if not vals: vals = {} pricelist_id = self.env['ir.default'].sudo().get( @@ -723,7 +726,8 @@ class HotelReservation(models.Model): for i in range(0, days): idate = (fields.Date.from_string(dfrom) + timedelta(days=i)).strftime(DEFAULT_SERVER_DATE_FORMAT) old_line = self.reservation_line_ids.filtered(lambda r: r.date == idate) - if update_old_prices or (idate not in old_lines_days): + if update_old_prices or (idate not in old_lines_days): + _logger.info("PASA 3") product = product.with_context( lang=partner.lang, partner=partner.id, @@ -807,7 +811,7 @@ class HotelReservation(models.Model): with the reservations dates between dfrom and dto reservations_dates {'2018-07-30': [hotel.reservation(29,), hotel.reservation(30,), - hotel.reservation(31,)], + hotel.reservation(31,)], '2018-07-31': [hotel.reservation(22,), hotel.reservation(35,), hotel.reservation(36,)], } @@ -871,7 +875,7 @@ class HotelReservation(models.Model): recs = self.search([]).filtered(lambda x: x.cardex_pending is True) if recs: return [('id', 'in', [x.id for x in recs])] - + @api.multi def action_reservation_checkout(self): for record in self: @@ -1078,4 +1082,3 @@ class HotelReservation(models.Model): @api.multi def send_cancel_mail(self): return self.folio_id.send_cancel_mail() - diff --git a/hotel/tests/common.py b/hotel/tests/common.py index 5a32c6f3d..d4ad79355 100644 --- a/hotel/tests/common.py +++ b/hotel/tests/common.py @@ -98,12 +98,12 @@ class TestHotel(TestMail): cls.tz_hotel = 'Europe/Madrid' cls.parity_pricelist_id = cls.pricelist_1.id cls.parity_restrictions_id = cls.restriction_1.id - cls.env['ir.values'].sudo().set_default('hotel.config.settings', + cls.env['ir.values'].sudo().set_default('res.config.settings', 'tz_hotel', cls.tz_hotel) - cls.env['ir.values'].sudo().set_default('hotel.config.settings', + cls.env['ir.values'].sudo().set_default('res.config.settings', 'parity_pricelist_id', cls.parity_pricelist_id) - cls.env['ir.values'].sudo().set_default('hotel.config.settings', + cls.env['ir.values'].sudo().set_default('res.config.settings', 'parity_restrictions_id', cls.parity_restrictions_id) diff --git a/hotel_calendar/models/bus_hotel_calendar.py b/hotel_calendar/models/bus_hotel_calendar.py index 5e73bddef..2cef55759 100644 --- a/hotel_calendar/models/bus_hotel_calendar.py +++ b/hotel_calendar/models/bus_hotel_calendar.py @@ -39,7 +39,7 @@ class BusHotelCalendar(models.TransientModel): 'username': user_id.partner_id.name, 'userid': user_id.id, 'reservation': { - 'product_id': vals['product_id'], + 'id': vals['id'], 'reserv_id': vals['reserv_id'], 'partner_name': vals['partner_name'], 'adults': vals['adults'], diff --git a/hotel_calendar/models/hotel_calendar_management.py b/hotel_calendar/models/hotel_calendar_management.py index 33d9c2204..fc2317b7d 100644 --- a/hotel_calendar/models/hotel_calendar_management.py +++ b/hotel_calendar/models/hotel_calendar_management.py @@ -270,10 +270,10 @@ class HotelCalendarManagement(models.TransientModel): vals = {} if not pricelist_id: pricelist_id = self.env['ir.default'].sudo().get( - 'hotel.config.settings', 'parity_pricelist_id') + 'res.config.settings', 'parity_pricelist_id') if not restriction_id: restriction_id = self.env['ir.default'].sudo().get( - 'hotel.config.settings', 'parity_restrictions_id') + 'res.config.settings', 'parity_restrictions_id') pricelist_id = int(pricelist_id) vals.update({'pricelist_id': pricelist_id}) diff --git a/hotel_calendar/models/inherited_hotel_reservation.py b/hotel_calendar/models/inherited_hotel_reservation.py index c4a3b514c..d7ab0f4b6 100644 --- a/hotel_calendar/models/inherited_hotel_reservation.py +++ b/hotel_calendar/models/inherited_hotel_reservation.py @@ -20,7 +20,7 @@ class HotelReservation(models.Model): json_reservation_tooltips = {} for reserv in reservations: json_reservations.append([ - reserv.product_id.id, + reserv.room_id.id, reserv.id, reserv.folio_id.partner_id.name, reserv.adults, @@ -60,33 +60,24 @@ class HotelReservation(models.Model): @api.model def _hcalendar_room_data(self, rooms): pricelist_id = self.env['ir.default'].sudo().get( - 'hotel.config.settings', 'parity_pricelist_id') + 'res.config.settings', 'parity_pricelist_id') if pricelist_id: pricelist_id = int(pricelist_id) json_rooms = [] room_type_obj = self.env['hotel.room.type'] - vroom_obj = self.env['hotel.room.type'] for room in rooms: - room_type = room_type_obj.search([ - ('cat_id', '=', room.categ_id.id) - ], limit=1) - vrooms = vroom_obj.search([ - '|', ('room_ids', 'in', room.id), - ('room_type_ids.id', '=', room.categ_id.id)], - order='hcal_sequence ASC') json_rooms.append(( - room.product_id.id, + room.id, room.name, room.capacity, - room.categ_id.id, - room_type.code_type, + '', # Reserved for type code room.shared_room, - room.sale_price_type == 'vroom' - and ['pricelist', room.price_virtual_room.id, pricelist_id, - room.price_virtual_room.name] - or ['fixed', room.list_price], - vrooms.mapped('name'), - vrooms.ids, + 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, room.room_amenities.ids)) return json_rooms @@ -129,7 +120,7 @@ class HotelReservation(models.Model): @api.model def get_hcalendar_pricelist_data(self, dfrom, dto): pricelist_id = self.env['ir.default'].sudo().get( - 'hotel.config.settings', 'parity_pricelist_id') + 'res.config.settings', 'parity_pricelist_id') if pricelist_id: pricelist_id = int(pricelist_id) date_start = date_utils.get_datetime(dfrom, hours=False) \ @@ -137,39 +128,39 @@ class HotelReservation(models.Model): date_diff = date_utils.date_diff(date_start, dto, hours=False) + 1 # Get Prices json_rooms_prices = {pricelist_id: []} - vrooms = self.env['hotel.room.type'].search( + room_typed_ids = self.env['hotel.room.type'].search( [], order='hcal_sequence ASC') - vroom_pr_cached_obj = self.env['room.pricelist.cached'] + room_pr_cached_obj = self.env['room.pricelist.cached'] - for vroom in vrooms: + for room_type_id in room_typed_ids: days = {} for i in range(0, date_diff): ndate = date_start + timedelta(days=i) ndate_str = ndate.strftime(DEFAULT_SERVER_DATE_FORMAT) - prod_price_id = vroom_pr_cached_obj.search([ - ('virtual_room_id', '=', vroom.id), + prod_price_id = room_pr_cached_obj.search([ + ('room_id', '=', room_type_id.id), ('date', '=', ndate_str) ], limit=1) days.update({ ndate.strftime("%d/%m/%Y"): prod_price_id and prod_price_id.price or - vroom.product_id.with_context( + room_type_id.product_id.with_context( quantity=1, date=ndate_str, pricelist=pricelist_id).price }) json_rooms_prices[pricelist_id].append({ - 'room': vroom.id, + 'room': room_type_id.id, 'days': days, - 'title': vroom.name, + 'title': room_type_id.name, }) return json_rooms_prices @api.model def get_hcalendar_restrictions_data(self, dfrom, dto): restriction_id = self.env['ir.default'].sudo().get( - 'hotel.config.settings', 'parity_restrictions_id') + 'res.config.settings', 'parity_restrictions_id') if restriction_id: restriction_id = int(restriction_id) date_start = date_utils.get_datetime(dfrom, hours=False) \ @@ -177,17 +168,17 @@ class HotelReservation(models.Model): date_diff = date_utils.date_diff(dfrom, dto, hours=False) + 1 # Get Prices json_rooms_rests = {} - vrooms = self.env['hotel.room.type'].search( + room_type_ids = self.env['hotel.room.type'].search( [], order='hcal_sequence ASC') vroom_rest_obj = self.env['hotel.virtual.room.restriction.item'] - for vroom in vrooms: + for room_type_id in room_type_ids: days = {} for i in range(0, date_diff): ndate = date_start + timedelta(days=i) ndate_str = ndate.strftime(DEFAULT_SERVER_DATE_FORMAT) rest_id = vroom_rest_obj.search([ - ('virtual_room_id', '=', vroom.id), + ('room_type_id', '=', room_type_id.id), ('date_start', '>=', ndate_str), ('date_end', '<=', ndate_str), ('applied_on', '=', '0_virtual_room'), @@ -207,7 +198,7 @@ class HotelReservation(models.Model): rest_id.closed_arrival, rest_id.closed_departure) }) - json_rooms_rests.update({vroom.id: days}) + json_rooms_rests.update({room_type_id.id: days}) return json_rooms_rests @api.model @@ -246,9 +237,9 @@ class HotelReservation(models.Model): 'allow_invalid_actions': type_move == 'allow_invalid', 'assisted_movement': type_move == 'assisted', 'default_arrival_hour': self.env['ir.default'].sudo().get( - 'hotel.config.settings', 'default_arrival_hour'), + 'res.config.settings', 'default_arrival_hour'), 'default_departure_hour': self.env['ir.default'].sudo().get( - 'hotel.config.settings', 'default_departure_hour'), + 'res.config.settings', 'default_departure_hour'), 'show_notifications': user_id.pms_show_notifications, 'show_pricelist': user_id.pms_show_pricelist, 'show_availability': user_id.pms_show_availability, @@ -283,7 +274,7 @@ class HotelReservation(models.Model): 'action': naction, 'type': ntype, 'title': ntitle, - 'product_id': record.product_id.id, + 'id': record.room_id.id, 'reserv_id': record.id, 'partner_name': record.partner_id.name, 'adults': record.adults, @@ -296,7 +287,7 @@ class HotelReservation(models.Model): 'splitted': record.splitted, 'parent_reservation': record.parent_reservation and record.parent_reservation.id or 0, - 'room_name': record.product_id.name, + 'room_name': record.name, 'partner_phone': record.partner_id.mobile or record.partner_id.phone or _('Undefined'), 'state': record.state, @@ -310,7 +301,7 @@ class HotelReservation(models.Model): from_reservs = self.env['hotel.reservation'].browse(fromReservsIds) to_reservs = self.env['hotel.reservation'].browse(toReservsIds) - if not any(from_reservs) or not any(toReservs): + if not any(from_reservs) or not any(to_reservs): raise ValidationError(_("Invalid swap parameters")) max_from_persons = max( @@ -318,29 +309,23 @@ class HotelReservation(models.Model): max_to_persons = max( to_reservs.mapped(lambda x: x.adults + x.children)) - from_room_product = from_reservs[0].product_id - to_room_product = to_reservs[0].product_id + from_room = from_reservs[0].room_id + to_room = to_reservs[0].room_id from_overbooking = from_reservs[0].overbooking to_overbooking = to_reservs[0].overbooking - hotel_room_obj = self.env['hotel.room'] - from_room = hotel_room_obj.search([ - ('product_id', '=', from_room_product.id)]) - to_room = hotel_room_obj.search([ - ('product_id', '=', from_room_product.id)]) - if max_from_persons > to_room.capacity or \ max_to_persons > from_room.capacity: raise ValidationError("Invalid swap operation: wrong capacity") for record in from_reservs: record.with_context({'ignore_avail_restrictions': True}).write({ - 'product_id': to_room_product.id, + 'room_id': to_room.id, 'overbooking': to_overbooking, }) for record in to_reservs: record.with_context({'ignore_avail_restrictions': True}).write({ - 'product_id': from_room_product.id, + 'room_id': from_room.id, 'overbooking': from_overbooking, }) diff --git a/hotel_calendar/models/inherited_hotel_virtual_room_restriction_item.py b/hotel_calendar/models/inherited_hotel_virtual_room_restriction_item.py index 2059905fb..f315aa327 100644 --- a/hotel_calendar/models/inherited_hotel_virtual_room_restriction_item.py +++ b/hotel_calendar/models/inherited_hotel_virtual_room_restriction_item.py @@ -12,7 +12,7 @@ class HotelVirtualRoomResrtrictionItem(models.Model): def create(self, vals): res = super(HotelVirtualRoomResrtrictionItem, self).create(vals) restrictions_parity_id = self.env['ir.default'].sudo().get( - 'hotel.config.settings', 'parity_restrictions_id') + 'res.config.settings', 'parity_restrictions_id') if restrictions_parity_id: restrictions_parity_id = int(restrictions_parity_id) restriction_id = res.restriction_id.id @@ -36,7 +36,7 @@ class HotelVirtualRoomResrtrictionItem(models.Model): @api.multi def write(self, vals): restrictions_parity_id = self.env['ir.default'].sudo().get( - 'hotel.config.settings', 'parity_restrictions_id') + 'res.config.settings', 'parity_restrictions_id') if restrictions_parity_id: restrictions_parity_id = int(restrictions_parity_id) ret_vals = super(HotelVirtualRoomResrtrictionItem, self).write(vals) @@ -64,7 +64,7 @@ class HotelVirtualRoomResrtrictionItem(models.Model): @api.multi def unlink(self): restrictions_parity_id = self.env['ir.default'].sudo().get( - 'hotel.config.settings', 'parity_restrictions_id') + 'res.config.settings', 'parity_restrictions_id') if restrictions_parity_id: restrictions_parity_id = int(restrictions_parity_id) # Construct dictionary with relevant info of removed records 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 712334ce8..d187817dc 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 @@ -18,6 +18,8 @@ var PMSCalendarController = AbstractController.extend({ onLoadViewFilters: '_onLoadViewFilters', onUpdateButtonsCounter: '_onUpdateButtonsCounter', onReloadCalendar: '_onReloadCalendar', + onUpdateReservations: '_onUpdateReservations', + onSwapReservations: '_onSwapReservations' }), init: function (parent, model, renderer, params) { @@ -45,6 +47,37 @@ var PMSCalendarController = AbstractController.extend({ //-------------------------------------------------------------------------- // Handlers //-------------------------------------------------------------------------- + _onUpdateReservations: function (ev) { + var self = this; + return this.model.update_records(ev.data.ids, ev.data.values).then(function(result){ + // Remove OB Room Row? + if (ev.data.oldReservation.room.overbooking) { + self.renderer._hcalendar.removeOBRoomRow(ev.data.oldReservation); + } + }).fail(function(err, errev){ + self.renderer._hcalendar.replaceReservation(ev.data.newReservation, ev.data.oldReservation); + }); + }, + + _onSwapReservations: function (ev) { + var self = this; + return this.model.swap_reservations(ev.data.fromIds, ev.data.toIds).then(function(results){ + var allReservs = ev.data.detail.inReservs.concat(ev.data.detail.outReservs); + for (var nreserv of allReservs) { + self.renderer.$el.find(nreserv._html).stop(true); + } + }).fail(function(err, errev){ + for (var nreserv of ev.data.detail.inReservs) { + self.renderer.$el.find(nreserv._html).animate({'top': refFromReservDiv.style.top}, 'fast'); + } + for (var nreserv of ev.detail.outReservs) { + self.renderer.$el.find(nreserv._html).animate({'top': refToReservDiv.style.top}, 'fast'); + } + + self.renderer.$el._hcalendar.swapReservations(ev.data.detail.outReservs, ev.data.detail.inReservs); + }); + }, + _onLoadCalendarSettings: function (ev) { var self = this; return this.model.get_hcalendar_settings().then(function(options){ @@ -71,17 +104,15 @@ var PMSCalendarController = AbstractController.extend({ r[0], // Id r[1], // Name r[2], // Capacity - r[4], // Category - r[5], // Shared Room - r[6] // Price + r[3], // Category + r[4], // Shared Room + r[5] // Price ); nroom.addUserData({ - 'categ_id': r[3], - 'price_from': r[6][0] === 'fixed'?`${r[6][1]}${HotelConstants.CURRENCY_SYMBOL} (${_t('Fixed Price')})`:r[6][3], - 'inside_rooms': r[7], - 'inside_rooms_ids': r[8], - 'floor_id': r[9], - 'amenities': r[10] + 'room_type_name': r[6], + 'room_type_id': r[7], + 'floor_id': r[8], + 'amenities': r[9] }); rooms.push(nroom); } @@ -91,10 +122,10 @@ var PMSCalendarController = AbstractController.extend({ // TODO: Not read this... do the change!! var reservs = []; for (var r of results['reservations']) { - var room = self._hcalendar.getRoom(r[0], r[15], r[1]); + var room = self.renderer._hcalendar.getRoom(r[0], r[15], r[1]); // need create a overbooking row? if (!room && r[15]) { - room = self.renderer._hcalendar.createOBRoom(self._hcalendar.getRoom(r[0]), r[1]); + room = self.renderer._hcalendar.createOBRoom(self.renderer._hcalendar.getRoom(r[0]), r[1]); self.renderer._hcalendar.createOBRoomRow(room); } if (!room) { @@ -241,10 +272,10 @@ var PMSCalendarController = AbstractController.extend({ nreservs = _.reject(nreservs, function(item){ return item.id == reserv['reserv_id']; }); } else { nreservs = _.reject(nreservs, {'id': reserv['reserv_id']}); // Only like last changes - var room = this.renderer._hcalendar.getRoom(reserv['product_id'], reserv['overbooking'], reserv['reserv_id']); + var room = this.renderer._hcalendar.getRoom(reserv['id'], reserv['overbooking'], reserv['reserv_id']); // need create a overbooking row? if (!room && reserv['overbooking']) { - room = this.renderer._hcalendar.createOBRoom(this.renderer._hcalendar.getRoom(reserv['product_id']), reserv['reserv_id']); + room = this.renderer._hcalendar.createOBRoom(this.renderer._hcalendar.getRoom(reserv['id']), reserv['reserv_id']); this.renderer._hcalendar.createOBRoomRow(room); } if (!room) { 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 63b254b84..5e3415781 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 @@ -102,7 +102,7 @@ return AbstractModel.extend({ return this._rpc({ model: this.modelName, method: 'write', - args: [ids, write_values], + args: [ids, vals], 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 d8a4fa235..0475296d1 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 @@ -35,7 +35,6 @@ var HotelCalendarView = AbstractRenderer.extend({ /** VIEW METHODS **/ init: function(parent, state, params) { this._super.apply(this, arguments); - this.model = params.model; }, start: function () { @@ -204,20 +203,12 @@ var HotelCalendarView = AbstractRenderer.extend({ for (var nreserv of ev.detail.outReservs) { $(nreserv._html).animate({'top': refFromReservDiv.style.top}); } - self.model.swapReservations(fromIds, toIds).then(function(results){ - var allReservs = ev.detail.inReservs.concat(ev.detail.outReservs); - for (nreserv of allReservs) { - $(nreserv._html).stop(true); - } - }).fail(function(err, errev){ - for (var nreserv of ev.detail.inReservs) { - $(nreserv._html).animate({'top': refFromReservDiv.style.top}, 'fast'); - } - for (var nreserv of ev.detail.outReservs) { - $(nreserv._html).animate({'top': refToReservDiv.style.top}, 'fast'); - } - - self._hcalendar.swapReservations(ev.detail.outReservs, ev.detail.inReservs); + self.trigger_up('onSwapReservations', { + 'fromIds': fromIds, + 'toIds': toIds, + 'detail': ev.detail, + 'refFromReservDiv': refFromReservDiv, + 'refToReservDiv': refToReservDiv }); } else { var qdict = {}; @@ -290,16 +281,14 @@ var HotelCalendarView = AbstractRenderer.extend({ var write_values = { 'checkin': newReservation.startDate.format(HotelConstants.ODOO_DATETIME_MOMENT_FORMAT), 'checkout': newReservation.endDate.format(HotelConstants.ODOO_DATETIME_MOMENT_FORMAT), - 'product_id': roomId, + 'room_id': roomId, 'overbooking': newReservation.room.overbooking }; - self.model.update_records([newReservation.id], write_values).then(function(result){ - // Remove OB Room Row? - if (oldReservation.room.overbooking) { - self._hcalendar.removeOBRoomRow(oldReservation); - } - }).fail(function(err, errev){ - self._hcalendar.replaceReservation(newReservation, oldReservation); + self.trigger_up('onUpdateReservations', { + 'ids': [newReservation.id], + 'values': write_values, + 'oldReservation': oldReservation, + 'newReservation': newReservation }); // Workarround for dispatch room lines regeneration // new Model('hotel.reservation').call('on_change_checkin_checkout_product_id', [[newReservation.id], false]); @@ -313,7 +302,7 @@ var HotelCalendarView = AbstractRenderer.extend({ ], $content: QWeb.render('HotelCalendar.ConfirmReservationChanges', qdict) }).open(); - dialog.$modal.on('hide.bs.modal', function(e){ + dialog.opened(function(e){ if (!hasChanged) { self._hcalendar.replaceReservation(newReservation, oldReservation); } @@ -327,14 +316,14 @@ var HotelCalendarView = AbstractRenderer.extend({ var last_cell = ev.detail.cells[ev.detail.cells.length-1]; var date_cell_start = HotelCalendar.toMoment(self._hcalendar.etable.querySelector(`#${ev.detail.cells[0].dataset.hcalParentCell}`).dataset.hcalDate); var date_cell_end = HotelCalendar.toMoment(self._hcalendar.etable.querySelector(`#${last_cell.dataset.hcalParentCell}`).dataset.hcalDate); - var parentRow = document.querySelector(`#${ev.detail.cells[0].dataset.hcalParentRow}`); - var room = self._hcalendar.getRoom(parentRow.dataset.hcalRoomObjId); - if (room.overbooking) { - return; - } - var nights = date_cell_end.diff(date_cell_start, 'days'); + var parentRow = document.querySelector(`#${ev.detail.cells[0].dataset.hcalParentRow}`); + var room = self._hcalendar.getRoom(parentRow.dataset.hcalRoomObjId); + if (room.overbooking) { + return; + } + var nights = date_cell_end.diff(date_cell_start, 'days'); var qdict = { - 'total_price': Number(ev.detail.totalPrice).toLocaleString(), + //'total_price': Number(ev.detail.totalPrice).toLocaleString(), 'nights': nights }; $(last_cell).tooltip({ @@ -379,7 +368,8 @@ var HotelCalendarView = AbstractRenderer.extend({ 'default_checkout': endDate.utc().format(HotelConstants.ODOO_DATETIME_MOMENT_FORMAT), 'default_adults': numBeds, 'default_children': 0, - 'default_product_id': room.id, + 'default_room_id': room.id, + 'default_room_type_id': room.getUserData('room_type_id'), }, title: _t("Create: ") + _t("Reservation"), initial_view: "form", @@ -403,10 +393,10 @@ var HotelCalendarView = AbstractRenderer.extend({ _assign_extra_info: function() { var self = this; $(this._hcalendar.etable).find('.hcal-cell-room-type-group-item.btn-hcal-3d').on("mouseenter", function(){ - var $this = $(this); - var room = self._hcalendar.getRoom($this.parent().data("hcalRoomObjId")); - if (room.overbooking) { - $this.tooltip({ + var $this = $(this); + var room = self._hcalendar.getRoom($this.parent().data("hcalRoomObjId")); + if (room.overbooking) { + $this.tooltip({ animation: true, html: true, placement: 'right', @@ -414,13 +404,11 @@ var HotelCalendarView = AbstractRenderer.extend({ }).tooltip('show'); return; } else { - var qdict = { - 'price_from': room.getUserData('price_from'), - 'inside_rooms': room.getUserData('inside_rooms'), - 'num_inside_rooms': room.getUserData('inside_rooms').length, - 'name': room.number - }; - $this.tooltip({ + var qdict = { + 'room_type_name': room.getUserData('room_type_name'), + 'name': room.number + }; + $this.tooltip({ animation: true, html: true, placement: 'right', @@ -636,7 +624,7 @@ var HotelCalendarView = AbstractRenderer.extend({ var $list = this.$el.find('#pms-search #type_list'); $list.html(''); resultsHotelRoomType.forEach(function(item, index){ - $list.append(``); + $list.append(``); }); $list.select2({ theme: "classic" @@ -800,7 +788,7 @@ var HotelCalendarView = AbstractRenderer.extend({ domain.push(['amenities', 'in', amenities]); } if (virtual && virtual.length > 0) { - domain.push(['inside_rooms_ids', 'some', virtual]); + domain.push(['room_type_id', 'some', virtual]); } this._hcalendar.setDomain(HotelCalendar.DOMAIN.ROOMS, domain); diff --git a/hotel_calendar/static/src/js/views/calendar/hotel_calendar_view.js b/hotel_calendar/static/src/js/views/calendar/hotel_calendar_view.js index 31f927e28..1a8ecc1b2 100644 --- a/hotel_calendar/static/src/js/views/calendar/hotel_calendar_view.js +++ b/hotel_calendar/static/src/js/views/calendar/hotel_calendar_view.js @@ -193,8 +193,6 @@ var PMSCalendarView = AbstractView.extend({ this.controllerParams.context = params.context || {}; this.controllerParams.displayName = params.action && params.action.name; - this.rendererParams.model = viewInfo.model; - this.loadParams.fields = fields; this.loadParams.fieldsInfo = viewInfo.fieldsInfo; this.loadParams.creatable = false; diff --git a/hotel_calendar/static/src/xml/hotel_calendar_templates.xml b/hotel_calendar/static/src/xml/hotel_calendar_templates.xml index 736f677bf..eeb8195b4 100644 --- a/hotel_calendar/static/src/xml/hotel_calendar_templates.xml +++ b/hotel_calendar/static/src/xml/hotel_calendar_templates.xml @@ -83,15 +83,7 @@
-

Price From:

- - Belongs to the Virtual Rooms: -
    -
  • - -
  • -
-
+

Room Type:

diff --git a/hotel_calendar/tests/test_reservations_calendar.py b/hotel_calendar/tests/test_reservations_calendar.py index 1cbc497ad..14c8b2d65 100644 --- a/hotel_calendar/tests/test_reservations_calendar.py +++ b/hotel_calendar/tests/test_reservations_calendar.py @@ -222,12 +222,12 @@ class TestReservationsCalendar(TestHotelCalendar): self.user_hotel_manager.pms_type_move == 'assisted', "Hotel Calendar Invalid Options!") default_arrival_hour = self.env['ir.default'].sudo().get( - 'hotel.config.settings', 'default_arrival_hour') + 'res.config.settings', 'default_arrival_hour') self.assertEqual(hcal_options['default_arrival_hour'], default_arrival_hour, "Hotel Calendar Invalid Options!") default_departure_hour = self.env['ir.default'].sudo().get( - 'hotel.config.settings', 'default_departure_hour') + 'res.config.settings', 'default_departure_hour') self.assertEqual(hcal_options['default_departure_hour'], default_departure_hour, "Hotel Calendar Invalid Options!") diff --git a/hotel_calendar/wizard/wizard_reservation.py b/hotel_calendar/wizard/wizard_reservation.py index 08d791e00..0c4271aee 100644 --- a/hotel_calendar/wizard/wizard_reservation.py +++ b/hotel_calendar/wizard/wizard_reservation.py @@ -48,7 +48,7 @@ class FolioWizard(models.TransientModel): def _get_default_checkin(self): folio = False default_arrival_hour = self.env['ir.default'].sudo().get( - 'hotel.config.settings', 'default_arrival_hour') + 'res.config.settings', 'default_arrival_hour') if 'folio_id' in self._context: folio = self.env['hotel.folio'].search([ ('id', '=', self._context['folio_id']) @@ -57,7 +57,7 @@ class FolioWizard(models.TransientModel): return folio.room_lines[0].checkin else: tz_hotel = self.env['ir.default'].sudo().get( - 'hotel.config.settings', 'tz_hotel') + 'res.config.settings', 'tz_hotel') now_utc_dt = date_utils.now() ndate = "%s %s:00" % \ (now_utc_dt.strftime(DEFAULT_SERVER_DATE_FORMAT), @@ -70,7 +70,7 @@ class FolioWizard(models.TransientModel): def _get_default_checkout(self): folio = False default_departure_hour = self.env['ir.default'].sudo().get( - 'hotel.config.settings', 'default_departure_hour') + 'res.config.settings', 'default_departure_hour') if 'folio_id' in self._context: folio = self.env['hotel.folio'].search([ ('id', '=', self._context['folio_id']) @@ -79,7 +79,7 @@ class FolioWizard(models.TransientModel): return folio.room_lines[0].checkout else: tz_hotel = self.env['ir.default'].sudo().get( - 'hotel.config.settings', 'tz_hotel') + 'res.config.settings', 'tz_hotel') now_utc_dt = date_utils.now() + timedelta(days=1) ndate = "%s %s:00" % \ (now_utc_dt.strftime(DEFAULT_SERVER_DATE_FORMAT), @@ -148,14 +148,14 @@ class FolioWizard(models.TransientModel): line.checkout, hours=False) hotel_tz = self.env['ir.default'].sudo().get( - 'hotel.config.settings', + 'res.config.settings', 'hotel_tz') start_date_utc_dt = date_utils.get_datetime(self.checkin) start_date_dt = date_utils.dt_as_timezone(start_date_utc_dt, hotel_tz) for room in product_list: pricelist_id = self.env['ir.default'].sudo().get( - 'hotel.config.settings', 'parity_pricelist_id') + 'res.config.settings', 'parity_pricelist_id') if pricelist_id: pricelist_id = int(pricelist_id) res_price = 0 @@ -208,14 +208,14 @@ class FolioWizard(models.TransientModel): self.checkout = time.strftime(DEFAULT_SERVER_DATETIME_FORMAT) # UTC -> Hotel tz - tz = self.env['ir.default'].sudo().get('hotel.config.settings', + tz = self.env['ir.default'].sudo().get('res.config.settings', 'tz_hotel') chkin_utc_dt = date_utils.get_datetime(self.checkin) chkout_utc_dt = date_utils.get_datetime(self.checkout) if chkin_utc_dt >= chkout_utc_dt: dpt_hour = self.env['ir.default'].sudo().get( - 'hotel.config.settings', 'default_departure_hour') + 'res.config.settings', 'default_departure_hour') checkout_str = (chkin_utc_dt + timedelta(days=1)).strftime( DEFAULT_SERVER_DATE_FORMAT) checkout_str = "%s %s:00" % (checkout_str, dpt_hour) @@ -397,14 +397,14 @@ class VirtualRoomWizars(models.TransientModel): if self.rooms_num > self.max_rooms: raise ValidationError(_("There are not enough rooms!")) # UTC -> Hotel tz - tz = self.env['ir.default'].sudo().get('hotel.config.settings', + tz = self.env['ir.default'].sudo().get('res.config.settings', 'tz_hotel') chkin_utc_dt = date_utils.get_datetime(self.checkin) chkout_utc_dt = date_utils.get_datetime(self.checkout) if chkin_utc_dt >= chkout_utc_dt: dpt_hour = self.env['ir.default'].sudo().get( - 'hotel.config.settings', 'default_departure_hour') + 'res.config.settings', 'default_departure_hour') checkout_str = (chkin_utc_dt + timedelta(days=1)).strftime( DEFAULT_SERVER_DATE_FORMAT) checkout_str = "%s %s:00" % (checkout_str, dpt_hour) @@ -424,7 +424,7 @@ class VirtualRoomWizars(models.TransientModel): checkout_dt -= timedelta(days=1) pricelist_id = self.env['ir.default'].sudo().get( - 'hotel.config.settings', 'parity_pricelist_id') + 'res.config.settings', 'parity_pricelist_id') if pricelist_id: pricelist_id = int(pricelist_id) @@ -507,14 +507,14 @@ class ReservationWizard(models.TransientModel): self.checkout = self.folio_wizard_id.checkout hotel_tz = self.env['ir.default'].sudo().get( - 'hotel.config.settings', 'hotel_tz') + 'res.config.settings', 'hotel_tz') start_date_utc_dt = date_utils.get_datetime(line.checkin) start_date_dt = date_utils.dt_as_timezone(start_date_utc_dt, hotel_tz) if line.virtual_room_id: pricelist_id = self.env['ir.default'].sudo().get( - 'hotel.config.settings', 'parity_pricelist_id') + 'res.config.settings', 'parity_pricelist_id') if pricelist_id: pricelist_id = int(pricelist_id) nights = days_diff = date_utils.date_diff(line.checkin, @@ -567,7 +567,7 @@ class ServiceWizard(models.TransientModel): if self.product_id: #TODO change pricelist for partner pricelist_id = self.env['ir.default'].sudo().get( - 'hotel.config.settings', 'parity_pricelist_id') + 'res.config.settings', 'parity_pricelist_id') prod = self.product_id.with_context( lang=self.folio_wizard_id.partner_id.lang, partner=self.folio_wizard_id.partner_id.id, diff --git a/hotel_calendar_channel_connector/models/inherited_hotel_reservation.py b/hotel_calendar_channel_connector/models/inherited_hotel_reservation.py index fe396c641..df0209e8c 100644 --- a/hotel_calendar_channel_connector/models/inherited_hotel_reservation.py +++ b/hotel_calendar_channel_connector/models/inherited_hotel_reservation.py @@ -14,13 +14,13 @@ class HotelReservation(models.Model): @api.model def _generate_reservation_notif(self, action, ntype, title, - product_id, reserv_id, partner_name, + 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, product_id, + action, ntype, title, id, reserv_id, partner_name, adults, children, checkin, checkout, folio_id, color, color_text, splitted, parent_reservation, diff --git a/hotel_channel_connector/components/importer.py b/hotel_channel_connector/components/importer.py index 1b4c8c468..d4de13fa7 100644 --- a/hotel_channel_connector/components/importer.py +++ b/hotel_channel_connector/components/importer.py @@ -193,13 +193,13 @@ class HotelChannelConnectorImporter(AbstractComponent): _logger.info("=== BOOKINGS FROM WUBOOK") _logger.info(bookings) default_arrival_hour = self.env['ir.default'].sudo().get( - 'hotel.config.settings', 'default_arrival_hour') + 'res.config.settings', 'default_arrival_hour') default_departure_hour = self.env['ir.default'].sudo().get( - 'hotel.config.settings', 'default_departure_hour') + 'res.config.settings', 'default_departure_hour') # Get user timezone tz_hotel = self.env['ir.default'].sudo().get( - 'hotel.config.settings', 'tz_hotel') + 'res.config.settings', 'tz_hotel') res_partner_obj = self.env['res.partner'] hotel_reserv_obj = self.env['hotel.reservation'] hotel_folio_obj = self.env['hotel.folio'] diff --git a/hotel_channel_connector/controllers/main.py b/hotel_channel_connector/controllers/main.py index 75b9e94ae..7632c4fc7 100644 --- a/hotel_channel_connector/controllers/main.py +++ b/hotel_channel_connector/controllers/main.py @@ -82,7 +82,7 @@ class website_wubook(http.Controller): wubook_obj.fetch_rooms_values(dfrom, dto) parity_restr_id = request.env['ir.default'].sudo().get( - 'hotel.config.settings', 'parity_restrictions_id') + 'res.config.settings', 'parity_restrictions_id') if parity_restr_id: vroom_restr_obj = request.env['hotel.virtual.room.restriction'] restr_id = vroom_restr_obj.sudo().browse(int(parity_restr_id)) @@ -91,7 +91,7 @@ class website_wubook(http.Controller): rpid=restr_id.wpid) parity_pricelist_id = request.env['ir.default'].sudo().get( - 'hotel.config.settings', 'parity_pricelist_id') + 'res.config.settings', 'parity_pricelist_id') if parity_pricelist_id: pricelist_id = request.env['product.pricelist'].sudo().browse( int(parity_pricelist_id)) diff --git a/hotel_channel_connector/models/res_config.py b/hotel_channel_connector/models/res_config.py index 28e5a8122..4adb5533a 100644 --- a/hotel_channel_connector/models/res_config.py +++ b/hotel_channel_connector/models/res_config.py @@ -115,9 +115,9 @@ class HotelChannelConnectorConfiguration(models.TransientModel): # Get Parity Models pricelist_id = int(self.env['ir.default'].sudo().get( - 'hotel.config.settings', 'parity_pricelist_id')) + 'res.config.settings', 'parity_pricelist_id')) restriction_id = int(self.env['ir.default'].sudo().get( - 'hotel.config.settings', 'parity_restrictions_id')) + 'res.config.settings', 'parity_restrictions_id')) vroom_restr_it_obj = self.env['hotel.virtual.room.restriction.item'] # Secure Wubook Input diff --git a/hotel_channel_connector/wizard/wubook_installer.py b/hotel_channel_connector/wizard/wubook_installer.py index e671e9e44..b0c84c460 100644 --- a/hotel_channel_connector/wizard/wubook_installer.py +++ b/hotel_channel_connector/wizard/wubook_installer.py @@ -124,10 +124,10 @@ class WuBookInstallerParity(models.TransientModel): wubookObj = self.env['wubook'] irValuesObj = self.env['ir.values'] for rec in self: - irValuesObj.sudo().set_default('hotel.config.settings', + irValuesObj.sudo().set_default('res.config.settings', 'parity_pricelist_id', rec.parity_pricelist_id.id) - irValuesObj.sudo().set_default('hotel.config.settings', + irValuesObj.sudo().set_default('res.config.settings', 'parity_restrictions_id', rec.parity_restrictions_id.id) import_data = rec.import_data