mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[WIP] filter all calendar data by hotel
This commit is contained in:
@@ -8,8 +8,14 @@ from odoo.exceptions import ValidationError
|
|||||||
class HotelCalendar(models.Model):
|
class HotelCalendar(models.Model):
|
||||||
_name = 'hotel.calendar'
|
_name = 'hotel.calendar'
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def _get_default_hotel(self):
|
||||||
|
return self.env.user.hotel_id
|
||||||
|
|
||||||
name = fields.Char('Name', required=True)
|
name = fields.Char('Name', required=True)
|
||||||
segmentation_ids = fields.Many2many('hotel.room.type.class', string='Segmentation')
|
segmentation_ids = fields.Many2many('hotel.room.type.class', string='Segmentation')
|
||||||
location_ids = fields.Many2many('hotel.floor', string='Location')
|
location_ids = fields.Many2many('hotel.floor', string='Location')
|
||||||
amenity_ids = fields.Many2many('hotel.amenity', string='Amenity')
|
amenity_ids = fields.Many2many('hotel.amenity', string='Amenity')
|
||||||
room_type_ids = fields.Many2many('hotel.room.type', string='Room Type')
|
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,)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import logging
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from odoo import models, fields, api, _
|
from odoo import models, fields, api, _
|
||||||
from odoo.models import operator
|
from odoo.models import operator
|
||||||
from odoo.exceptions import ValidationError
|
from odoo.exceptions import AccessError, ValidationError
|
||||||
from odoo.tools import DEFAULT_SERVER_DATE_FORMAT
|
from odoo.tools import DEFAULT_SERVER_DATE_FORMAT
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -69,6 +69,7 @@ class HotelReservation(models.Model):
|
|||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _hcalendar_reservation_data(self, reservations):
|
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_reservations = []
|
||||||
json_reservation_tooltips = {}
|
json_reservation_tooltips = {}
|
||||||
for reserv in reservations:
|
for reserv in reservations:
|
||||||
@@ -127,11 +128,11 @@ class HotelReservation(models.Model):
|
|||||||
'services': reserv['services'],
|
'services': reserv['services'],
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return (json_reservations, json_reservation_tooltips)
|
return (json_reservations, json_reservation_tooltips)
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _hcalendar_room_data(self, rooms):
|
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(
|
pricelist_id = self.env['ir.default'].sudo().get(
|
||||||
'res.config.settings', 'default_pricelist_id')
|
'res.config.settings', 'default_pricelist_id')
|
||||||
if pricelist_id:
|
if pricelist_id:
|
||||||
@@ -156,6 +157,7 @@ class HotelReservation(models.Model):
|
|||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _hcalendar_calendar_data(self, calendars):
|
def _hcalendar_calendar_data(self, calendars):
|
||||||
|
_logger.warning('_found [%s] calendars for hotel [%s]', len(calendars), self.env.user.hotel_id.id)
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
'id': calendar.id,
|
'id': calendar.id,
|
||||||
@@ -168,6 +170,7 @@ class HotelReservation(models.Model):
|
|||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _hcalendar_event_data(self, events):
|
def _hcalendar_event_data(self, events):
|
||||||
|
# TODO: Filter events by hotel
|
||||||
json_events = [
|
json_events = [
|
||||||
{
|
{
|
||||||
'id': event.id,
|
'id': event.id,
|
||||||
@@ -179,7 +182,10 @@ class HotelReservation(models.Model):
|
|||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def get_hcalendar_calendar_data(self):
|
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)
|
res = self._hcalendar_calendar_data(calendars)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
@@ -241,7 +247,11 @@ class HotelReservation(models.Model):
|
|||||||
if pricelist_id:
|
if pricelist_id:
|
||||||
pricelist_id = int(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)
|
dfrom_str = dfrom_dt.strftime(DEFAULT_SERVER_DATE_FORMAT)
|
||||||
dto_str = dto_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:
|
if restriction_id:
|
||||||
restriction_id = int(restriction_id)
|
restriction_id = int(restriction_id)
|
||||||
|
|
||||||
|
hotel_id = self.env.user.hotel_id.id
|
||||||
|
|
||||||
# Get Restrictions
|
# Get Restrictions
|
||||||
json_rooms_rests = {}
|
json_rooms_rests = {}
|
||||||
room_typed_ids = self.env['hotel.room.type'].search(
|
room_typed_ids = self.env['hotel.room.type'].search([], order='sequence ASC')
|
||||||
[],
|
|
||||||
order='sequence ASC')
|
|
||||||
room_type_rest_obj = self.env['hotel.room.type.restriction.item']
|
room_type_rest_obj = self.env['hotel.room.type.restriction.item']
|
||||||
rtype_rest_ids = room_type_rest_obj.search([
|
rtype_rest_ids = room_type_rest_obj.search([
|
||||||
|
('hotel_id', '=', hotel_id),
|
||||||
('room_type_id', 'in', room_typed_ids.ids),
|
('room_type_id', 'in', room_typed_ids.ids),
|
||||||
('date', '>=', dfrom_dt),
|
('date', '>=', dfrom_dt),
|
||||||
('date', '<=', dto_dt),
|
('date', '<=', dto_dt),
|
||||||
@@ -372,9 +384,19 @@ class HotelReservation(models.Model):
|
|||||||
if not dfrom or not dto:
|
if not dfrom or not dto:
|
||||||
raise ValidationError(_('Input Error: No dates defined!'))
|
raise ValidationError(_('Input Error: No dates defined!'))
|
||||||
|
|
||||||
|
hotel_id = self.env.user.hotel_id.id
|
||||||
|
|
||||||
dfrom_dt = fields.Date.from_string(dfrom)
|
dfrom_dt = fields.Date.from_string(dfrom)
|
||||||
dto_dt = fields.Date.from_string(dto)
|
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(
|
json_res, json_res_tooltips = self.get_hcalendar_reservations_data(
|
||||||
dfrom_dt, dto_dt, rooms)
|
dfrom_dt, dto_dt, rooms)
|
||||||
@@ -390,7 +412,6 @@ class HotelReservation(models.Model):
|
|||||||
'calendars': withRooms and self.get_hcalendar_calendar_data()
|
'calendars': withRooms and self.get_hcalendar_calendar_data()
|
||||||
or []
|
or []
|
||||||
}
|
}
|
||||||
|
|
||||||
return vals
|
return vals
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ from odoo import models, fields, api
|
|||||||
class ProductPricelist(models.Model):
|
class ProductPricelist(models.Model):
|
||||||
_inherit = 'product.pricelist'
|
_inherit = 'product.pricelist'
|
||||||
|
|
||||||
|
# TODO REVIEW: deprecated ?¿
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def update_price(self, room_type_id, date, price):
|
def update_price(self, room_type_id, date, price):
|
||||||
room_type = self.env['hotel.room.type'].browse(room_type_id)
|
room_type = self.env['hotel.room.type'].browse(room_type_id)
|
||||||
|
|||||||
@@ -69,39 +69,44 @@ return AbstractModel.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
get_room_types: function() {
|
get_room_types: function() {
|
||||||
|
var domain = [['hotel_id', '=', Session.user_hotels.current_hotel[0]]];
|
||||||
return this._rpc({
|
return this._rpc({
|
||||||
model: 'hotel.room.type',
|
model: 'hotel.room.type',
|
||||||
method: 'search_read',
|
method: 'search_read',
|
||||||
args: [false, ['id','name']],
|
args: [domain, ['id','name']],
|
||||||
context: Session.user_context,
|
context: Session.user_context,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
get_floors: function() {
|
get_floors: function() {
|
||||||
|
var domain = [['hotel_ids', 'in', Session.user_hotels.current_hotel[0]]];
|
||||||
return this._rpc({
|
return this._rpc({
|
||||||
model: 'hotel.floor',
|
model: 'hotel.floor',
|
||||||
method: 'search_read',
|
method: 'search_read',
|
||||||
args: [false, ['id','name']],
|
args: [domain, ['id','name']],
|
||||||
context: Session.user_context,
|
context: Session.user_context,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
get_amenities: function() {
|
get_amenities: function() {
|
||||||
|
var domain = [['hotel_ids', 'in', Session.user_hotels.current_hotel[0]]];
|
||||||
return this._rpc({
|
return this._rpc({
|
||||||
model: 'hotel.amenity',
|
model: 'hotel.amenity',
|
||||||
method: 'search_read',
|
method: 'search_read',
|
||||||
args: [false, ['id','name']],
|
args: [domain, ['id','name']],
|
||||||
context: Session.user_context,
|
context: Session.user_context,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
get_room_type_class: function() {
|
get_room_type_class: function() {
|
||||||
|
var domain = [['hotel_ids', 'in', Session.user_hotels.current_hotel[0]]];
|
||||||
return this._rpc({
|
return this._rpc({
|
||||||
model: 'hotel.room.type.class',
|
model: 'hotel.room.type.class',
|
||||||
method: 'search_read',
|
method: 'search_read',
|
||||||
args: [false, ['id','name']],
|
args: [domain, ['id','name']],
|
||||||
context: Session.user_context,
|
context: Session.user_context,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
search_count: function(domain) {
|
search_count: function(domain) {
|
||||||
|
// TODO: add hotel_id domain based on modelName
|
||||||
return this._rpc({
|
return this._rpc({
|
||||||
model: this.modelName,
|
model: this.modelName,
|
||||||
method: 'search_count',
|
method: 'search_count',
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
<sheet>
|
<sheet>
|
||||||
<group>
|
<group>
|
||||||
<field name="name" />
|
<field name="name" />
|
||||||
|
<field name="hotel_id" invisible="0"/>
|
||||||
</group>
|
</group>
|
||||||
<group>
|
<group>
|
||||||
<field name="segmentation_ids" />
|
<field name="segmentation_ids" />
|
||||||
@@ -28,6 +29,7 @@
|
|||||||
<field name="model">hotel.calendar</field>
|
<field name="model">hotel.calendar</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<tree string="Hotel Calendar">
|
<tree string="Hotel Calendar">
|
||||||
|
<field name="hotel_id" />
|
||||||
<field name="name" />
|
<field name="name" />
|
||||||
</tree>
|
</tree>
|
||||||
</field>
|
</field>
|
||||||
|
|||||||
Reference in New Issue
Block a user