Odoo 10.0 Name_search 域示例

Odoo 10.0 Name_search domain example

我需要在我的 one2many 字段 product_lines 中使用 many2one product_id 字段,产品应该根据 page_no 进行过滤。

Model1 包含 product_lines(o2m : model2-model1_id) 和 page_no

class model1(models.Model):
    _name = "model1"

    ....
    page_no = fields.Integer('Page No.')
    ...
    product_lines = fields.One2many('model2', 'model1_id', 'Product lines')

model2 包含 product_id 和 model1_id(m2o : model1)

class model2(models.Model):
    _name = "model2"

    model1_id = fields.Many2one('model1')
    product_id = fields.Many2one('product.product')

在我的 xml 中,model1 的表单视图是

    <field name="product_lines"  >
        <tree editable="bottom" name="petan_nos">
            <field name="model1_id" invisible="1" />
            <field name="product_id" domain="[('page_no', '=', model1_id.page_no)]" />
        </tree>
    </field>

这就是我如何收到前端错误 Uncaught Error: AttributeError: object has no attribute 'page_no' 终端上没有错误堆栈。

如何处理这个问题并在域中使用关系字段的字段以便我可以使用 name_search 并修改行为?

提前致谢。

继承product.product并添加字段page_no

_inherit='product.product'

page_no = fields.Char('Page_no')

并在model2

中定义page_no
class model2(models.Model):
_name = "model2"

model1_id = fields.Many2one('model1')
product_id = fields.Many2one('product.product')
page_no = fields.Char('Page_no')

在xml

<field name="product_lines"  >
    <tree editable="bottom" name="petan_nos">
        <field name="page_no" />
        <field name="model1_id" invisible="1" />
        <field name="product_id" domain="[('page_no', '=', page_no)]" />
    </tree>
</field>

希望对您有所帮助。