Pointer
Pointer

Reputation: 2186

How to use a name field instead of id in attrs in Odoo 9?

Is it possible to use project name instead of id in my example?

<field name="my_field" 
       attrs="{'invisible': [('project_id', '!=', 2)], 'required': [('project_id', '=', 2)]}"/>

I have tried with [('project_id.name', '!=', 'TEST PROJECT')] but it's not working.

Upvotes: 3

Views: 467

Answers (1)

ChesuCR
ChesuCR

Reputation: 9670

You can create a related field in order to use it in the attrs attribute

project_name = fields.Char(
    related='product_id.name',
)
<field name="project_name" invisible="1"/>
<field name="my_field" 
       attrs="{'invisible': [('project_name', '!=', 'TEST PROJECT')], 'required': [('project_name', '=', 'TEST PROJECT')]}"/>

Upvotes: 4

Related Questions