Display another field in many2one instead of name
odoo
Solution
There are a couple of ways to do this.
The name that is displayed for relational fields is the result of the `name_get` method. You can inherit `product.product` and override `name_get` but that will affect the entire system, every time a product is displayed it will change this. You could code around this using the `context` but it is starting to get messy.
If you just want the code I would create a related field like this.
'product_ref': fields.related(
'product_id',
'part_number',
string='Product',
readonly=True,
type='char',
help = 'The product part number',
)
and then use this on your form. The ORM layer is smart enough that if your particular record doesn't have a product ID or a product doesn't have a part number it will handle it gracefully.
If you needed to be a little trickier you could create a functional field that showed say the name and the part number for example.
Problem
I have a many2one field like this ``` 'product_id': fields.many2one('product.product', 'Product', required=True) ``` It displays me all the product names (name attribute from product_template class) and stores id inside. I would like to display the part_number of the product instead of name and store id inside. Is there a way to do this in openerp7. Thanks for your time.