gpt4 book ai didi

python - Odoo 10.0 Name_search 域示例

转载 作者:太空宇宙 更新时间:2023-11-04 05:03:58 27 4
gpt4 key购买 nike

我需要在我的 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>

希望对你有所帮助。

关于python - Odoo 10.0 Name_search 域示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44962486/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com