From 4530faae8ba8ecb80ae2765129302fd6c9718442 Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Fri, 13 Mar 2015 10:35:48 +0100 Subject: [PATCH] [FIX] account_payment: compute amount to pay compute the amount_to_pay with function field amount_residual on account.move.line opw:628903, 628428 --- addons/account_payment/account_move_line.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/addons/account_payment/account_move_line.py b/addons/account_payment/account_move_line.py index e8d67e6dd89..9068d8b729c 100644 --- a/addons/account_payment/account_move_line.py +++ b/addons/account_payment/account_move_line.py @@ -29,16 +29,14 @@ class account_move_line(osv.osv): def amount_to_pay(self, cr, uid, ids, name, arg=None, context=None): """ Return the amount still to pay regarding all the payemnt orders (excepting cancelled orders)""" + res = {} if not ids: - return {} - res = dict.fromkeys(ids, 0.0) - cr.execute("""SELECT ml.id, - (SELECT sum(coalesce(residual, 0)) - FROM account_invoice - WHERE move_id = ml.move_id) - FROM account_move_line ml - WHERE id IN %s""", (tuple(ids),)) - res.update(cr.fetchall()) + return res + for ml in self.browse(cr, uid, ids, context=context): + if ml.amount_currency: + res[ml.id] = ml.amount_residual_currency + else: + res[ml.id] = ml.amount_residual return res def _to_pay_search(self, cr, uid, obj, name, args, context=None):