Odoo Help


Working with fields.selection values

on 2/15/13, 4:51 PM 7,592 views


How I can read or return the value chosen from a selection field? I need the user to select values from a list, and use the selected value to complete the information in other fields in the form.


Some code used to test, with error:

 'seq_choosed': fields.selection([(11,'Product End'),(12,'Product Base')],'Sequence to use '),
 lot_sequence = self.pool.get('ir.sequence').get_id(cr, uid, seq_choosed.value, context={} )

Olivier Dony (odo)

--Olivier Dony (odo)--

| 7 6 8
Ramilies, Belgium
--Olivier Dony (odo)--


Olivier Dony (odo)
On 2/15/13, 5:53 PM

Your question does not clearly explain what you want to do nor what you tried. You say you have an error but you do not say what is the error message (and trace). Your code example is not complete enough to understand properly.

Still, here are a few pointers:

  • How to obtain the value chosen by the user depends on where you do it: in an on_change method, in a fields.function, when overriding one of the base ORM methods, etc.
  • Have a look at the OpenERP Technical memento, it contains examples for these various use cases.
  • The selection field in your example has 2 possible hardcoded integer values: 11 or 12. This is rather unusual but supported. Most selection fields use string values though. In this case when you read() or browse() a record from the model in which this field is defined, you will get the value as an int (11 or 12) or False if the field was left empty (if it's not required).

Here's a random example based on the little information you provided:

Imagine you put an on_change on your field in the XML view:

  <field name="seq_choosed" on_change="on_change_seq_choosed(seq_choosed)"/>
  <field name="seq_num"/>

Then you could do something like the following:

  def on_change_seq_choosed(self, cr, uid, ids, seq_choosed, context=None):
       # on_change returns a dict
       result = {
           'value': {}
       # selected value is explicitly passed in seq_choosed parameter in XML def 
       if seq_choosed:
           seq_num = self.pool.get('ir.sequence').get_id(cr, uid, seq_choosed, context=context)
           result['value']['seq_num'] = seq_num
       return result

That's not a very useful example, but if you want better answers you'll have to be a lot more specific in your question ;-)

Thanks a lot for your answer, and all the corrections, my English is no very good. I going to try this, and looking more about the on_change method.

on 2/15/13, 6:23 PM

@Oliver Dony, for instance I want to print the value (Product Base) with key (12), how to do?

If I print seq_choosed, it prints me the key of selection field. I need to print value of key chosen

Atchuthan - Technical Consultant, Sodexis Inc
on 12/13/13, 9:21 AM

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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)


Asked: 2/15/13, 4:51 PM
Seen: 7592 times
Last updated: 3/16/15, 8:10 AM