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

How to only show companies in a many2one field ?

By
PY
on 12/3/13, 12:52 PM 1,653 views

Hi !

I have a many2one field in my shipping_line class that refers to res_partner_id. In my view, I want to show only the companies, not all the partners. I know that it's related to the boolean field names 'is_company'.

I tried this by creating a fields.related field in shipping_line, like this :

'partner_is_company': fields.related('partner_id', 'res_partner_is_company', type='boolean', store=True)

In my view, I've added a domain :

<field name="partner_id" domain="[('partner_is_company', '==', True)]" />

I don't know what's wrong, I'm kind of new (you can see that in my others Q...)

So I have this error for now :

(...)
ValueError: Invalid leaf ['partner_is_company', '==', True]

If someone can help me with this, I'll be very gratefull !

2
Ashif Abdulrahman
On 12/4/13, 5:29 AM

You can just achieve it using the field in XML like this, no need for using extra related field..

<field name="partner_id" domain="[('is_company', '=', True)]" />

Thanks, works perfectly ! :)

PY
on 12/4/13, 9:12 AM

I wonder why we must use '=' in domain, and '==' in <field name="field" attrs="{'invisible':[('type', '==', 'f')]}" />, it's a little confusing...

PY
on 12/4/13, 9:16 AM

No, we use '=' in field also like this <field name="field" attrs="{'invisible':[('type', '=', 'f')]}" />. and we are using '==' in python conditional statements like if,while etc...

Ashif Abdulrahman
on 12/5/13, 5:21 AM
1
Julio Serna
On 12/3/13, 1:52 PM

in the domain function not is valid the equal double sign

try this:

<field name="partner_id" domain="[('partner_is_company', '=', True)]" />

although not is necessary the "related" field

try this:

> 'partner_is_company': fields.many2one('res.partner', 'Partner Company', domain=[('is_company', '=', True)])

Best regards

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

0 follower(s)

Stats

Asked: 12/3/13, 12:52 PM
Seen: 1653 times
Last updated: 3/16/15, 8:10 AM