141 lines
6.1 KiB
Python
141 lines
6.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:
|
|
# Use relative redirect to maintain HTTPS/HTTP protocol
|
|
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):
|
|
# -----------------------------------------------------------
|
|
# SUPER SAFE EDITOR & IFRAME DETECTION
|
|
# -----------------------------------------------------------
|
|
path = request.httprequest.path
|
|
params = request.params
|
|
headers = request.httprequest.headers
|
|
referer = headers.get('Referer', '')
|
|
fetch_dest = headers.get('Sec-Fetch-Dest', '')
|
|
|
|
# 1. If not logged in, always show standard homepage
|
|
if not request.session.uid:
|
|
return super(ImageHome, self).index(**kwargs)
|
|
|
|
# 2. ROLE-BASED AUTO REDIRECTION (FOR STAFF)
|
|
# Skip the dashboard/website entirely for Chefs and Waiters
|
|
user = request.env.user.sudo()
|
|
is_admin = user.has_group('base.group_system') or \
|
|
user.has_group('dine360_restaurant.group_restaurant_admin')
|
|
|
|
if not is_admin:
|
|
# 1. WAITER / CASHIER -> Priority goes to POS
|
|
if user.has_group('dine360_restaurant.group_restaurant_waiter') or \
|
|
user.has_group('dine360_restaurant.group_restaurant_cashier'):
|
|
return request.redirect('/web#action=point_of_sale.action_client_pos_menu')
|
|
|
|
# 2. CHEF -> Directly to KDS
|
|
if user.has_group('dine360_restaurant.group_restaurant_kitchen'):
|
|
return request.redirect('/web#action=dine360_kds.action_kds_dashboard')
|
|
|
|
# 3. SUPER SAFE EDITOR & IFRAME DETECTION
|
|
path = request.httprequest.path
|
|
params = request.params
|
|
headers = request.httprequest.headers
|
|
referer = headers.get('Referer', '')
|
|
fetch_dest = headers.get('Sec-Fetch-Dest', '')
|
|
|
|
# Check for ANY editor or backend signal
|
|
editor_params = ['enable_editor', 'edit', 'path', 'website_id', 'frontend_edit', 'model', 'id']
|
|
is_editor_request = any(p in params for p in editor_params)
|
|
is_from_backend = any(m in referer for m in ['/website/force', 'enable_editor'])
|
|
|
|
# if it looks like Odoo internal business, return the real website
|
|
if fetch_dest == 'iframe' or is_editor_request or is_from_backend:
|
|
return super(ImageHome, self).index(**kwargs)
|
|
|
|
if path != '/':
|
|
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
|
|
|
|
# User requested to hide all standard apps and POS/KDS.
|
|
# Only allow specific menus based on user request + admin tools.
|
|
allowed_menus = ['Online Orders', 'Website', 'Table Reservations', 'Uber Integration', 'Apps', 'Settings']
|
|
|
|
filtered_menus = []
|
|
seen_names = set()
|
|
for menu in menus:
|
|
# Match strictly against allowed menus
|
|
if menu.name not in allowed_menus and menu.name != 'Table Reservation':
|
|
continue
|
|
|
|
# Hide "Apps" and "Settings" for non-admins
|
|
if menu.name in ['Apps', 'Settings'] and not is_admin:
|
|
continue
|
|
|
|
# De-duplicate by name
|
|
if menu.name in seen_names:
|
|
continue
|
|
seen_names.add(menu.name)
|
|
|
|
# Dynamic Icon Override (Dine360 Branding)
|
|
icon_mapping = {
|
|
'Apps': 'dine360_dashboard,static/src/img/icons/apps.svg',
|
|
'Settings': 'dine360_dashboard,static/src/img/icons/settings.svg',
|
|
'Table Reservation': 'dine360_dashboard,static/src/img/icons/table_reservation.svg',
|
|
'Table Reservations': 'dine360_dashboard,static/src/img/icons/table_reservation.svg',
|
|
'Uber Integration': 'dine360_dashboard,static/src/img/icons/uber_integration.svg',
|
|
'Online Orders': 'dine360_dashboard,static/src/img/icons/website.svg',
|
|
}
|
|
|
|
# Find the best match in the mapping
|
|
current_name = menu.name
|
|
for key, icon_path in icon_mapping.items():
|
|
if key.lower() in current_name.lower():
|
|
menu.web_icon = icon_path
|
|
break
|
|
|
|
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')
|