我无法按计算域搜索
我覆盖了要计算的 product.template 中的名称字段,因此我需要按名称搜索产品
class autopart(models.Model):
_inherit = 'product.template'
@api.multi
@api.depends('item', 'car', 'model', 'dsc', 'drc', 'year', 'org')
def compute_amount(self):
for rec in self:
rec.name = " ".join(
[rec.item and rec.item.name or "", rec.car and rec.car.name or "", rec.model and rec.model.name or "",
rec.dsc and rec.dsc.name or "", rec.drc and rec.drc.name or "", rec.org and rec.org.name or "",
rec.year and rec.year.name or ""])
def pro_searach(self, operator, value):
if operator == 'like':
operator = 'ilike'
name = self.env['product.template'].search([('name', operator, value)], limit=None)
return [(self.name, operator, value)]
name = fields.Char(string="Name", required=False ,compute=compute_amount,search=pro_searach)
这是日志中的错误
raise ValueError("Invalid leaf %s" % str(self.leaf))
ValueError: Invalid leaf (False, 'ilike', 'تيل')
请您参考如下方法:
非持久字段不可搜索。那是因为 Odoo 试图将域元组/过滤器解析为一个 SQL 查询,该查询当然是在现有列上搜索。非存储字段没有表列。
你现在有两个选择:
- 使字段存储为
store=True - 定义搜索方法并使用
search='name_of_search_method( more information here ) 在字段上设置它
第一个选项很简单,但存储计算字段可能会对性能产生不利或有利的影响。第二个选项要困难得多,因为您必须考虑如何将搜索形成为使用依赖字段或您在计算中使用的每个字段。
