Odoo Help

Welcome!

This community 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.

1

retrieving fields.Selection values, how???

By
E.M.
on 1/10/16, 9:30 AM 693 views

I have extended account_invoice so there is a simple descriptive payment method field.

 

 class account_invoice(models.Model):

   _inherit = "account.invoice"

   payment_method = fields.Selection(

     selection=[

      ('bank_transfer', 'Transferencia Bancaria'),

      ('check', 'Cheque'),

      ('confirming', 'Confirming'),

      ('bank_giro', 'Giro'),

     ('promisory_note', 'Pagaré'),

     ('direct_debit', 'Domiciliación')

      ],  string='Método de pago')


Provided that in another module payment_method variable points to that field and returns "bank_transfer", how can I get "Transferencia Bancaria" instead of "bank_transfer"?

Thanks

0

Daniel Reis

--Daniel Reis--
3436
| 6 7 9
Lisbon, Portugal
--Daniel Reis--

Author of the "Odoo Development Essentials" book.

Applications Manager at Securitas Portugal

Github: https://github.com/dreispt

Twitter; @reis_pt


Daniel Reis
On 4/11/16, 7:36 AM

With the new API I found this to work:


env['account.invoice']._columns['payment_method'].selection
0

Pawan

--Pawan--
1267
| 4 3 5
Hyderabad, India
--Pawan--


Pawan
On 1/11/16, 12:12 AM

EM,

You can use below line to get the selection field in form of dictionary...

dict(self.pool.get('account.invoice').fields_get(cr, uid, allfields=['payment_method'], context=context)['payment_method]['selection']

and then you can use your key to find out its relevant value:

its result will be like:

     {'direct_debit': 'Domiciliación', 'promisory_note': 'Pagaré', 'bank_giro': 'Giro', 'confirming':'Confirming','check': 'Cheque', 'bank_transfer': 'Transferencia Bancaria'}

then you can use normal dictionary functionality to retrive your desired key's value....

Hope it Helps!

Regards,


payment_method_dict = dict(self.pool.get('account.invoice').fields_get(cr, uid, allfields=['payment_method'], context=context)['payment_method']['selection']) NameError: global name 'cr' is not defined

E.M.
on 1/11/16, 6:40 PM

EM,
as u are using Odoo8 api, you can't use cr,uid direclty, you should use self.env.cr, self.env.uid, self.env.context, etc .....
I just gave you the format, you have to manipulate it as per your requirement ...

Pawan
on 1/12/16, 12:13 AM

as per your api, you can use it...
dict(self.env['account.invoice'].fields_get(allfields=['payment_method'])['payment_method]['selection']

Pawan
on 1/12/16, 12:17 AM
0
Mai Ecarde
On 1/11/16, 12:12 AM

I believe what you are asking is similar to https://www.odoo.com/es_ES/forum/help-1/question/how-to-use-the-value-of-a-selection-field-instead-of-its-key-in-a-python-function-39080/


Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 1/10/16, 9:30 AM
Seen: 693 times
Last updated: 4/11/16, 7:36 AM