Odoo Help


many2one show all the fields

Hachem Chraiti
on 4/15/14, 10:10 AM 1,779 views

hi, im doing a many2one relation i can show the name of the relation field(foreign key) but i retrieve onlu its id, how can i retrieve other fields?


Dhinesh - Technical Consultant, Sodexis Inc

--Dhinesh - Technical Consultant, Sodexis Inc--
| 5 4 9
Pondicherry, India
--Dhinesh - Technical Consultant, Sodexis Inc--

Passionate coder in Python/OpenERP. Knows Django/Flask MVC frameworks. Did code in Java, PHP.

Contact me at: dvdhinesh.mail@gmail.com

Dhinesh - Technical Consultant, Sodexis Inc
On 4/15/14, 10:28 AM

You can use rec_name for retrieving a single value. But if u want to display more than one field means go for name_get method

def name_get(self, cr, uid, ids, context=None):
        res = []
        for obj in self.browse(cr, uid, ids, context=context):
                var = obj.name +"Email("+obj.email+")"              
            res.append((obj.id, var))
        return res

Use the above method in your parent class and simply call that class on your manytoone relational field.

Syntax of name_get orm method

name_get(cr, user, ids, context=None)

        cr -- database cursor

        user (integer) -- current user id

        ids -- list of ids

        context (dictionary) -- context arguments, like lang, time zone


    tuples with the text representation of requested objects for to-many relationships

but th field i would like to retrive is not in the same class

Hachem Chraiti
on 4/15/14, 10:34 AM

I have updated answer.. Check it...

Dhinesh - Technical Consultant, Sodexis Inc
on 4/15/14, 10:49 AM

please if im retrieving well the id how can access other fields?i must pass by sql queries?

Hachem Chraiti
on 4/15/14, 10:56 AM

Use browse method. It will give you the entire fields in other object as well as same object. If u already have ids and want to access particular field means use search orm method.

Dhinesh - Technical Consultant, Sodexis Inc
on 4/15/14, 11:15 AM



| 5 5 7
Bikaner, India

OpenERP Developer at SunARC Technology

On 4/15/14, 10:33 AM

Check many2one relation table "name" column is available. It shows "name" column value in many2one selection or add the below code in python file

rec_name = "fieldname"

Here after its shows rec_name field value shows in many2one selection.

using browse ORM method you can access all other fields.


 def meth_name(self, cr, uid, ids, context=None):
      table_obj = self.pool.get('table.name')
      for val in table_obj.browse(cr, uid, ids, context=context):
             field1_value = val.column1
             field2_value = val.column2
      return field1_value

i doing this right and it shows me the field i need,but how to access to other fields????

Hachem Chraiti
on 4/15/14, 10:37 AM

updated the sample code to access other fields.

on 4/16/14, 5:30 AM

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: 4/15/14, 10:10 AM
Seen: 1779 times
Last updated: 3/16/15, 8:10 AM