Skip to content

Instantly share code, notes, and snippets.

@repodevs
Created April 13, 2018 07:36
Show Gist options
  • Save repodevs/535eb574e8fba42611d2f2e29e205a9b to your computer and use it in GitHub Desktop.
Save repodevs/535eb574e8fba42611d2f2e29e205a9b to your computer and use it in GitHub Desktop.
Odoo snippet fields.Selection get text name
def get_selection_name(models, fields, value):
""" Get text value of Selection fields
:param models: models of fields
:param fields: fields name to get
:param value: fields value
:return text: Text value of the fields or ''
"""
res = dict(models.fields_get(allfields=[fields])[fields]['selection'])[value] if value else ''
return res
# how to use
models = self.env['some.model']
fields = 'selection_field'
value = models.selection_field
print(get_selection_name(models, fields, value))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment