addons-cm/website_search_products/controllers/controller.py

47 lines
1.7 KiB
Python

# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import http
from odoo.http import request
from odoo.addons.website.controllers.main import Website
from werkzeug.utils import redirect as werkzeug_redirect
import logging
_logger = logging.getLogger(__name__)
class InventoryForm(http.Controller):
@http.route(["/inventory/search"], type="http", auth="user", website=True)
def inventory_form(self, **post):
"""Display inventory search form for authorized users."""
user = request.env["res.users"].browse(request.uid)
# Check if user has portal or internal access
has_portal = user.has_group("base.group_portal")
has_internal = user.has_group("base.group_user")
if not has_portal and not has_internal:
return werkzeug_redirect("/web")
# Fetch active products available in POS
products = (
request.env["product.template"]
.sudo()
.search([("active", "=", True), ("available_in_pos", "=", True)])
)
vals = {"products": products}
return request.render("website_search_products.web_list_products", vals)
class WebsiteController(Website):
"""Extend Website controller to redirect portal users after login."""
def _login_redirect(self, uid, redirect=None):
"""Send non-internal users to the website home instead of /my,
unless an explicit redirect was requested."""
if not redirect and request.params.get("login_success"):
if not request.env["res.users"].browse(uid)._is_internal():
redirect = "/"
return super()._login_redirect(uid, redirect=redirect)