コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
6350 ビュー

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

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

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

著作者

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

最善の回答

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

アバター
破棄