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 a8a1eb032..f47da36ba 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 @@ -372,18 +372,6 @@ var PMSCalendarController = AbstractController.extend({ res_id: ev.detail.reservationObj.id, views: [[false, 'form']] }); - // self._model.call('get_formview_id', [res_id, Session.user_context]).then(function(view_id){ - // var pop = new ViewDialogs.FormViewDialog(self, { - // res_model: 'hotel.folio', - // res_id: res_id, - // title: _t("Open: ") + ev.detail.reservationObj.title, - // view_id: view_id - // //readonly: false - // }).open(); - // pop.on('write_completed', self, function(){ - // self.trigger('changed_value'); - // }); - // }); }); this._multi_calendar.on_calendar('hcalOnUnifyReservations', function(ev){ console.log("TO UNIFY"); diff --git a/hotel_calendar/static/src/js/widgets/MultiCalendar.js b/hotel_calendar/static/src/js/widgets/MultiCalendar.js index 841cd3fdc..9f65bec65 100644 --- a/hotel_calendar/static/src/js/widgets/MultiCalendar.js +++ b/hotel_calendar/static/src/js/widgets/MultiCalendar.js @@ -208,7 +208,7 @@ odoo.define('hotel_calendar.MultiCalendar', function(require) { } for (var calendar of this._calendars) { - calendar.addReservations(this._dataset['reservations']); + calendar.addReservations(reservations); } }, diff --git a/hotel_calendar/static/src/lib/hcalendar/js/hcalendar.js b/hotel_calendar/static/src/lib/hcalendar/js/hcalendar.js index b8ca0eaa2..17c77d2b5 100644 --- a/hotel_calendar/static/src/lib/hcalendar/js/hcalendar.js +++ b/hotel_calendar/static/src/lib/hcalendar/js/hcalendar.js @@ -177,11 +177,15 @@ HotelCalendar.prototype = { this._divideDivs[1].remove(); this._divideDivs = false; } + this._reset_action_reservation(); } if (this._selectionMode === HotelCalendar.ACTION.UNIFY) { this.reservationAction.action = HotelCalendar.ACTION.UNIFY; this.reservationAction.toUnify = []; + } else { + this._reset_action_reservation(); + this._updateHighlightUnifyReservations(); } this._dispatchEvent('hcalOnChangeSelectionMode', { @@ -1488,7 +1492,7 @@ HotelCalendar.prototype = { for (var elm of elms) { elm.classList.remove('hcal-reservation-unify-selected'); } } else { - var dateLimits = this.getDateLimits(this.reservationAction.toUnify); + var dateLimits = this.getDateLimits(this.reservationAction.toUnify, false); var refUnifyReservation = this.reservationAction.toUnify[0]; var uniRoom = refUnifyReservation?refUnifyReservation.room.id:false; for (var nreserv of this._reservations) { @@ -1519,7 +1523,7 @@ HotelCalendar.prototype = { for (var elm of elms) { elm.classList.remove('hcal-reservation-swap-out-selected'); } } else { - var dateLimits = this.getDateLimits(this.reservationAction.inReservations); + var dateLimits = this.getDateLimits(this.reservationAction.inReservations, true); var refInReservation = this.reservationAction.inReservations[0]; var refOutReservation = this.reservationAction.outReservations[0]; var inCapacity = refInReservation?refInReservation.room.capacity:false; @@ -1546,7 +1550,7 @@ HotelCalendar.prototype = { } } // Invalid reservations out of dates - else if (nreserv.startDate.isBefore(realDateLimits[0], 'day') || nreserv.endDate.isAfter(realDateLimits[1], 'day')) { + else if (nreserv.startDate.isBefore(realDateLimits[0], 'day') || nreserv.endDate.clone().subtract('1', 'd').isAfter(realDateLimits[1], 'day')) { if (nreserv.room.id !== refInReservation.room.id) { nreserv._html.classList.add('hcal-reservation-invalid-swap'); } @@ -1781,9 +1785,9 @@ HotelCalendar.prototype = { console.warn("[HotelCalendar][swapReservations] Invalid Swap Operation!"); return false; } - var fromDateLimits = this.getDateLimits(fromReservations); + var fromDateLimits = this.getDateLimits(fromReservations, true); var fromRealDateLimits = this.getFreeDatesByRoom(fromDateLimits[0], fromDateLimits[1], fromReservations[0].room.id); - var toDateLimits = this.getDateLimits(toReservations); + var toDateLimits = this.getDateLimits(toReservations, true); var toRealDateLimits = this.getFreeDatesByRoom(toDateLimits[0], toDateLimits[1], toReservations[0].room.id); if (fromDateLimits[0].clone().local().isSameOrAfter(toRealDateLimits[0].clone().local(), 'd') && fromDateLimits[1].clone().local().isSameOrBefore(toRealDateLimits[1].clone().local(), 'd') && @@ -1839,12 +1843,12 @@ HotelCalendar.prototype = { nreserv.room = refFromRoom; } - if (this.options.divideRoomsByCapacity) { - var allReservs = toReservations.concat(fromReservations); - for (var nreserv of allReservs) { this._updateUnusedZones(nreserv); } - } + // if (this.options.divideRoomsByCapacity) { + // var allReservs = toReservations.concat(fromReservations); + // for (var nreserv of allReservs) { this._updateUnusedZones(nreserv); } + // } } else { - console.warn("[HotelCalendar][swapReservations] Invalid Swap Operation!"); + console.warn("[HotelCalendar][swapReservations] Invalid Swap Operation!"); return false; } @@ -1940,7 +1944,7 @@ HotelCalendar.prototype = { // MODE UNIFY RESERVATIONS if ($this._selectionMode === HotelCalendar.ACTION.UNIFY) { var reserv = $this.getReservation(this.dataset.hcalReservationObjId); - var dateLimits = $this.getDateLimits($this.reservationAction.toUnify); + var dateLimits = $this.getDateLimits($this.reservationAction.toUnify, false); var refUnifyReserv = ($this.reservationAction.toUnify.length > 0)?$this.reservationAction.toUnify[0]:false; if ($this.reservationAction.toUnify.indexOf(reserv) != -1) { $this.reservationAction.toUnify = _.reject($this.reservationAction.toUnify, function(item){ return item === reserv}); @@ -2066,21 +2070,6 @@ HotelCalendar.prototype = { return HotelCalendar.ACTION.MOVE_ALL; }, - // _getRerservationPositionAction: function(/*HTMLObject*/elm, /*Int*/posX, /*Int*/posY) { - // var bounds = elm.getBoundingClientRect(); - // var mouseActMargin = 10*bounds.width*0.01; - // console.log("------- Esta aiki"); - // console.log(posX); - // var ppOsX = posX - posX*(1.0-window.devicePixelRatio); - // posX -= ppOsX; - // console.log(posX); - // var mouseActMarginV = (10*bounds.width)/100; - // //debugger; - // if (posX <= mouseActMargin) { return HotelCalendar.ACTION.MOVE_LEFT; } - // else if (posX >= bounds.width-mouseActMargin) { return HotelCalendar.ACTION.MOVE_RIGHT; } - // return HotelCalendar.ACTION.MOVE_ALL; - // }, - _cleanUnusedZones: function(/*HReservationObject*/reserv) { var reservs = _.filter(this._reservations, function(item){ return item.unusedZone && item.linkedId === reserv.id; }); for (var creserv of reservs) { this.removeReservation(creserv); } @@ -2267,17 +2256,21 @@ HotelCalendar.prototype = { return end_date.diff(start_date, 'days'); }, - getDateLimits: function(/*List HReservationObject*/reservs) { + getDateLimits: function(/*List HReservationObject*/reservs, /*Bool?*/noCheckouts) { var start_date = false; var end_date = false; for (var creserv of reservs) { - if (!start_date) { start_date = creserv.startDate; } + if (!start_date) { start_date = creserv.startDate.clone(); } else if (creserv.startDate.isBefore(start_date, 'day')) { - start_date = creserv.startDate; + start_date = creserv.startDate.clone(); } - if (!end_date) { end_date = creserv.endDate; } + if (!end_date) { end_date = creserv.endDate.clone(); } else if (creserv.endDate.isAfter(end_date, 'day')) { - end_date = creserv.endDate; + end_date = creserv.endDate.clone(); + } + + if (noCheckouts) { + end_date.subtract(1, 'd'); } } @@ -2289,17 +2282,19 @@ HotelCalendar.prototype = { var daysRight = this.getDateDiffDays(dateEnd, this._endDate); var freeDates = [dateStart, dateEnd]; + var ndate = dateStart.clone(); for (var i=1; i