![](/img/trans.png)
[英]How to get total amount after applying coupon in Stripe payment gateway
[英]How to get Invoice Payment amount - Custom Report
我正在發票模塊中創建自定義報告。
<span class="text-nowrap" t-esc="doc.invoice_payments_widget" />
我添加了上面的代碼,它返回 jSON 格式。 但我只需要得到金額。
{"title": "Less Payment", "outstanding": false, "content": [{"name": "Customer Payment: INV/2021/0006", "journal_name": "Bank", "amount": 500.0, "currency": "$", "digits": [69, 2], "position": "before", "date": "2021-03-26", "payment_id": 25, "account_payment_id": 2, "payment_method_name": "Manual", "move_id": 11, "ref": "BNK1/2021/0002 (INV/2021/0006)"}]}
可能有不止一筆付款,因此您應該總結content
字典的所有金額。
sum([content.get('amount', 0.0)
for content in doc.invoice_payments_widget.get('content', [])])
我會為它編寫一個方法,將它綁定到報告並調用它。 它也會更干凈。
如果返回 json,首先需要使用 json 庫將其轉換為 Python 結構:
import json
data = json.loads('{"title": "Less Payment", "outstanding": false, "content": [{"name": "Customer Payment: INV/2021/0006", "journal_name": "Bank", "amount": 500.0, "currency": "$", "digits": [69, 2], "position": "before", "date": "2021-03-26", "payment_id": 25, "account_payment_id": 2, "payment_method_name": "Manual", "move_id": 11, "ref": "BNK1/2021/0002 (INV/2021/0006)"}]}')
從那里您可以使用標准代碼,例如CZoellner建議的。 如果您不理解該答案,您可以查找 Python 的“列表理解”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.