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
相关产品推荐
相关产品推荐

