Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
9 Trả lời
29066 Lượt xem

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

With the new API I found this to work:


env['account.invoice']._columns['payment_method'].selection
Ảnh đại diện
Huỷ bỏ

Adding on to this, I was able to do a key lookup with this:

dict(env['account.invoice']._columns['state'].selection)[o.state]

Câu trả lời hay nhất

You can use this.

dict(self._fields['your_selection_field'].selection).get(self.your_selection_field)


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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,


Ảnh đại diện
Huỷ bỏ
Tác giả

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

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

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

Câu trả lời hay nhất

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/


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 11 16
8396
1
thg 3 15
3797
1
thg 5 21
4064
7
thg 11 20
47522
0
thg 5 20
6335