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 defined display name in custom many2one

By
Gobman
on 2/7/15, 1:43 AM 596 views

I created custom object from Setting->Technical->Database Structure.
And I can't defined field name in 'name' must be 'x_name'.
When I called this in view it show 'object_name, object_id' like below image.
http://i.imgur.com/cENOGo7.png

 How i can fix this? 

I read some topic in this forum. It said to defined '_rec_name' but my workflow not follow those. How I can do in my workflow. 

0

Ankit H Gandhi(AHG)

--Ankit H Gandhi(AHG)--
996
| 5 3 6
Rajkot, India
--Ankit H Gandhi(AHG)--

Learning Python..

Ankit H Gandhi(AHG)
On 2/7/15, 5:28 AM

Hello Gobman,

@Bole is 100 % correct,here we use name_get method for custom many2one field

here i give one example of name get_method hope this code is very help full

class hobbies_hobbies(osv.osv):
    _name = 'hobbies.hobbies'
    _columns = {
        'name' : fields.char('Hobby Name'),
        'place' : fields.char('Place'),
        'code' : fields.char('Code'),
    }
    
    def name_get(self, cr, uid, ids, context=None):
        res = super(hobbies_hobbies, self).name_get(cr, uid, ids, context=context)
        final_result = []
        if ids:
            for hobbies in self.browse(cr, uid, ids,context=context):
                hobbies_data = hobbies.name or ""
                hobbies_data += " ["
                hobbies_data += hobbies.code or ""
                hobbies_data += "] "
                final_result.append((hobbies.id, hobbies_data))
            return final_result
        else: 
            return res

if you find this answer helpful, please give me a thumbs up vote    

Regards,

Ankit H Gandhi

0

Bole

--Bole--
2385
| 5 4 6
Zagreb | Karlovac, Croatia
--Bole--

there is only 10 kind of people the ones that understand binary ... and others

Bole
On 2/7/15, 3:59 AM

in your new object you need the result of  _name_get method.


by default _name_get will show field name 
if some other field shoud be used for representing name, then you define it in _rec_name = 'other_field'
and if you want name to be shown as combination of few field values then you need to define 
_name_get method

all this should be done in py file defining the object.... 
hope it helps...
 

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: 2/7/15, 1:43 AM
Seen: 596 times
Last updated: 3/16/15, 8:10 AM