forked from alaguraj/odoo-testing-addons
101 lines
4.1 KiB
Python
101 lines
4.1 KiB
Python
from odoo import http
|
|
from odoo.http import request
|
|
from odoo.addons.web.controllers.home import Home
|
|
|
|
class CustomHome(Home):
|
|
@http.route('/web/login', type='http', auth="public", website=True)
|
|
def web_login(self, *args, **kw):
|
|
response = super(CustomHome, self).web_login(*args, **kw)
|
|
if request.params.get('login_success') and request.session.uid:
|
|
return request.redirect('/')
|
|
return response
|
|
|
|
from odoo.addons.website.controllers.main import Website
|
|
|
|
class ImageHome(Website):
|
|
@http.route('/', type='http', auth='public', website=True, sitemap=True)
|
|
def index(self, **kwargs):
|
|
# Detection methods (any one is enough):
|
|
# 1. Sec-Fetch-Dest == 'iframe' → browser signals iframe load
|
|
# 2. enable_editor / edit param → explicit editor activation
|
|
# 3. path param → Odoo redirection to a specific page
|
|
# 4. Referer contains website/force → coming from editor switch
|
|
# -----------------------------------------------------------
|
|
fetch_dest = request.httprequest.headers.get('Sec-Fetch-Dest', '')
|
|
referer = request.httprequest.headers.get('Referer', '')
|
|
|
|
is_iframe = fetch_dest == 'iframe'
|
|
is_editor_param = any([
|
|
kwargs.get('enable_editor'),
|
|
request.params.get('enable_editor'),
|
|
kwargs.get('edit'),
|
|
request.params.get('edit'),
|
|
kwargs.get('path'),
|
|
request.params.get('path')
|
|
])
|
|
is_from_editor = '/website/force' in referer or 'enable_editor' in referer or '/web' in referer
|
|
|
|
# In Odoo, when we click "Edit", it often redirects to /?path=...
|
|
# If any editor signal is present, we must let the real website handle it.
|
|
if is_iframe or is_editor_param or is_from_editor:
|
|
return super(ImageHome, self).index(**kwargs)
|
|
|
|
# For public users (not logged in), always show the standard website homepage
|
|
if not request.session.uid:
|
|
return super(ImageHome, self).index(**kwargs)
|
|
|
|
# Remove sudo() to respect Odoo's standard menu group restrictions
|
|
menus = request.env['ir.ui.menu'].search([
|
|
('parent_id', '=', False)
|
|
], order='sequence')
|
|
|
|
# User role checks
|
|
try:
|
|
is_admin = request.env.user.has_group('base.group_system') or \
|
|
request.env.user.has_group('dine360_restaurant.group_restaurant_admin')
|
|
is_kitchen = request.env.user.has_group('dine360_restaurant.group_restaurant_kitchen')
|
|
except Exception:
|
|
is_admin = request.env.user.has_group('base.group_system')
|
|
is_kitchen = False
|
|
|
|
filtered_menus = []
|
|
seen_names = set()
|
|
for menu in menus:
|
|
# 1. Hide "Apps" for non-admins
|
|
if (menu.name == 'Apps' or (menu.web_icon and menu.web_icon.startswith('base,'))) and not is_admin:
|
|
continue
|
|
|
|
# 2. Hide "Kitchen (KDS)" for non-kitchen/non-admin users
|
|
if 'Kitchen' in menu.name or 'KDS' in menu.name:
|
|
if not (is_kitchen or is_admin):
|
|
continue
|
|
|
|
# 3. De-duplicate by name
|
|
if menu.name in seen_names:
|
|
continue
|
|
seen_names.add(menu.name)
|
|
|
|
filtered_menus.append(menu)
|
|
|
|
# Low Stock Alerts (Ingredients)
|
|
low_stock_products = []
|
|
try:
|
|
ProductTemplate = request.env['product.template'].sudo()
|
|
if hasattr(ProductTemplate, 'get_low_stock_products'):
|
|
low_stock_products = ProductTemplate.get_low_stock_products(limit=5)
|
|
except Exception:
|
|
low_stock_products = []
|
|
|
|
return request.render('dine360_dashboard.image_home_template', {
|
|
'menus': filtered_menus,
|
|
'user_id': request.env.user,
|
|
'low_stock_products': low_stock_products
|
|
})
|
|
|
|
|
|
|
|
@http.route('/home', type='http', auth="public", website=True, sitemap=True)
|
|
def website_home(self, **kw):
|
|
# Explicit route for standard Website Homepage
|
|
return request.render('website.homepage')
|