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?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project
- MRP
This question has been flagged
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
I have updated answer.. Check it...
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.
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????
updated the sample code to access other fields.
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
|
3
Jan 19
|
7113 | ||
|
2
Jun 15
|
8094 | ||
|
0
Jun 15
|
3955 | ||
|
1
Apr 15
|
6570 | ||
|
1
Mar 15
|
4973 |
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