In my odoo app I have a 'plantation' model with a one2many field "crop_ids". I have created a form view, and inside that form view I am showing the crop_ids as a tree. What I want to do is to show only the crops with an specific condition. I try to use a domain in the view with domain="[('is_verified', '=', True)]", but this is not working. It is showing all crops. It is important tho appy the domain in the view and not in the model, cause I have other form view that needs to show all crops inside. This is my code and is not working.
<page name="crop" string="Crop list">
<field name="crop_ids" domain="[('is_verified', '=', True)]">
<tree create="0" delete="0">
<field name="name_seq"/>
<field name="rubro"/>
<field name="fecha"/>
<field name="cantidad_plantas"/>
<field name="cantidad_atrofiadas"/>
</tree>
</field>
</page>
CodePudding user response:
Odoo will use the field domain when it tries to retrieve the lines in the comodel.
Use the domain in the field declaration:
crop_ids = fields.One2many(.., domain=[('is_verified', '=', True)])
CodePudding user response:
In this case, it seems domain element can have only 2 cases. One quick solution would be having 2 fields (crop_ids, crop_verified_ids) one with
domain="[('is_verified', '=', True)]"
other with either false or no domain. You can make each visible easily in a form view based on the condition you want.