Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

odoo9 : How to get domain with the field name of a many2one?

By
Drees Far
on 4/29/16, 4:30 AM 254 views

Hello everybody!!!

I have a field named type_id which is a many2one to a table hr.contract.type. (where its fields are id, name, ...)

I want to make a field named Date_end invisible when the name of the contract is "CDI".

I tried like this : <field name="date_end" attrs="{'invisible':[('type_id.name,'=',"CDI")]}"/>

But it doesnt work.

Can anyone help please.

Thanks a lot in advance.

Best Regards.

1

Jignesh Mehta

--Jignesh Mehta--
2081
| 6 4 8
Surat, India
--Jignesh Mehta--


Jignesh Mehta
On 4/29/16, 6:42 AM

Hello DressFar,


Try this :-

First Solution:-

<field name="date_end" attrs ="{'invisible': {'type_id': [('name', '=', 'CDI')]}}" / >


Second Solution :-

In py:-

type_id = fields.Many2one ("hr.contract.type", 'Type')

type_name = fields.Char(related='type_id.name', 'Type Name')

In Xml:-

<field name="type_id" attrs="{'invisible': [('type_name', '=', 'CDI')]}" />

<field name="type_name" invisible="1"/>


Hope it works for you.

Thanks,

0
Motez
On 4/29/16, 6:42 AM

Add the contract name as a related field in the contract object then change the domain in xml

<field name="date_end" attrs="{'invisible':[('my_related_field','=','CDI')]}"/>

NOTE : The code you posted has some errors it should be like this :

<field name="date_end" attrs="{'invisible':[('type_id.name','=','CDI')]}"/>

Let us now how it went for you !

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 4/29/16, 4:30 AM
Seen: 254 times
Last updated: 4/29/16, 6:42 AM