【发布时间】:2021-06-15 08:40:46
【问题描述】:
以这个场景为例:
class Model1(models.Model):
_name = "model1"
_description = "Model 1"
custom_field = fields.One2many(
'model2',
'registration',
)
class Model2(models.Model):
_name = "model2"
_description = "Model 2"
field_name = fields.Char(
'Field Name',
required=True,
)
field_value = fields.Char(
'Field Value',
required=True,
)
registration = fields.Many2one(
'model1',
required=True,
)
所需输出:
根据field_value 其中field_name="amount" 在odoo 树视图中过滤model1 的记录。 field_value 应由用户输入。 amount 是一个存储为 str 的浮点数。
当前过滤器(静态):
domain="['&',('custom_field.field_name','=','amount'),('custom_field.field_value','>','100.0')]"
实际输出:
model1 和 amount='20' 的记录在上述情况下被过滤。(字符串比较 '20'>'100.0')。这个100.0是用户在界面中输入的。
我从forum post on odoo.com "How to use dynamic values in domain filter?" 尝试了这个解决方案
输出:
Uncaught TypeError: Cannot read property 'fields' of null
请帮忙!感谢您的宝贵时间!
【问题讨论】: