Skip to Content
Menu
This question has been flagged
652 Views

I'm struggling to define a restriction on possible values for the "XPart.a_part_id" many2one relationship. When I create a "XPart" I'd like to get only a subset of all "AParts". Namely, those depending on "A-X" relationship.

One attempt (just to imply intention):

a_part_id=field.Many2one('a.part', domain="[('a_id', '=', x_id.a_id)]"

I'm using the following simplified setup.

class A(models.Model):
_name='a'
a_part_ids=fields.One2many('a.part', a_id)
x_ids=fields.One2many('x', a_id)

class APart(models.Model):
_name='a.part'
a_id=field.Many2one('a')
a_part_ids=fields.One2many('x.part', a_part_id)

class X(models.Model):
_name='x'
a_id=field.Many2one('a')
x_part_ids=fields.One2many('x.part', x_id)

class XPart(models.Model):
_name='x.part'
x_id=field.Many2one('x')
a_part_id=field.Many2one('a.part')

Thanks for any hit!

Wolfgang

Avatar
Discard
Author

Meanwhile, I've found a solution that seems to work. I defined a related field and used the field in the domain-clause instead of x_id.a_id