From 272c7b26fc651e613fe9d174153ee649315cd3cb Mon Sep 17 00:00:00 2001 From: Wolfgang Taferner Date: Tue, 31 May 2016 06:51:47 +0200 Subject: [PATCH] [FIX] account: fix potential traceback `all([]) = True`, therefore if there is no `matched_debit_ids` or `matched_credit_ids` on a payment ==> boom when you access `payment.matched_debit_ids[0]` opw-677157 Closes #12232 Closes #12242 --- addons/account/models/account_invoice.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index 4f068187452..db9a8c57c7a 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -148,14 +148,17 @@ class AccountInvoice(models.Model): info = {'title': _('Less Payment'), 'outstanding': False, 'content': []} currency_id = self.currency_id for payment in self.payment_move_line_ids: + payment_currency_id = False if self.type in ('out_invoice', 'in_refund'): amount = sum([p.amount for p in payment.matched_debit_ids if p.debit_move_id in self.move_id.line_ids]) amount_currency = sum([p.amount_currency for p in payment.matched_debit_ids if p.debit_move_id in self.move_id.line_ids]) - payment_currency_id = all([p.currency_id == payment.matched_debit_ids[0].currency_id for p in payment.matched_debit_ids]) and payment.matched_debit_ids[0].currency_id or False + if payment.matched_debit_ids: + payment_currency_id = all([p.currency_id == payment.matched_debit_ids[0].currency_id for p in payment.matched_debit_ids]) and payment.matched_debit_ids[0].currency_id or False elif self.type in ('in_invoice', 'out_refund'): amount = sum([p.amount for p in payment.matched_credit_ids if p.credit_move_id in self.move_id.line_ids]) amount_currency = sum([p.amount_currency for p in payment.matched_credit_ids if p.credit_move_id in self.move_id.line_ids]) - payment_currency_id = all([p.currency_id == payment.matched_credit_ids[0].currency_id for p in payment.matched_credit_ids]) and payment.matched_credit_ids[0].currency_id or False + if payment.matched_credit_ids: + payment_currency_id = all([p.currency_id == payment.matched_credit_ids[0].currency_id for p in payment.matched_credit_ids]) and payment.matched_credit_ids[0].currency_id or False # get the payment value in invoice currency if payment_currency_id and payment_currency_id == self.currency_id: amount_to_show = amount_currency