From 6c9afff057047724953ee14aed47eea34bd2650c Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Wed, 4 Mar 2015 15:20:17 +0100 Subject: [PATCH] [FIX] account_payment: amount in payment order is not correct. Amount in payment order is not correct if the account move line has already been paid by another way. The right amount is in the residual field related with move_id to the account invoice. opw:628903, 628428 --- addons/account_payment/account_move_line.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/addons/account_payment/account_move_line.py b/addons/account_payment/account_move_line.py index 9cc300d2e4b..e8d67e6dd89 100644 --- a/addons/account_payment/account_move_line.py +++ b/addons/account_payment/account_move_line.py @@ -31,21 +31,15 @@ class account_move_line(osv.osv): (excepting cancelled orders)""" if not ids: return {} + res = dict.fromkeys(ids, 0.0) cr.execute("""SELECT ml.id, - CASE WHEN ml.amount_currency < 0 - THEN - ml.amount_currency - ELSE ml.credit - END - - (SELECT coalesce(sum(amount_currency),0) - FROM payment_line pl - INNER JOIN payment_order po - ON (pl.order_id = po.id) - WHERE move_line_id = ml.id - AND po.state != 'cancel') AS amount + (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),)) - r = dict(cr.fetchall()) - return r + res.update(cr.fetchall()) + return res def _to_pay_search(self, cr, uid, obj, name, args, context=None): if not args: