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
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
|Asked: 11/6/14, 2:04 PM|
|Seen: 768 times|
|Last updated: 3/16/15, 8:10 AM|