[WIP] Manage multihotel and multicompany

This commit is contained in:
Pablo
2019-07-19 11:47:51 +02:00
committed by Dario Lodeiros
parent 676e1b253f
commit 8f9b63d562
6 changed files with 31 additions and 1 deletions

View File

@@ -2,8 +2,9 @@
# Copyright 2019 Dario Lodeiros
# 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.exceptions import MissingError
class IrHttp(models.AbstractModel):
@@ -13,8 +14,17 @@ class IrHttp(models.AbstractModel):
res = super().session_info()
user = request.env.user
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['user_hotels'] = {'current_hotel': (user.hotel_id.id, user.hotel_id.name),
'allowed_hotels': [(hotel.id, hotel.name) for hotel in
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