Created
August 2, 2021 08:24
-
-
Save sehrishnaz/ab9b8238cc3e3fe127eda61d6e68c722 to your computer and use it in GitHub Desktop.
Retrieving Selection Field value instead of key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Syntax | |
dict(self.fields_get(allfields=['field_name'])['field_name']['selection'])['key_of_selection_field'] | |
#If you want to get field value in same model in which you are working than use below code | |
code = dict(self.fields_get(allfields=['state'])['state']['selection'])['key'] | |
#Example | |
code = dict(self.fields_get(allfields=['code'])['code']['selection'])[self.code] | |
#If you want to get field value from another model than use below code | |
code = dict(self.env['your.model'].fields_get(allfields=['state'])['state']['selection'])['key'] | |
#Example | |
code = dict(self.env['your.model'].fields_get(allfields=['code'])['code']['selection'])[self.code] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Read more in detail: https://learnopenerp.blogspot.com/2021/08/get-selection-field-value-instead-of-key-odoo.html