【问题标题】:Filter one2many with dynamic values in interface在界面中使用动态值过滤 one2many
【发布时间】: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')]"

实际输出:

model1amount='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

请帮忙!感谢您的宝贵时间!

【问题讨论】:

    标签: filter odoo-12 one2many


    【解决方案1】:

    用于导入字段

    from odoo import api, fields, models
    

    试试这个:

    domain="['&',('field_name','=','amount'),('field_value','>','100.0')]"
    

    你也可以在py中使用上面的域。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-10
      • 1970-01-01
      • 1970-01-01
      • 2019-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多