mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[WIP] Manage multihotel and multicompany
This commit is contained in:
@@ -15,3 +15,6 @@ class HotelProperty(models.Model):
|
|||||||
company_id = fields.Many2one('res.company', help='The company that owns or operates this hotel.')
|
company_id = fields.Many2one('res.company', help='The company that owns or operates this hotel.')
|
||||||
user_ids = fields.Many2many('res.users', 'hotel_property_users_rel', 'hotel_id', 'user_id',
|
user_ids = fields.Many2many('res.users', 'hotel_property_users_rel', 'hotel_id', 'user_id',
|
||||||
string='Accepted Users')
|
string='Accepted Users')
|
||||||
|
|
||||||
|
room_type_ids = fields.One2many('hotel.room.type', 'hotel_id', 'Room Types')
|
||||||
|
room_ids = fields.One2many('hotel.room', 'hotel_id', 'Room')
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
from odoo import models, fields, api, _
|
from odoo import models, fields, api, _
|
||||||
from odoo.exceptions import ValidationError
|
from odoo.exceptions import ValidationError
|
||||||
|
|
||||||
|
|
||||||
class HotelRoom(models.Model):
|
class HotelRoom(models.Model):
|
||||||
""" The rooms for lodging can be for sleeping, usually called rooms, and also
|
""" The rooms for lodging can be for sleeping, usually called rooms, and also
|
||||||
for speeches (conference rooms), parking, relax with cafe con leche, spa...
|
for speeches (conference rooms), parking, relax with cafe con leche, spa...
|
||||||
@@ -13,6 +14,10 @@ class HotelRoom(models.Model):
|
|||||||
_description = 'Hotel Room'
|
_description = 'Hotel Room'
|
||||||
_order = "sequence, room_type_id, name"
|
_order = "sequence, room_type_id, name"
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def _get_default_hotel(self):
|
||||||
|
return self.env.user.hotel_id
|
||||||
|
|
||||||
name = fields.Char('Room Name', required=True)
|
name = fields.Char('Room Name', required=True)
|
||||||
active = fields.Boolean('Active', default=True)
|
active = fields.Boolean('Active', default=True)
|
||||||
sequence = fields.Integer('Sequence', default=0)
|
sequence = fields.Integer('Sequence', default=0)
|
||||||
@@ -21,6 +26,9 @@ class HotelRoom(models.Model):
|
|||||||
ondelete='restrict')
|
ondelete='restrict')
|
||||||
floor_id = fields.Many2one('hotel.floor', 'Ubication',
|
floor_id = fields.Many2one('hotel.floor', 'Ubication',
|
||||||
help='At which floor the room is located.')
|
help='At which floor the room is located.')
|
||||||
|
hotel_id = fields.Many2one('hotel.property', 'Hotel', required=True, ondelete='restrict',
|
||||||
|
default=_get_default_hotel,)
|
||||||
|
|
||||||
max_adult = fields.Integer('Max Adult')
|
max_adult = fields.Integer('Max Adult')
|
||||||
max_child = fields.Integer('Max Child')
|
max_child = fields.Integer('Max Child')
|
||||||
capacity = fields.Integer('Capacity')
|
capacity = fields.Integer('Capacity')
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
from odoo import models, fields, api, _
|
from odoo import models, fields, api, _
|
||||||
from odoo.exceptions import ValidationError
|
from odoo.exceptions import ValidationError
|
||||||
|
|
||||||
|
|
||||||
class HotelRoomType(models.Model):
|
class HotelRoomType(models.Model):
|
||||||
""" Before creating a 'room type', you need to consider the following:
|
""" Before creating a 'room type', you need to consider the following:
|
||||||
With the term 'room type' is meant a sales type of residential accommodation: for
|
With the term 'room type' is meant a sales type of residential accommodation: for
|
||||||
@@ -13,6 +14,10 @@ class HotelRoomType(models.Model):
|
|||||||
_description = "Room Type"
|
_description = "Room Type"
|
||||||
_inherits = {'product.product': 'product_id'}
|
_inherits = {'product.product': 'product_id'}
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def _get_default_hotel(self):
|
||||||
|
return self.env.user.hotel_id
|
||||||
|
|
||||||
# Relationship between models
|
# Relationship between models
|
||||||
product_id = fields.Many2one('product.product', 'Product Room Type',
|
product_id = fields.Many2one('product.product', 'Product Room Type',
|
||||||
required=True, delegate=True,
|
required=True, delegate=True,
|
||||||
@@ -26,6 +31,8 @@ class HotelRoomType(models.Model):
|
|||||||
'room_type_ids', 'amenity_ids',
|
'room_type_ids', 'amenity_ids',
|
||||||
string='Room Type Amenities',
|
string='Room Type Amenities',
|
||||||
help='List of Amenities.')
|
help='List of Amenities.')
|
||||||
|
hotel_id = fields.Many2one('hotel.property', 'Hotel', required=True, ondelete='restrict',
|
||||||
|
default=_get_default_hotel,)
|
||||||
|
|
||||||
# TODO Hierarchical relationship for parent-child tree ?
|
# TODO Hierarchical relationship for parent-child tree ?
|
||||||
# parent_id = fields.Many2one ...
|
# parent_id = fields.Many2one ...
|
||||||
|
|||||||
@@ -2,8 +2,9 @@
|
|||||||
# Copyright 2019 Dario Lodeiros
|
# Copyright 2019 Dario Lodeiros
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from odoo import models
|
from odoo import models, _
|
||||||
from odoo.http import request
|
from odoo.http import request
|
||||||
|
from odoo.exceptions import MissingError
|
||||||
|
|
||||||
|
|
||||||
class IrHttp(models.AbstractModel):
|
class IrHttp(models.AbstractModel):
|
||||||
@@ -13,8 +14,17 @@ class IrHttp(models.AbstractModel):
|
|||||||
res = super().session_info()
|
res = super().session_info()
|
||||||
user = request.env.user
|
user = request.env.user
|
||||||
display_switch_hotel_menu = len(user.hotel_ids) > 1
|
display_switch_hotel_menu = len(user.hotel_ids) > 1
|
||||||
|
# TODO: limit hotels to the current company? or switch company automatically
|
||||||
res['hotel_id'] = request.env.user.hotel_id.id if request.session.uid else None
|
res['hotel_id'] = request.env.user.hotel_id.id if request.session.uid else None
|
||||||
res['user_hotels'] = {'current_hotel': (user.hotel_id.id, user.hotel_id.name),
|
res['user_hotels'] = {'current_hotel': (user.hotel_id.id, user.hotel_id.name),
|
||||||
'allowed_hotels': [(hotel.id, hotel.name) for hotel in
|
'allowed_hotels': [(hotel.id, hotel.name) for hotel in
|
||||||
user.hotel_ids]} if display_switch_hotel_menu else False
|
user.hotel_ids]} if display_switch_hotel_menu else False
|
||||||
|
if user.hotel_id.company_id in user.company_ids:
|
||||||
|
user.company_id = user.hotel_id.company_id
|
||||||
|
res['company_id'] = user.hotel_id.company_id.id
|
||||||
|
else:
|
||||||
|
raise MissingError(
|
||||||
|
_("Wrong hotel and company access settings for this user. "
|
||||||
|
"Please review hotel and company for user %s") % user.name)
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|||||||
@@ -66,6 +66,7 @@
|
|||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<tree string=" Hotel Room Type">
|
<tree string=" Hotel Room Type">
|
||||||
<field name="sequence" widget="handle"/>
|
<field name="sequence" widget="handle"/>
|
||||||
|
<field name="hotel_id" />
|
||||||
<field name="name" />
|
<field name="name" />
|
||||||
<field name="code_type"/>
|
<field name="code_type"/>
|
||||||
<field name="list_price"/>
|
<field name="list_price"/>
|
||||||
|
|||||||
@@ -126,6 +126,7 @@
|
|||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<tree string="Hotel Room">
|
<tree string="Hotel Room">
|
||||||
<field name="sequence" widget="handle"/>
|
<field name="sequence" widget="handle"/>
|
||||||
|
<field name="hotel_id"/>
|
||||||
<field name="name" />
|
<field name="name" />
|
||||||
<field name="room_type_id" />
|
<field name="room_type_id" />
|
||||||
<field name="capacity" />
|
<field name="capacity" />
|
||||||
|
|||||||
Reference in New Issue
Block a user