我需要在我的 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 的表单 View 是
<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'
no error stack on terminal.
如何处理这个问题并在域中使用关系字段的字段以便我可以使用 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>
希望对你有所帮助。
我是一名优秀的程序员,十分优秀!