Community mailing list archives

community@mail.odoo.com

Filter field using another field from another model

by
Andre Kurniawan
- 07/27/2016 23:11:08

Hello Community,

I have this code:

class Parent(models.Model):
    _name = "mymodel.parent"

    child1_ids = fields.One2many("mymodel.child1", "parent_id")
    child2_ids = fields.One2many("mymodel.child2", "parent_id")


class Child1(models.Model):
    _name = "mymodel.child1"

    parent_id = fields.Many2one("mymodel.parent", required=True)
    product_id = fields.Many2one("product.product", required=True)


class Child2(models.Model):
    _name = "mymodel.child2"

    parent_id = fields.Many2one("mymodel.parent", required=True)
    product_id = fields.Many2one("product.product", required=True, domain="???")  # domain using `mymodel.child1` record

I wanted to filter the `product_id` field on `mymodel.child2` model, using `product_id` on `mymodel.child1` model on the same parent.


Example:

The parent have 3 record on field `child1_ids`, each have different product (product1, product2, product3), and I want the product in field `child2_ids` can only select product1, product2, or product3, not product4 or another product not set on `child1_ids`. How I can do that?

-- 
Regards,
Andre