Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
I want to add a select list to the Product Template view which shows values from my new, supplemental table. I found this function in the documentation:
Using relation fields many2one with selection. In fields definitions add:
..., 'my_field': fields.many2one( 'mymodule.relation.model', 'Title', selection=_sel_func), ...,
And then define the _sel_func like this (but before the fields definitions):
def _sel_func(self, cr, uid, context=None):
obj = self.pool.get('mymodule.relation.model')
ids = obj.search(cr, uid, )
res = obj.read(cr, uid, ids, ['name', 'id'], context)
res = [(r['id'], r['name']) for r in res]
This works, and I correctly get the name field in the selection list, and the database stores the record id. However, I would like to tweak this function a bit, so that I get a concatenation of 'name' and 'description' in my selection list. I have tried various options, but my selection list always renders exactly the same as before. I know very little Python. How would I modify the above function to get '[name] description' as the displayed option in my select list?
Write a "name_get" method in your object " mymodule.relation.model", and by using a context (which helps ypu decide how to frame the name value), then you can display a concatenated data...
And coming to this object, in XML pass a context on the field "my_field", which will be carried to the name_get of the its model
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.Register
Odoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.Test it now
|Asked: 11/6/14, 2:04 PM|
|Seen: 960 times|
|Last updated: 3/16/15, 8:10 AM|