Odoo Help


Creating A Dropdown Menu With Customer Names

Alex Gallien
on 7/21/14, 4:53 PM 746 views

I am looking to add a customer field to the products screen. In my business problem, each product is assigned to one customer specifically. I tried copying the code from the Sales Order form, but that didn't work out - I got a label for my field, but no menu to select from. This is the line I added:

In my .py:

    'x_cust_name': fields.many2one('res.partner', 'Customer', readonly=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}, required=True, change_default=True, select=True, track_visibility='always'),

In my .xml:

          <field name="x_cust_name" domain="[('customer','=',True)]" context="{'search_default_customer':1, 'show_address': 1}" options='{"always_reload": True}'/>


This hasn't worked so far. Is there a way to get a nice dropdown menu of customers to appear in the products form? Thanks!

Nhomar Hernandez
On 7/22/14, 1:12 AM


In my .py:

_id for convention, not x_* due to this name is reserved for other porpose.

    'customer_id': fields.many2one('res.partner', 'Customer'),

In my .xml:

          <field name="customer_id"/>

But I think you are reinventing the wheel.

It is done here:


It is a little more complicated than what you want to do but the data model is done already.


Thanks! That was super helpful. I overcomplicated things as usual. I read that using x_* in custom modules was a best practice, in case of updates later. Is that not the case? What is x_* reserved for?

Alex Gallien
on 7/22/14, 1:31 PM

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 7/21/14, 4:53 PM
Seen: 746 times
Last updated: 3/16/15, 8:10 AM