Search Here

Domain of One2Many Child fields on the basis of parent fields

 In this article you will learn how to put domain on one2many field on the basis of parent model field. To achieve this I am going to use of context and many2many computed field.

Domain of One2Many Child fields on the basis of parent fields

Problem Statement

I have a parent model "parent.model" which have some fields, and a child model "child.model" (one2many) in a parent model. Now I want to add or put a domain filter on one2many field on the basis of some field which parent model have. For example I have semester_id field in one2many field of ("child.model") and I want to put domain filter on that field on the basis of my parent model ("parent.model"). To achieve this functionality we need some modification in our code.


  • Pass parent field value (active_id) as a context in our one2many field
  • Create a many2many computed field and fill that field value by using context, which we have get in point no 1.
  • Use that many2many field as a domain in xml

Model.py


XML

Post a Comment

0 Comments