LaOsaCoop/Odoo16#109 migrated website_search_products
This commit is contained in:
parent
26dbe222dd
commit
f1a3a75988
11 changed files with 525 additions and 0 deletions
3
website_search_products/controllers/__init__.py
Normal file
3
website_search_products/controllers/__init__.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from . import controller
|
||||
59
website_search_products/controllers/controller.py
Normal file
59
website_search_products/controllers/controller.py
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
# -*- 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
|
||||
|
||||
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 http.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."""
|
||||
|
||||
@http.route(website=True, auth="public")
|
||||
def web_login(self, redirect=None, *args, **kw):
|
||||
"""Handle login redirection based on user group."""
|
||||
response = super().web_login(redirect=redirect, *args, **kw)
|
||||
|
||||
# Check if login was successful
|
||||
if not redirect and request.params.get("login_success"):
|
||||
user = request.env["res.users"].browse(request.uid)
|
||||
|
||||
# Redirect internal users to web, others to inventory search
|
||||
if user.has_group("base.group_user"):
|
||||
# Keep original redirect for internal users
|
||||
redirect = "/web"
|
||||
else:
|
||||
# Redirect portal users to inventory search
|
||||
redirect = "/inventory/search"
|
||||
|
||||
return http.redirect(redirect)
|
||||
|
||||
return response
|
||||
Loading…
Add table
Add a link
Reference in a new issue