You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Odoo15 website_sale自定义属性搜索失效问题求助

排查Odoo 15网站搜索自定义字段失效的原因

核心问题:搜索模型不匹配

你在product.template上定义了wine_award字段,但Odoo的website_sale模块默认搜索的是**product.product(产品变体)**模型,而非product.template(产品模板)。你当前的搜索条件('wine_award', 'ilike', search)直接作用于product.product,但该模型本身没有这个字段,自然不会生效。

从你打印的域名也能看出,原始搜索逻辑里的name、product_variant_ids.default_code都是针对product.product的关联或自身字段,你的wine_award条件直接加进去,Odoo无法在product.product上找到对应字段,会被忽略或静默报错。

修复方案

修改搜索条件,通过product_tmpl_id关联到产品模板的字段:

from odoo.addons.website_sale.controllers.main import WebsiteSale
from odoo.osv.expression import OR

class WebsiteSaleInherit(WebsiteSale):
    def _get_search_domain(self, search, category, attrib_values, search_in_description=False):
        domain = super()._get_search_domain(
            search, category, attrib_values,
            search_in_description=search_in_description
        )

        if search:
            # 通过product_tmpl_id关联到产品模板的wine_award字段
            award_domain = [('product_tmpl_id.wine_award', 'ilike', search)]
            domain = OR([domain, award_domain])
        return domain

额外验证点

  • 字段权限检查:确保wine_award字段对网站public用户组有读取权限,否则即使搜索条件正确,也会因权限不足返回空结果。
  • 数据验证:确认测试用的产品变体对应的产品模板,wine_award字段确实包含你搜索的关键词(比如"Yves")。
  • 日志排查:查看Odoo服务器日志,确认是否存在"字段不存在"类的报错,这能直接验证模型不匹配的问题。

内容的提问来源于stack exchange,提问作者Toni Fankhauser

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 10:50:08