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 show all the fields

By
Hachem Chraiti
on 4/15/14, 10:10 AM 1,223 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?

2

Dhinesh - Technical Consultant, Sodexis Inc

--Dhinesh - Technical Consultant, Sodexis Inc--
3577
| 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)
    Parameters: 

        cr -- database cursor

        user (integer) -- current user id

        ids -- list of ids

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

    Returns:    

    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
0

Prakash

--Prakash--
3173
| 5 4 7
Bikaner, India
--Prakash--

OpenERP Devloper at SunARC Technology

Prakash
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.

Example:-

 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.

Prakash
on 4/16/14, 5:30 AM

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