Odoo Help

3

3
11 Answers
5
Avatar

Felipe Colombia

--Felipe--

1087
| 5 5 10
Bogotá, Colombia
--Felipe--
Informatics engineer Industrial engineer
Felipe Colombia
12/16/13, 11:10 AM
  • model is the name of the model, example: 'account.invoice'
  • field is the name of the field inside the model, example: 'state'
  • field_val is the value of that field, example: 'draft'

Code:

dict(self.pool.get(model).fields_get(cr, uid, allfields=[field], context=context)[field]['selection'])[field_val]

Example:

dict(self.pool.get('account.invoice').fields_get(cr, uid, allfields=['state'], context=context)['state']['selection'])['draft']
4 Comments
PY France
12/16/13, 11:18 AM

Hum, this is quite unreadable, can you give me an example ?

PY France
12/16/13, 11:22 AM

Well, thanks, I'll try this :)

PY France
12/16/13, 12:02 PM

Works fine, thanks again !

medhabib Malta
12/16/13, 12:24 PM

test=dict(self.pool.get('sale.order').fields_get(cr, uid, allfields=['state'], context=context))['state']['selection']

    print "***************order",test                 ///////////////[('draft', u'Devis brouillon'), ('sent', u'Devis envoy\xe9'), ('cancel', u'Annul\xe9e'), ('waiting_date', u'Attente de planification'), ('progress', u'Bon de commande'), ('manual', u'Commande \xe0 facturer'), ('shipping_except', u"Incident d'exp\xe9dition"), ('invoice_except', u'Incident de facturation'), ('done', u'Termin\xe9e')]
4
Alessandro Ruffolo Italy
10/1/15, 8:18 AM

I use another technique.

First I define the list of pairs code/value

VALUES = [('a', 'A'), ('b','B'), ('c','C')]

I use it into my field definition

f = fields.Selection(VALUES)

and to return value, given the code, with a dict

dict(VALUES)[self.f]

or with a simple loop

for item in VALUES:
if item[0] == self.f:
return item[1]
1 Comment
GLOBAL CREATIVE CONCEPTS TECH CO LTD - iWesabe Saudi Arabia
2/19/18, 3:50 AM

Super way ... especially for custom models

4
Avatar

Bejaoui Souheil Belgium

--Bejaoui Souheil--
1151
| 2 1 7
Waterloo, Belgium
--Bejaoui Souheil--

Odoo developer,  functional and technical consultant

souheil_bejaoui@hotmail.fr

Bejaoui Souheil Belgium
4/1/15, 9:54 AM

The V8 way:

use the @api.one decorator

  • current model :value = dict(self.fields_get(allfields=['state'])['state']['selection'])['key']

  • other model : value = dict(self.env['your.model'].fields_get(allfields=['state'])['state']['selection'])['key']

Hope this help somebody..

0
Avatar
--Haresh Kansara--

Odoo Application Engineer

I have completed odoo training from Odoo India, and i have formerly worked there as an application engineer. And currently works as an application engineer at jupical technologies pvt. ltd. 

I have worked on different projects like Sales, Purchase, MRP, Account etc. I have also worked on website development.

I can help you to:

- Develop new module

- Customise existing module

- Provide Odoo Functional / Technical training

Connect me at: https://www.linkedin.com/in/haresh-kansara-50048914b

Haresh Kansara India
9/25/19, 12:33 PM
-1
Alessandro Ruffolo Italy
10/1/15, 8:18 AM

I use another technique.

First I define the list of pairs code/value

VALUES = [('a', 'A'), ('b','B'), ('c','C')]

I use it into my field definition

f = fields.Selection(VALUES)

and to return value, given the code, with a dict

dict(VALUES)[self.f]

or with a simple loop

for item in VALUES:
if item[0] == self.f:

1 Comment
Alessandro Ruffolo Italy
10/1/15, 9:28 AM

there must be some error: i can't explain myself this duplicate answer...

Ask a Question
Writer
559
PY
Keep Informed
0 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now