Přejít na obsah
Odoo Menu
  • Přihlásit se
  • Vyzkoušejte zdarma
  • Aplikace
    Finance
    • Účetnictví
    • Fakturace
    • Výdaje
    • Spreadsheet (BI)
    • Dokumenty
    • Podpisy
    Prodej
    • CRM
    • Prodej
    • POS Obchod
    • POS Restaurace
    • Předplatné
    • Pronájem
    Webové stránky
    • Webové stránky
    • E-shop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Dodavatelský řetězec
    • Sklad
    • Výroba
    • PLM
    • Nákup
    • Údržba
    • Kvalita
    Lidské zdroje
    • Zaměstnanci
    • Nábor
    • Volno
    • Hodnocení zaměstnanců
    • Doporučení
    • Vozový park
    Marketing
    • Marketing sociálních sítí
    • Emailový marketing
    • SMS Marketing
    • Události
    • Marketingová automatizace
    • Dotazníky
    Služby
    • Projekt
    • Časové výkazy
    • Práce v terénu
    • Helpdesk
    • Plánování
    • Schůzky
    Produktivita
    • Diskuze
    • Schvalování
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Aplikace třetích stran Odoo Studio Odoo cloudová platforma
  • Branže
    Maloobchod
    • Knihkupectví
    • Obchod s oblečením
    • Obchod s nábytkem
    • Potraviny
    • Obchod s hardwarem
    • Hračkářství
    Food & Hospitality
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Guest House
    • Distributor nápojů
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Trades
    • Údržbář
    • IT hardware a podpora
    • Solar Energy Systems
    • Výrobce obuvi
    • Úklidové služby
    • HVAC Services
    Others
    • Nonprofit Organization
    • Agentura pro životní prostředí
    • Pronájem billboardů
    • Fotografování
    • Leasing jízdních kol
    • Prodejce softwaru
    Browse all Industries
  • Komunita
    Edukační program
    • Tutoriály
    • Dokumentace
    • Certifikace
    • Vzdělávání
    • Blog
    • Podcast
    Podpora vzdělávání
    • Vzdělávací program
    • Scale Up! Hra na firmu
    • Navštivte Odoo
    Získat software
    • Stáhnout
    • Porovnejte edice
    • Verze
    Spolupráce
    • Github
    • Fórum
    • Události
    • Překlady
    • Stát se partnerem
    • Services for Partners
    • Registrujte svou účetní firmu
    Získat služby
    • Najít partnera
    • Najít účetní
    • Setkejte se s poradcem
    • Implementační služby
    • Zákaznické reference
    • Podpora
    • Upgrady
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dohodnout demo
  • Ceník
  • Pomoc

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Účetnictví
  • Sklad
  • PoS
  • Projekty
  • MRP
All apps
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
Pomoc

How to get string of selection field?

Odebírat

Get notified when there's activity on this post

This question has been flagged
odooodoo9odoo10odoo11odoo12
4 Odpovědi
81257 Zobrazení
Avatar
Alpesh Valaki

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
5
Avatar
Zrušit
Sehrish

Hope this will helps: https://learnopenerp.blogspot.com/2021/08/get-selection-field-value-instead-of-key-odoo.html

Avatar
Alpesh Valaki
Autor Nejlepší odpověď

it can be archive as follow.

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

if user select o

output O - Original


Better answer are welcome.

21
Avatar
Zrušit
Avatar
Martin Salcedo Pacheco
Nejlepší odpověď

Lets see some methods in selection fields

console_output = fields.Selection(
[
('console', 'Console'), ​#Consola
('screen', 'Screen'), ​#Pantalla
('both', 'Both') ​ ​#Ambos
], string="Console Output"
)

The original descriptions (Console, Screen...) can be retrieved with the selection property

self._fields['console_output'].selection     

this returns a tuple of values

[('console', 'Console'), ('screen', 'Screen'), ('both', 'Both')]

is most useful with dict()

dict(self._fields['console_output'].selection)

returns

{'console': 'Console', 'screen': 'Screen', 'both': 'Both'}

To retrieve the values translated as seen in the front use get_description() method. 

This method have all information of the field. The self.env is needed to translate the field label

self._fields['console_output'].get_description(self.env)

returns

{'type': 'selection', 'change_default': False, 'company_dependent': False, 'depends': (), 'manual': False, 'readonly': False, 'required': False, 'searchable': True, 'selection': [('console', 'Consola'), ('screen', 'Pantalla'), ('both', 'Ambos')], 'sortable': True, 'store': True, 'string': 'Salida por Consola'}

then, will use the selection key as dict to retrieve the value translated, so

field_info = dict(self._fields['console_output'].get_description(self.env))
field_selection = dict(field_info.get('selection'))
field_label = field_selection.get(self.console_output)


3
Avatar
Zrušit
Avatar
Cyril Gaspard (GEM)
Nejlepší odpověď
from odoo import api, models, _


def get_selection_label(self, object, field_name, field_value):
  return _(dict(self.env[object].fields_get(allfields=[field_name])[field_name]['selection'])[field_value])


class ResPartner(models.Model):
  _inherit = 'res.partner'

    def my_method(self):
        state_value_translated = get_selection_label(self, 'res.partner', 'state', self.state)
3
Avatar
Zrušit
Vairea Mana

After 2 hour of searching, I've found your solution, thank you, I'm exhausted

Avatar
Haresh Kansara
Nejlepší odpověď

https://www.odoo.com/forum/help-1/question/selection-field-label-42889

0
Avatar
Zrušit
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Přihlásit se
Related Posts Odpovědi Zobrazení Aktivita
Custom price for a line with two taxes.
odoo odoo10 odoo11 odoo12
Avatar
0
čvn 19
3328
why Odoo Release it's next version too early ? Vyřešeno
odoo odoo8 odoo9 odoo10 odoo11
Avatar
Avatar
Avatar
4
čvc 18
6597
how to set the default values of many2one field in wizard in odoo v12 Vyřešeno
odoo odoo11 odoo12
Avatar
Avatar
1
říj 22
8920
How to get Product name with single Attribute e.g: Product1(color)
odoo odoo11 odoo12
Avatar
Avatar
1
pro 18
5088
Call from one widget to another widget using odoo js. Vyřešeno
odoo9 odoo10 odoo11
Avatar
Avatar
1
srp 18
9982
Komunita
  • Tutoriály
  • Dokumentace
  • Fórum
Open Source
  • Stáhnout
  • Github
  • Runbot
  • Překlady
Služby
  • Odoo.sh hostování
  • Podpora
  • Upgrade
  • Nestandardní vývoj
  • Edukační program
  • Najít účetní
  • Najít partnera
  • Stát se partnerem
O nás
  • Naše společnost
  • Podklady značky
  • Kontakujte nás
  • Práce
  • Události
  • Podcast
  • Blog
  • Zákazníci
  • Právní dokumenty • Soukromí
  • Zabezpečení
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo je balíček open-source aplikací, které pokrývají všechny potřeby vaší společnosti: CRM, e-shop, účetnictví, sklady, kasy, projektové řízení a další.

Unikátní nabídka od Odoo poskytuje velmi jednoduché uživatelské rozhraní a vše je integrované na jednom místě.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now