コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
9975 ビュー

From sales.order object, how do I get the associated invoices?

I have tried to extend class stock.picking like this and added a function field:

#Field:

payment_method = fields.Char(compute='_get_payment_terms',string='Payment Method',readonly=True)

#Method:

@api.depends(''sale_id.invoice_ids','sale_id.invoice_ids.payment_method_id','sale_id.invoice_ids.payment_method_id.name')

def _get_payment_terms(self):

self.payment_method = self.sale_id.invoice_ids and self.sale_id.invoice_ids[0].payment_method_id and self.sale_id.invoice_ids[0].payment_method_id.name or ''

When loading the module it says: fields = [model._fields[head]] KeyError: 'payment_method_id'

Is there anything obvious I could be missing?

アバター
破棄
最善の回答

Hello E.M.,

There is a m2m field called "invoice_ids" in Sale Order which contains all the Invoices related to the SO.

I don't see "payment_method_id" field in account.invoice. Make sure you are using right field. I guess you want to show "Payment  Terms". For this you have to use "payment_term" field which is in "account.invoice".

Hope this will resolve your issue.

Thanks,

アバター
破棄
著作者

In the GUI, if you select an invoice and go to "Other information" tab, you will find there: payment_method. That is what I am trying to recover.

Yes, you are right. But you are using wrong field in your code. You should use "payment_term" instead of "payment_method_id".

著作者

i finally found that I just had to use payment_method, not payment_method_id. However, if I do that I just got "bank_transfer", how can I get the descriptive text "Bank Transfer"

著作者

WOW I forgot payment_method was actually an extension I wrote a few months ago. Requesting support for your own custom module seems like kinda audacious.

関連投稿 返信 ビュー 活動
0
5月 15
9582
0
4月 15
4666
1
2月 16
6305
0
12月 15
3553
0
3月 15
4938