Search code examples
python-2.7odoo-8odoo-9odoo-10

How to get string of selection field?


i have following selection fields in my module i want to get string value of selection field. suppose user select 'o' i want to print O - Original please provide me any better solution.

type = fields.Selection([
                        ('o', 'O - Original'),
                        ('a', 'A - Amended')],
                         string="Is this an Original Invoice or Amended Invoice ?"

i have this solution

def get_string_value_of_selection():
    if self.type == 'o':
        value = "O - Original", 
    if self.type == 'a':
        value = "A - Amended"

    print "value = ",value

output

if user select o

value = O - Original

Solution

  • it can be archive as follow. working in odoo 9, 10 not tried in 8

    print dict(self._fields['type'].selection).get(self.type)
    

    if user select o

    output O - Original