Odoo Help


This community 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.


How to popoulate fields.Selection manually

D.H. Bahr
on 5/18/15, 2:20 PM 377 views

Hi all!

I have a model with a m2o relation to other model. I also have a Selection which gets populated on the fly from a web server... something like this:

from openerp import models, fields, api
class MyModel (models.Model):
def _get_options (self, query=None):
url = "http://example.com/fetch?"
rc = http_client.get (url+query) #this instruction fetches results from the external server
values = []
for entry in rc:
values.append ((entry['id'], entry['name']))
return values

_name = "my.model"
other_model = fields.Many2One ("other.model", "Other Model")
select_ = fields.Selection (_get_options, string="Select")

def _on_other_model_change (self):
query = ... # here the query is built from the other_model data
values = self._get_options (query) ??????

What I need is to update in the view the available choices for the "select_" field.

Hope I was able to explain myself.

Best regards and thanks in advance


Your Answer

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

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)


Asked: 5/18/15, 2:20 PM
Seen: 377 times
Last updated: 5/18/15, 2:20 PM