Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
2 Antwoorden
8630 Weergaven

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?

Avatar
Annuleer

Enhance the functionality of Many2One fields in Odoo with dynamic multi-field Search and Get capabilities. This app allows users to search and get records within Many2One fields using multiple fields. With a user-friendly configuration interface, you can easily specify the fields to be included in the search criteria, making it more efficient and flexible for finding records as well as displaying the records based on multiple fields instead of only name field.
https://apps.odoo.com/apps/modules/17.0/mh_dynamic_name_get_many2one

Beste antwoord

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
Avatar
Annuleer
Auteur

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

I have updated answer.. Check it...

Auteur

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

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.

Beste antwoord

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
Avatar
Annuleer
Auteur

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

updated the sample code to access other fields.

Gerelateerde posts Antwoorden Weergaven Activiteit
3
jan. 19
7210
2
jun. 15
8173
0
jun. 15
4017
1
apr. 15
6712
1
mrt. 15
5076