[WIP] filter all calendar data by hotel

This commit is contained in:
Pablo
2019-08-05 19:17:20 +02:00
committed by Dario Lodeiros
parent 8e7b76baae
commit fa1ce8edda
5 changed files with 49 additions and 13 deletions

View File

@@ -8,8 +8,14 @@ from odoo.exceptions import ValidationError
class HotelCalendar(models.Model):
_name = 'hotel.calendar'
@api.model
def _get_default_hotel(self):
return self.env.user.hotel_id
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')
hotel_id = fields.Many2one('hotel.property', 'Hotel', required=True, ondelete='restrict',
default=_get_default_hotel,)

View File

@@ -4,7 +4,7 @@ import logging
from datetime import timedelta
from odoo import models, fields, api, _
from odoo.models import operator
from odoo.exceptions import ValidationError
from odoo.exceptions import AccessError, ValidationError
from odoo.tools import DEFAULT_SERVER_DATE_FORMAT
_logger = logging.getLogger(__name__)
@@ -69,6 +69,7 @@ class HotelReservation(models.Model):
@api.model
def _hcalendar_reservation_data(self, reservations):
_logger.warning('_found [%s] reservations for hotel [%s]', len(reservations), self.env.user.hotel_id.id)
json_reservations = []
json_reservation_tooltips = {}
for reserv in reservations:
@@ -127,11 +128,11 @@ class HotelReservation(models.Model):
'services': reserv['services'],
}
})
return (json_reservations, json_reservation_tooltips)
@api.model
def _hcalendar_room_data(self, rooms):
_logger.warning('_found [%s] rooms for hotel [%s]', len(rooms), self.env.user.hotel_id.id)
pricelist_id = self.env['ir.default'].sudo().get(
'res.config.settings', 'default_pricelist_id')
if pricelist_id:
@@ -156,6 +157,7 @@ class HotelReservation(models.Model):
@api.model
def _hcalendar_calendar_data(self, calendars):
_logger.warning('_found [%s] calendars for hotel [%s]', len(calendars), self.env.user.hotel_id.id)
return [
{
'id': calendar.id,
@@ -168,6 +170,7 @@ class HotelReservation(models.Model):
@api.model
def _hcalendar_event_data(self, events):
# TODO: Filter events by hotel
json_events = [
{
'id': event.id,
@@ -179,7 +182,10 @@ class HotelReservation(models.Model):
@api.model
def get_hcalendar_calendar_data(self):
calendars = self.env['hotel.calendar'].search([])
hotel_id = self.env.user.hotel_id.id
calendars = self.env['hotel.calendar'].search([
('hotel_id', '=', hotel_id)
])
res = self._hcalendar_calendar_data(calendars)
return res
@@ -241,7 +247,11 @@ class HotelReservation(models.Model):
if pricelist_id:
pricelist_id = int(pricelist_id)
room_types_ids = self.env['hotel.room.type'].search([])
hotel_id = self.env.user.hotel_id.id
room_types_ids = self.env['hotel.room.type'].search([
('hotel_id', '=', hotel_id)
])
dfrom_str = dfrom_dt.strftime(DEFAULT_SERVER_DATE_FORMAT)
dto_str = dto_dt.strftime(DEFAULT_SERVER_DATE_FORMAT)
@@ -296,13 +306,15 @@ class HotelReservation(models.Model):
if restriction_id:
restriction_id = int(restriction_id)
hotel_id = self.env.user.hotel_id.id
# Get Restrictions
json_rooms_rests = {}
room_typed_ids = self.env['hotel.room.type'].search(
[],
order='sequence ASC')
room_typed_ids = self.env['hotel.room.type'].search([], order='sequence ASC')
room_type_rest_obj = self.env['hotel.room.type.restriction.item']
rtype_rest_ids = room_type_rest_obj.search([
('hotel_id', '=', hotel_id),
('room_type_id', 'in', room_typed_ids.ids),
('date', '>=', dfrom_dt),
('date', '<=', dto_dt),
@@ -372,9 +384,19 @@ class HotelReservation(models.Model):
if not dfrom or not dto:
raise ValidationError(_('Input Error: No dates defined!'))
hotel_id = self.env.user.hotel_id.id
dfrom_dt = fields.Date.from_string(dfrom)
dto_dt = fields.Date.from_string(dto)
rooms = self.env['hotel.room'].search([], order='sequence ASC')
rooms = self.env['hotel.room'].search([
('hotel_id', '=', hotel_id)
], order='sequence ASC') or None
if not rooms:
raise AccessError(
_("Wrong hotel and company access settings for this user. "
"No rooms found for hotel %s") % self.env.user.hotel_id.name)
json_res, json_res_tooltips = self.get_hcalendar_reservations_data(
dfrom_dt, dto_dt, rooms)
@@ -390,7 +412,6 @@ class HotelReservation(models.Model):
'calendars': withRooms and self.get_hcalendar_calendar_data()
or []
}
return vals
@api.multi

View File

@@ -6,6 +6,8 @@ from odoo import models, fields, api
class ProductPricelist(models.Model):
_inherit = 'product.pricelist'
# TODO REVIEW: deprecated ?¿
@api.multi
def update_price(self, room_type_id, date, price):
room_type = self.env['hotel.room.type'].browse(room_type_id)

View File

@@ -69,39 +69,44 @@ return AbstractModel.extend({
},
get_room_types: function() {
var domain = [['hotel_id', '=', Session.user_hotels.current_hotel[0]]];
return this._rpc({
model: 'hotel.room.type',
method: 'search_read',
args: [false, ['id','name']],
args: [domain, ['id','name']],
context: Session.user_context,
});
},
get_floors: function() {
var domain = [['hotel_ids', 'in', Session.user_hotels.current_hotel[0]]];
return this._rpc({
model: 'hotel.floor',
method: 'search_read',
args: [false, ['id','name']],
args: [domain, ['id','name']],
context: Session.user_context,
});
},
get_amenities: function() {
var domain = [['hotel_ids', 'in', Session.user_hotels.current_hotel[0]]];
return this._rpc({
model: 'hotel.amenity',
method: 'search_read',
args: [false, ['id','name']],
args: [domain, ['id','name']],
context: Session.user_context,
});
},
get_room_type_class: function() {
var domain = [['hotel_ids', 'in', Session.user_hotels.current_hotel[0]]];
return this._rpc({
model: 'hotel.room.type.class',
method: 'search_read',
args: [false, ['id','name']],
args: [domain, ['id','name']],
context: Session.user_context,
});
},
search_count: function(domain) {
// TODO: add hotel_id domain based on modelName
return this._rpc({
model: this.modelName,
method: 'search_count',

View File

@@ -10,6 +10,7 @@
<sheet>
<group>
<field name="name" />
<field name="hotel_id" invisible="0"/>
</group>
<group>
<field name="segmentation_ids" />
@@ -28,6 +29,7 @@
<field name="model">hotel.calendar</field>
<field name="arch" type="xml">
<tree string="Hotel Calendar">
<field name="hotel_id" />
<field name="name" />
</tree>
</field>