Community mailing list archives
Re: Filter field using another field from another modelby
You could create a computed field in the parent model, that aggregates the products in the child1.
Add this field in the form view, but leave it invisible.
Then for child2, filter according this invisible field.
Let us know if that would work...
I don't think I can do that, since users would be confused since they don't need the m2o field to child1, and also the product_id doesn't need domain anymore since I can just relate it from child1 (related or computed field).
On 07/28/2016 10:57 AM, Togar Hutabarat wrote:
I don't see any possible way to get the domain for this case. However, you can do this by creating another additional field in model mymodel.child2, a many2one field, referenced to object mymodel.child1:# class Child2child1_id = fields.Many2one('mymodel.child1','Child 1 Reference')In your XML view, you can add the domain:<!-- view for Child2 --><field name="parent_id" /><field name="child1_id" domain=[('parent_id','=',parent_id)] /><field name="product_id" />
Then finally you can add a simple onchange function to this field that will change product_id based on product_id chosen in current record of mymodel.child1.
Hope it would help.
On Thu, Jul 28, 2016 at 10:13 AM, vak0160 <firstname.lastname@example.org> wrote:
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.
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