[FIX] Getting books

This commit is contained in:
Alexandre Díaz
2019-01-14 18:51:49 +01:00
parent aee74efa54
commit 03ff5e3871
6 changed files with 63 additions and 48 deletions

View File

@@ -1,12 +1,10 @@
# Copyright 2018 Alexandre Díaz <dev@redneboa.es>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging
import time
from datetime import timedelta
from odoo import models, fields, api, _
from odoo.exceptions import ValidationError
from odoo.tools import DEFAULT_SERVER_DATE_FORMAT
from odoo.tools.profiler import profile
_logger = logging.getLogger(__name__)
@@ -179,7 +177,6 @@ class HotelReservation(models.Model):
def get_hcalendar_reservations_data(self, dfrom_dt, dto_dt, rooms):
rdfrom_dt = dfrom_dt + timedelta(days=1) # Ignore checkout
rdfrom_str = rdfrom_dt.strftime(DEFAULT_SERVER_DATE_FORMAT)
dfrom_str = dfrom_dt.strftime(DEFAULT_SERVER_DATE_FORMAT)
dto_str = dto_dt.strftime(DEFAULT_SERVER_DATE_FORMAT)
self.env.cr.execute('''
SELECT
@@ -201,11 +198,20 @@ class HotelReservation(models.Model):
LEFT JOIN product_template AS pt ON pp.product_tmpl_id = pt.id
LEFT JOIN res_partner AS rp ON hf.partner_id = rp.id
LEFT JOIN room_closure_reason as rcr ON hf.closure_reason_id = rcr.id
WHERE room_id IN %s AND ((checkin <= %s AND checkout >= %s) OR (checkin <= %s AND checkout >= %s) OR (checkin >= %s AND checkout <= %s))
WHERE room_id IN %s AND (
(checkin <= %s AND checkout >= %s AND checkout <= %s)
OR (checkin >= %s AND checkout <= %s)
OR (checkin >= %s AND checkin <= %s AND checkout >= %s)
OR (checkin <= %s AND checkout >= %s))
ORDER BY checkin DESC, checkout ASC, adults DESC, children DESC
''', (tuple(rooms.ids), dto_str, rdfrom_str, dfrom_str, dto_str, dfrom_str, dto_str))
''', (tuple(rooms.ids),
rdfrom_str, rdfrom_str, dto_str,
rdfrom_str, dto_str,
rdfrom_str, dto_str, dto_str,
rdfrom_str, dto_str))
return self._hcalendar_reservation_data(self.env.cr.dictfetchall())
# Expensive if no data in cache model
@api.model
def get_hcalendar_pricelist_data(self, dfrom_dt, dto_dt):
pricelist_id = self.env['ir.default'].sudo().get(

View File

@@ -22,8 +22,10 @@
}
#pms-menu {
padding: 0 0.2em !important;
overflow: auto;
background-color: #f8f8f8;
height: 100%;
padding: 0 2.5em;
}
#pms-menu .input-group span, #pms-menu input {
@@ -41,6 +43,32 @@
overflow: auto;
}
#pms-search {
position: fixed;
z-index: 9;
}
#hcal_widget {
max-height: 100%;
}
#multicalendar_panels {
background-color: white;
border-left: 1px solid #ddd;
}
.nav-tabs > li > a {
border-radius: 0;
}
.nav-tabs {
padding-top: 4px;
}
.navbar-default {
border-color: #f8f8f8;
}
button .led {
position: absolute;
display: inline-block;

View File

@@ -296,7 +296,6 @@ var PMSCalendarController = AbstractController.extend({
$(this).find('.led').removeClass('led-enabled');
}
active_calendar.addReservations(_.reject(self._multi_calendar._dataset['reservations'], {overbooking:false}));
_.defer(function(){ active_calendar._updateReservations(false); }); // Fix Possible Rows Displacements
});
this.renderer.$el.find('#pms-menu #btn_action_cancelled button').on('click', function(ev){
@@ -310,7 +309,6 @@ var PMSCalendarController = AbstractController.extend({
$(this).find('.led').removeClass('led-enabled');
}
active_calendar.addReservations(_.reject(self._multi_calendar._dataset['reservations'], {cancelled:false}));
_.defer(function(){ active_calendar._updateReservations(false); }); // Fix Possible Rows Displacements
});
this.renderer.$el.find('#pms-menu #btn_action_divide button').on('click', function(ev){

View File

@@ -53,7 +53,7 @@ var HotelCalendarView = AbstractRenderer.extend({
if (days === 'month') {
days = date_begin.daysInMonth();
}
var date_end = date_begin.clone().add(days+1, 'd');
var date_end = date_begin.clone().add(days, 'd');
return [date_begin, date_end];
},

View File

@@ -41,42 +41,15 @@
vertical-align: middle;
}
#pms-search {
position: fixed;
z-index: 9;
}
#pms-menu {
background-color: #f8f8f8;
height: 100%;
padding: 0 2.5em !important;
}
#hcal_widget {
max-height: 100%;
}
#multicalendar_panels {
background-color: white;
border-left: 1px solid #ddd;
}
.nav-tabs > li > a {
border-radius: 0;
}
.nav-tabs {
padding-top: 4px;
}
.navbar-default {
border-color: #f8f8f8;
}
#cal-pag-prev-plus, #cal-pag-prev, #cal-pag-selector, #cal-pag-next, #cal-pag-next-plus {
min-height: 0px;
}
.hcalendar-container {
display: flex;
flex-flow: column;
}
.table-reservations-header {
order: 1;
flex-grow: 1;
@@ -493,6 +466,7 @@ td.hcal-cell-room-type-group-item {
vertical-align: middle;
font-size: x-small;
white-space: nowrap;
text-overflow: ellipsis;
}
td.hcal-cell-room-type-group-item:last-child {
border-right-width: 2px;

View File

@@ -306,6 +306,7 @@ HotelCalendar.prototype = {
if (reservations.length > 0 && !(reservations[0] instanceof HReservation)) {
console.warn("[HotelCalendar][addReservations] Invalid Reservation definition!");
} else {
var isCalendarEmpty = (this._reservations.length>0);
// Merge
var addedReservations = [];
for (var r of reservations) {
@@ -317,6 +318,7 @@ HotelCalendar.prototype = {
continue;
}
var hasCreatedExtraRows = false;
r = r.clone(); // HOT-FIX: Multi-Calendar Support
r.room = this.getRoom(r.room_id, r.overbooking || r.cancelled, r.id);
// need create a overbooking row?
@@ -327,6 +329,7 @@ HotelCalendar.prototype = {
cancelled: r.cancelled,
});
this.createExtraRoomRow(r.room);
hasCreatedExtraRows = true;
} else {
console.warn(`Can't found the room '${r.room_id}' for the reservation '${r.id}' (${r.title})!`);
continue;
@@ -356,7 +359,7 @@ HotelCalendar.prototype = {
_.defer(function(reservs){
// Update offsets (New Rooms change positions?)
this._updateOffsets();
var unusedZones = this._createUnusedZones(reservs);
// Add Unused Zones
this._reservations = this._reservations.concat(unusedZones);
@@ -928,17 +931,21 @@ HotelCalendar.prototype = {
var scrollThrottle = _.throttle(this._updateOBIndicators.bind(this), 100);
this.edivcontainer = document.createElement("div");
this.edivcontainer.classList.add('hcalendar-container');
// Reservations Table
this.edivrh = document.createElement("div");
this.edivrh.classList.add('table-reservations-header');
this.e.appendChild(this.edivrh);
this.edivcontainer.appendChild(this.edivrh);
this.etableHeader = document.createElement("table");
this.etableHeader.classList.add('hcal-table');
this.etableHeader.classList.add('noselect');
this.edivrh.appendChild(this.etableHeader);
this.edivr = document.createElement("div");
this.edivr.classList.add('table-reservations');
this.e.appendChild(this.edivr);
this.edivcontainer.appendChild(this.edivr);
this.etable = document.createElement("table");
this.etable.classList.add('hcal-table');
this.etable.classList.add('noselect');
@@ -947,14 +954,14 @@ HotelCalendar.prototype = {
// Detail Calcs Table
this.edivch = document.createElement("div");
this.edivch.classList.add('table-calcs-header');
this.e.appendChild(this.edivch);
this.edivcontainer.appendChild(this.edivch);
this.edtableHeader = document.createElement("table");
this.edtableHeader.classList.add('hcal-table');
this.edtableHeader.classList.add('noselect');
this.edivch.appendChild(this.edtableHeader);
this.edivc = document.createElement("div");
this.edivc.classList.add('table-calcs');
this.e.appendChild(this.edivc);
this.edivcontainer.appendChild(this.edivc);
this.edtable = document.createElement("table");
this.edtable.classList.add('hcal-table');
this.edtable.classList.add('noselect');
@@ -965,6 +972,8 @@ HotelCalendar.prototype = {
});
observer.observe(this.edivr, { childList: true });
this.e.appendChild(this.edivcontainer);
this._updateView();
//_.defer(function(self){ self._updateView(); }, this);
this._tableCreated = true;
@@ -1444,7 +1453,7 @@ HotelCalendar.prototype = {
warnDiv.classList.add('hcal-warn-ob-indicator');
warnDiv.style.borderTopLeftRadius = warnDiv.style.borderTopRightRadius = "50px";
warnDiv.dataset.hcalReservationObjId = reserv.id;
this.e.appendChild(warnDiv);
this.edivcontainer.appendChild(warnDiv);
var warnComputedStyle = window.getComputedStyle(warnDiv, null);
warnDiv.style.top = `${mainBounds.height - eOffset.top - parseInt(warnComputedStyle.getPropertyValue("height"), 10)}px`;
warnDiv.style.left = `${(bounds.left + (bounds.right - bounds.left)/2.0 - parseInt(warnComputedStyle.getPropertyValue("width"), 10)/2.0) - mainBounds.left}px`;
@@ -1458,7 +1467,7 @@ HotelCalendar.prototype = {
warnDiv.style.borderBottomLeftRadius = warnDiv.style.borderBottomRightRadius = "50px";
warnDiv.style.top = `${mainBounds.top - eOffset.top}px`;
warnDiv.dataset.hcalReservationObjId = reserv.id;
this.e.appendChild(warnDiv);
this.edivcontainer.appendChild(warnDiv);
var warnComputedStyle = window.getComputedStyle(warnDiv, null);
warnDiv.style.left = `${(bounds.left + (bounds.right - bounds.left)/2.0 - parseInt(warnComputedStyle.getPropertyValue("width"), 10)/2.0) - mainBounds.left}px`;
}