odoo - 基于另一个字段的域过滤器 class

odoo - domain filter based on field from another class

所以我有这 2 类。

这个

class Relocation(models.Model):
_name = 'test.plan_relocation'

type = fields.Selection()
price_id = fields.Many2one('test.plan_price',domain="[('type','=',type)]")
relocation_line_ids = fields.One2many('test.plan_relocation_line','relocation_id')

还有这个

class RelocationLine(models.Model):
_name = 'test.plan_relocation_line'

relocation_id = fields.Many2one('test.plan_relocation')
source_id = fields.Many2one('test.plan_spending_actual',required=True)
available_source = fields.Float(related='source_id.available',default=0,readonly=True)

问题是我想根据 "price_id" 字段过滤 "source_id"。 我怎样才能做到这一点?

2个类合二为一xml。 xml 的一部分看起来像这样。

<field name="relocation_line_ids">
    <tree editable="bottom">
        <field name="source_id" string="Source" />
        <field name="available_source" />
    </tree>
</field>

非常感谢您的帮助。

在 test.plan_relocation_line 的 xml 中:

<field name="source_id" domain="[('price_id', '=',parent.price_id)]" />

希望对你有所帮助..