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

(many2one display) how to change?

By
Lakay lakay
on 10/3/14, 4:18 AM 1,149 views

We know that when you define a field with datatype of many2one and link it to "res.country.state" model  example  'state':fields.many2one('res.country.state','State',required=True),  it will display a selection button (drop down list box) wherein you could select a particular value example (Alabama, Alaska, Arizona etc.) ............ here "res.country.state" is a existing model in odoo

In my case i have a module ( i created my own model)

class si(osv.osv):
        _name='si'
        _columns ={
         'addr':fields.char('Shipping Address',size=100,required=True),

         'name':fields.char('Name',size=100,required=True),

}

si()

and then i override 'res_users' with a new field ('shipping_addr') in which this new field will be link to the previous class 'si'

class res_users(osv.osv):
        _inherit='res.users'
        _columns={
                'shipping_addr':fields.many2one('si','Shipping Addresss'),

}
res_users()

and then i added it to a form view, Im able to see this new field, since this new field has a type of many2one it will generate a selection box (drop down list box). My question is this,   why is it when i try to select something the values coming out  in the drop down list box are si,1    si,2  (its like having a format of  classname,recordno) i want it like the one in the 'state' variable as mentioned earlier (Alabama, Alaska, Arizona) , i want that when i click the dropdownlist button it will show the value in  'name' variable  not an id  like (si,1   si,2) how will i do this?

 

 

 

Why don't you try to define a name_get method in your overrided res_user module that returns a formatted string ? (a kind of __repr__ method) def name_get(self, cr, uid, ids, context=None): [...] browse your objet and build a string return a list with 2 items : id ans built string

Fabien REMY
on 10/3/14, 11:08 AM

It's look like that the orm doesn't detect "name" column in si model. Weird.

Ben Bernard
on 10/7/14, 12:51 PM

As @Ben told it's not detecting "name" column. By default _rec_name = 'name'....still try to set this property after _columns

dirtyHandsPHP
on 10/8/14, 1:58 AM

I already solve it! , actually the display in drop down box (many2one type) is based on the 'name' field in your object (in here: my 'si' object) . You're right Fabien REMY.. when I made this question I just included 'name' field here without this 'name' variable included in my code thats why when i added 'name' field into my python code it works... sorry for that haha..btw. thanks for those who answers

Lakay lakay
on 10/8/14, 4:05 AM
-1
Fabien REMY
On 10/7/14, 11:27 AM

Why don't you try to define a name_get method in your overrided res_user module that returns a formatted string ? (a kind of __repr__ method)

def name_get(self, cr, uid, ids, context=None):

          [...] browse your objet and build a string

          return a list with 2 items : id and built string

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

4 follower(s)

Stats

Asked: 10/3/14, 4:18 AM
Seen: 1149 times
Last updated: 3/16/15, 8:10 AM