Alpesh Valaki
Alpesh Valaki

Reputation: 1631

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

Upvotes: 1

Views: 10074

Answers (1)

Alpesh Valaki
Alpesh Valaki

Reputation: 1631

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

Upvotes: 6

Related Questions