[WIP][MIG][11.0] Hotel Improvements + Hotel Calendar

This commit is contained in:
QS5ELkMu
2018-09-06 00:06:37 +02:00
parent 0c7b3edd77
commit 52562f7341
70 changed files with 509 additions and 533 deletions

View File

@@ -60,7 +60,7 @@ return AbstractModel.extend({
return this._rpc({
model: 'hotel.room.type',
method: 'search_read',
args: [false, ['cat_id','name']],
args: [false, ['id','name']],
context: Session.user_context,
});
},

View File

@@ -71,7 +71,7 @@ var MPMSCalendarController = AbstractController.extend({
self.renderer._days_tooltips = results['events'];
var rooms = [];
for (var r of results['rooms']) {
var nroom = new HVRoom(
var nroom = new HRoomType(
r[0], // Id
r[1], // Name
r[2], // Capacity
@@ -112,15 +112,15 @@ var MPMSCalendarController = AbstractController.extend({
switch (notif[1]['type']) {
case 'availability':
var avail = notif[1]['availability'];
var vroom = Object.keys(avail)[0];
var day = Object.keys(avail[vroom])[0];
var room_type = Object.keys(avail)[0];
var day = Object.keys(avail[room_type])[0];
var dt = HotelCalendarManagement.toMoment(day);
var availability = {};
availability[vroom] = [{
availability[room_type] = [{
'date': dt.format(ODOO_DATE_MOMENT_FORMAT),
'avail': avail[vroom][day][0],
'no_ota': avail[vroom][day][1],
'id': avail[vroom][day][2]
'avail': avail[room_type][day][0],
'no_ota': avail[room_type][day][1],
'id': avail[room_type][day][2]
}];
this.renderer._hcalendar.addAvailability(availability);
break;
@@ -143,22 +143,22 @@ var MPMSCalendarController = AbstractController.extend({
this.renderer._hcalendar.addPricelist(pr);
break;
case 'restriction':
// FIXME: Expected one day and one vroom
// FIXME: Expected one day and one room_type
var restriction = notif[1]['restriction'];
var vroom = Object.keys(restriction)[0];
var day = Object.keys(restriction[vroom])[0];
var room_type = Object.keys(restriction)[0];
var day = Object.keys(restriction[room_type])[0];
var dt = HotelCalendarManagement.toMoment(day);
var rest = {};
rest[vroom] = [{
rest[room_type] = [{
'date': dt.format(ODOO_DATE_MOMENT_FORMAT),
'min_stay': restriction[vroom][day][0],
'min_stay_arrival': restriction[vroom][day][1],
'max_stay': restriction[vroom][day][2],
'max_stay_arrival': restriction[vroom][day][3],
'closed': restriction[vroom][day][4],
'closed_arrival': restriction[vroom][day][5],
'closed_departure': restriction[vroom][day][6],
'id': restriction[vroom][day][7]
'min_stay': restriction[room_type][day][0],
'min_stay_arrival': restriction[room_type][day][1],
'max_stay': restriction[room_type][day][2],
'max_stay_arrival': restriction[room_type][day][3],
'closed': restriction[room_type][day][4],
'closed_arrival': restriction[room_type][day][5],
'closed_departure': restriction[room_type][day][6],
'id': restriction[room_type][day][7]
}];
this.renderer._hcalendar.addRestrictions(rest);
break;

View File

@@ -132,7 +132,7 @@ var HotelCalendarManagementView = AbstractRenderer.extend({
this._hcalendar = new HotelCalendarManagement('#hcal_management_widget', options, this.$el[0]);
this._assignHCalendarEvents();
this.$CalendarHeaderDays = this.$el.find("div.table-vroom-data-header");
this.$CalendarHeaderDays = this.$el.find("div.table-room_type-data-header");
// Sticky Header Days
this.$ehcal.scroll(this._on_scroll.bind(this));
@@ -409,7 +409,7 @@ var HotelCalendarManagementView = AbstractRenderer.extend({
self._assign_extra_info();
});
this._last_dates = params['dates'];
this.$CalendarHeaderDays = this.$el.find("div.table-vroom-data-header");
this.$CalendarHeaderDays = this.$el.find("div.table-room_type-data-header");
this._on_scroll(); // FIXME: Workaround for update sticky header
},

View File

@@ -173,7 +173,7 @@ var HotelCalendarManagementView = View.extend({
}
});
this.$CalendarHeaderDays = this.$el.find("div.table-vroom-data-header");
this.$CalendarHeaderDays = this.$el.find("div.table-room_type-data-header");
// Sticky Header Days
this.$ehcal.scroll(this._on_scroll.bind(this));
@@ -204,7 +204,7 @@ var HotelCalendarManagementView = View.extend({
self._days_tooltips = results['events'];
var rooms = [];
for (var r of results['rooms']) {
var nroom = new HVRoom(
var nroom = new HRoomType(
r[0], // Id
r[1], // Name
r[2], // Capacity
@@ -478,15 +478,15 @@ var HotelCalendarManagementView = View.extend({
switch (notif[1]['type']) {
case 'availability':
var avail = notif[1]['availability'];
var vroom = Object.keys(avail)[0];
var day = Object.keys(avail[vroom])[0];
var room_type = Object.keys(avail)[0];
var day = Object.keys(avail[room_type])[0];
var dt = HotelCalendarManagement.toMoment(day);
var availability = {};
availability[vroom] = [{
availability[room_type] = [{
'date': dt.format(ODOO_DATE_MOMENT_FORMAT),
'avail': avail[vroom][day][0],
'no_ota': avail[vroom][day][1],
'id': avail[vroom][day][2]
'avail': avail[room_type][day][0],
'no_ota': avail[room_type][day][1],
'id': avail[room_type][day][2]
}];
this._hcalendar.addAvailability(availability);
break;
@@ -509,22 +509,22 @@ var HotelCalendarManagementView = View.extend({
this._hcalendar.addPricelist(pr);
break;
case 'restriction':
// FIXME: Expected one day and one vroom
// FIXME: Expected one day and one room_type
var restriction = notif[1]['restriction'];
var vroom = Object.keys(restriction)[0];
var day = Object.keys(restriction[vroom])[0];
var room_type = Object.keys(restriction)[0];
var day = Object.keys(restriction[room_type])[0];
var dt = HotelCalendarManagement.toMoment(day);
var rest = {};
rest[vroom] = [{
rest[room_type] = [{
'date': dt.format(ODOO_DATE_MOMENT_FORMAT),
'min_stay': restriction[vroom][day][0],
'min_stay_arrival': restriction[vroom][day][1],
'max_stay': restriction[vroom][day][2],
'max_stay_arrival': restriction[vroom][day][3],
'closed': restriction[vroom][day][4],
'closed_arrival': restriction[vroom][day][5],
'closed_departure': restriction[vroom][day][6],
'id': restriction[vroom][day][7]
'min_stay': restriction[room_type][day][0],
'min_stay_arrival': restriction[room_type][day][1],
'max_stay': restriction[room_type][day][2],
'max_stay_arrival': restriction[room_type][day][3],
'closed': restriction[room_type][day][4],
'closed_arrival': restriction[room_type][day][5],
'closed_departure': restriction[room_type][day][6],
'id': restriction[room_type][day][7]
}];
this._hcalendar.addRestrictions(rest);
break;
@@ -543,7 +543,7 @@ var HotelCalendarManagementView = View.extend({
self._assign_extra_info();
});
this._last_dates = params['dates'];
this.$CalendarHeaderDays = this.$el.find("div.table-vroom-data-header");
this.$CalendarHeaderDays = this.$el.find("div.table-room_type-data-header");
this._on_scroll(); // FIXME: Workaround for update sticky header
},

View File

@@ -690,8 +690,8 @@ HotelCalendar.prototype = {
},
addRestrictions: function(/*Object*/restrictions) {
var vroom_ids = Object.keys(restrictions);
for (var vid of vroom_ids) {
var room_type_ids = Object.keys(restrictions);
for (var vid of room_type_ids) {
if (vid in this._restrictions) {
this._restrictions[vid] = _.extend(this._restrictions[vid], restrictions[vid]);
}
@@ -1276,7 +1276,7 @@ HotelCalendar.prototype = {
row = tbody.insertRow();
row.setAttribute('id', this._sanitizeId(`ROW_DETAIL_PRICE_ROOM_${key}_${listitem.room}`));
row.dataset.hcalPricelist = key;
row.dataset.hcalVRoomId = listitem.room
row.dataset.hcalRoomTypeId = listitem.room
row.classList.add('hcal-row-detail-room-price-group-item');
cell = row.insertCell();
var span = document.createElement('span');
@@ -1306,7 +1306,7 @@ HotelCalendar.prototype = {
input.setAttribute('id', this._sanitizeId(`INPUT_PRICE_${key}_${listitem.room}_${dd_local.format(HotelCalendar.DATE_FORMAT_SHORT_)}`));
input.setAttribute('type', 'edit');
input.setAttribute('title', 'Price');
input.setAttribute('name', 'vroom_price_day');
input.setAttribute('name', 'room_type_price_day');
input.dataset.hcalParentCell = cell.getAttribute('id');
var dd_fmrt = dd_local.format(HotelCalendar.DATE_FORMAT_SHORT_);
input.dataset.orgValue = input.value = _.has(listitem['days'], dd_fmrt)?Number(listitem['days'][dd_fmrt]).toLocaleString():'...';
@@ -1335,8 +1335,8 @@ HotelCalendar.prototype = {
var orgValue = input.dataset.orgValue;
var parentCell = this.edtable.querySelector(`#${input.dataset.hcalParentCell}`);
var parentRow = this.edtable.querySelector(`#${parentCell.dataset.hcalParentRow}`);
if (!(parentRow.dataset.hcalVRoomId in data)) { data[parentRow.dataset.hcalVRoomId] = []; }
data[parentRow.dataset.hcalVRoomId].push({
if (!(parentRow.dataset.hcalRoomTypeId in data)) { data[parentRow.dataset.hcalRoomTypeId] = []; }
data[parentRow.dataset.hcalRoomTypeId].push({
'date': HotelCalendar.toMoment(parentCell.dataset.hcalDate).format('YYYY-MM-DD'),
'price': value
});
@@ -2107,13 +2107,13 @@ HotelCalendar.prototype = {
this._updatePriceList();
},
updateVRoomPrice: function(pricelist_id, vroom_id, date, price) {
updateRoomTypePrice: function(pricelist_id, room_type_id, date, price) {
var strDate = date.format(HotelCalendar.DATE_FORMAT_SHORT_);
var cellId = this._sanitizeId(`CELL_PRICE_${pricelist_id}_${vroom_id}_${strDate}`);
var cellId = this._sanitizeId(`CELL_PRICE_${pricelist_id}_${room_type_id}_${strDate}`);
var input = this.edtable.querySelector(`#${cellId} input`);
if (input) {
input.dataset.orgValue = input.value = price;
var pr_fk = _.findKey(this._pricelist[pricelist_id], {'room': vroom_id});
var pr_fk = _.findKey(this._pricelist[pricelist_id], {'room': room_type_id});
this._pricelist[pricelist_id][pr_fk].days[strDate] = price;
}
},
@@ -2289,7 +2289,7 @@ HotelCalendar.prototype = {
var orgValue = elm.dataset.orgValue;
var name = elm.getAttribute('name');
if (name === 'vroom_price_day') {
if (name === 'room_type_price_day') {
if (!this._isNumeric(value)) {
elm.style.backgroundColor = 'red';
} else if (orgValue !== value) {
@@ -2306,13 +2306,13 @@ HotelCalendar.prototype = {
var parentCell = this.edtable.querySelector(`#${elm.dataset.hcalParentCell}`);
var parentRow = this.edtable.querySelector(`#${parentCell.dataset.hcalParentRow}`);
var vals = {
'vroom_id': +parentRow.dataset.hcalVRoomId,
'room_type_id': +parentRow.dataset.hcalRoomTypeId,
'date': HotelCalendar.toMoment(parentCell.dataset.hcalDate),
'price': value,
'old_price': orgValue,
'pricelist_id': +parentRow.dataset.hcalPricelist
};
//this.updateVRoomPrice(vals['pricelist_id'], vals['vroom_id'], vals['date'], vals['price']);
//this.updateRoomTypePrice(vals['pricelist_id'], vals['room_type_id'], vals['date'], vals['price']);
this._dispatchEvent('hcalOnPricelistChanged', vals);
if (this.edivc.querySelector('.hcal-input-changed') !== null)

View File

@@ -74,7 +74,7 @@ function HotelCalendarManagement(/*String*/querySelector, /*Dictionary*/options,
};
// Check correct values
if (this.options.rooms.length > 0 && !(this.options.rooms[0] instanceof HVRoom)) {
if (this.options.rooms.length > 0 && !(this.options.rooms[0] instanceof HRoomType)) {
this.options.rooms = [];
console.warn("[Hotel Calendar Management][init] Invalid Room definiton!");
}
@@ -397,9 +397,9 @@ HotelCalendarManagement.prototype = {
this.e.removeChild(this.e.lastChild);
}
// VRoom Names
// RoomType Names
this.edivrhl = document.createElement("div");
this.edivrhl.classList.add('table-vrooms');
this.edivrhl.classList.add('table-room_types');
this.e.appendChild(this.edivrhl);
this.etableRooms = document.createElement("table");
this.etableRooms.classList.add('hcal-management-table');
@@ -412,7 +412,7 @@ HotelCalendarManagement.prototype = {
this.e.appendChild(this.edivm);
// Days
this.edivrh = document.createElement("div");
this.edivrh.classList.add('table-vroom-data-header');
this.edivrh.classList.add('table-room_type-data-header');
this.edivm.appendChild(this.edivrh);
this.etableHeader = document.createElement("table");
this.etableHeader.classList.add('hcal-management-table');
@@ -420,7 +420,7 @@ HotelCalendarManagement.prototype = {
this.edivrh.appendChild(this.etableHeader);
// Data
this.edivr = document.createElement("div");
this.edivr.classList.add('table-vroom-data');
this.edivr.classList.add('table-room_type-data');
this.edivm.appendChild(this.edivr);
this.etable = document.createElement("table");
this.etable.classList.add('hcal-management-table');
@@ -503,8 +503,8 @@ HotelCalendarManagement.prototype = {
//==== PRICELIST
addPricelist: function(/*Object*/pricelist) {
var vroom_ids = Object.keys(pricelist);
for (var vid of vroom_ids) {
var room_type_ids = Object.keys(pricelist);
for (var vid of room_type_ids) {
if (vid in this._pricelist) {
for (var price of pricelist[vid]) {
var index = _.findIndex(this._pricelist[vid], {date: price['date']});
@@ -524,10 +524,10 @@ HotelCalendarManagement.prototype = {
_updatePriceList: function() {
var keys = Object.keys(this._pricelist);
for (var vroomId of keys) {
for (var price of this._pricelist[vroomId]) {
for (var room_typeId of keys) {
for (var price of this._pricelist[room_typeId]) {
var dd = HotelCalendarManagement.toMoment(price.date, this.options.dateFormatShort);
var inputId = this._sanitizeId(`PRICE_${vroomId}_${dd.format(HotelCalendarManagement._DATE_FORMAT_SHORT)}`);
var inputId = this._sanitizeId(`PRICE_${room_typeId}_${dd.format(HotelCalendarManagement._DATE_FORMAT_SHORT)}`);
var input = this.etable.querySelector(`#${inputId}`);
if (input && !input.classList.contains('hcal-management-input-changed')) {
input.dataset.orgValue = price.price;
@@ -559,8 +559,8 @@ HotelCalendarManagement.prototype = {
//==== RESTRICTIONS
addRestrictions: function(/*Object*/restrictions) {
var vroom_ids = Object.keys(restrictions);
for (var vid of vroom_ids) {
var room_type_ids = Object.keys(restrictions);
for (var vid of room_type_ids) {
if (vid in this._restrictions) {
for (var rest of restrictions[vid]) {
var index = _.findIndex(this._restrictions[vid], {date: rest['date']});
@@ -580,15 +580,15 @@ HotelCalendarManagement.prototype = {
_updateRestrictions: function() {
var keys = Object.keys(this._restrictions);
for (var vroomId of keys) {
var room = this.getRoom(vroomId);
for (var restriction of this._restrictions[vroomId]) {
for (var room_typeId of keys) {
var room = this.getRoom(room_typeId);
for (var restriction of this._restrictions[room_typeId]) {
var dd = HotelCalendarManagement.toMoment(restriction.date, this.options.dateFormatShort);
var inputIds = [
this._sanitizeId(`MIN_STAY_${vroomId}_${dd.format(HotelCalendarManagement._DATE_FORMAT_SHORT)}`), restriction.min_stay,
this._sanitizeId(`MIN_STAY_ARRIVAL_${vroomId}_${dd.format(HotelCalendarManagement._DATE_FORMAT_SHORT)}`), restriction.min_stay_arrival,
this._sanitizeId(`MAX_STAY_${vroomId}_${dd.format(HotelCalendarManagement._DATE_FORMAT_SHORT)}`), restriction.max_stay,
this._sanitizeId(`MAX_STAY_ARRIVAL_${vroomId}_${dd.format(HotelCalendarManagement._DATE_FORMAT_SHORT)}`), restriction.max_stay_arrival,
this._sanitizeId(`MIN_STAY_${room_typeId}_${dd.format(HotelCalendarManagement._DATE_FORMAT_SHORT)}`), restriction.min_stay,
this._sanitizeId(`MIN_STAY_ARRIVAL_${room_typeId}_${dd.format(HotelCalendarManagement._DATE_FORMAT_SHORT)}`), restriction.min_stay_arrival,
this._sanitizeId(`MAX_STAY_${room_typeId}_${dd.format(HotelCalendarManagement._DATE_FORMAT_SHORT)}`), restriction.max_stay,
this._sanitizeId(`MAX_STAY_ARRIVAL_${room_typeId}_${dd.format(HotelCalendarManagement._DATE_FORMAT_SHORT)}`), restriction.max_stay_arrival,
];
for (var i=0; i<inputIds.length; i+=2) {
var inputItem = this.etable.querySelector(`#${inputIds[i]}`);
@@ -598,7 +598,7 @@ HotelCalendarManagement.prototype = {
}
}
var inputClousureId = this._sanitizeId(`CLOUSURE_${vroomId}_${dd.format(HotelCalendarManagement._DATE_FORMAT_SHORT)}`);
var inputClousureId = this._sanitizeId(`CLOUSURE_${room_typeId}_${dd.format(HotelCalendarManagement._DATE_FORMAT_SHORT)}`);
var inputClousure = this.etable.querySelector(`#${inputClousureId}`);
if (inputClousure && !inputClousure.classList.contains('hcal-management-input-changed')) {
inputClousure.dataset.orgValue = inputClousure.value = (restriction.closed && 'closed') ||
@@ -651,11 +651,11 @@ HotelCalendarManagement.prototype = {
//==== FREE Rooms
_updateNumFreeRooms: function() {
var keys = Object.keys(this._free_rooms);
for (var vroomId of keys) {
for (var fnroom of this._free_rooms[vroomId]) {
for (var room_typeId of keys) {
for (var fnroom of this._free_rooms[room_typeId]) {
var dd = HotelCalendarManagement.toMoment(fnroom.date, this.options.dateFormatShort);
var inputIds = [
`FREE_ROOMS_${vroomId}_${dd.format(HotelCalendarManagement._DATE_FORMAT_SHORT)}`, fnroom.num,
`FREE_ROOMS_${room_typeId}_${dd.format(HotelCalendarManagement._DATE_FORMAT_SHORT)}`, fnroom.num,
];
for (var i=0; i<inputIds.length; i+=2) {
@@ -671,8 +671,8 @@ HotelCalendarManagement.prototype = {
//==== AVAILABILITY
addAvailability: function(/*Object*/availability) {
var vroom_ids = Object.keys(availability);
for (var vid of vroom_ids) {
var room_type_ids = Object.keys(availability);
for (var vid of room_type_ids) {
if (vid in this._availability) {
for (var avail of availability[vid]) {
var index = _.findIndex(this._availability[vid], {date: avail['date']});
@@ -692,12 +692,12 @@ HotelCalendarManagement.prototype = {
_updateAvailability: function() {
var keys = Object.keys(this._availability);
for (var vroomId of keys) {
for (var avail of this._availability[vroomId]) {
for (var room_typeId of keys) {
for (var avail of this._availability[room_typeId]) {
var dd = HotelCalendarManagement.toMoment(avail.date, this.options.dateFormatShort);
var inputIds = [
`AVAIL_${vroomId}_${dd.format(HotelCalendarManagement._DATE_FORMAT_SHORT)}`, avail.avail,
`NO_OTA_${vroomId}_${dd.format(HotelCalendarManagement._DATE_FORMAT_SHORT)}`, avail.no_ota
`AVAIL_${room_typeId}_${dd.format(HotelCalendarManagement._DATE_FORMAT_SHORT)}`, avail.avail,
`NO_OTA_${room_typeId}_${dd.format(HotelCalendarManagement._DATE_FORMAT_SHORT)}`, avail.no_ota
];
for (var i=0; i<inputIds.length; i+=2) {
@@ -1062,7 +1062,7 @@ HotelCalendarManagement.toMoment = function(/*String,MomentObject*/ndate, /*Stri
/** ROOM OBJECT **/
function HVRoom(/*Int*/id, /*String*/name, /*Int*/capacity, /*Float*/price) {
function HRoomType(/*Int*/id, /*String*/name, /*Int*/capacity, /*Float*/price) {
this.id = id || -1;
this.name = name;
this.capacity = capacity;
@@ -1070,7 +1070,7 @@ function HVRoom(/*Int*/id, /*String*/name, /*Int*/capacity, /*Float*/price) {
this.userData_ = {};
}
HVRoom.prototype = {
HRoomType.prototype = {
clearUserData: function() { this.userData_ = {}; },
getUserData: function(/*String?*/key) {
if (typeof key === 'undefined') {
@@ -1080,7 +1080,7 @@ HVRoom.prototype = {
},
addUserData: function(/*Dictionary*/data) {
if (!_.isObject(data)) {
console.warn("[Hotel Calendar Management][HVRoom][setUserData] Invalid Data! Need be a object!");
console.warn("[Hotel Calendar Management][HRoomType][setUserData] Invalid Data! Need be a object!");
} else {
this.userData_ = _.extend(this.userData_, data);
}