[FIX] Change SQL query for manual reconciliation partners such that partners appear...
authorJosse Colpaert <jco@openerp.com>
Mon, 18 Mar 2013 11:30:43 +0000 (12:30 +0100)
committerJosse Colpaert <jco@openerp.com>
Mon, 18 Mar 2013 11:30:43 +0000 (12:30 +0100)
bzr revid: jco@openerp.com-20130318113043-fm2gc0yrln630vjf

addons/account/account_move_line.py

index a96ed88..4aa7da9 100644 (file)
@@ -741,20 +741,17 @@ class account_move_line(osv.osv):
 
     def list_partners_to_reconcile(self, cr, uid, context=None):
         cr.execute(
-             """
-             SELECT partner_id
-             FROM (
-                SELECT l.partner_id, p.last_reconciliation_date, SUM(l.debit) AS debit, SUM(l.credit) AS credit
+             """SELECT partner_id FROM (
+                SELECT l.partner_id, p.last_reconciliation_date, SUM(l.debit) AS debit, SUM(l.credit) AS credit, MAX(l.date) AS max_reconcil_date
                 FROM account_move_line l
                 RIGHT JOIN account_account a ON (a.id = l.account_id)
                 RIGHT JOIN res_partner p ON (l.partner_id = p.id)
                     WHERE a.reconcile IS TRUE
                     AND l.reconcile_id IS NULL
-                    AND (p.last_reconciliation_date IS NULL OR l.date > p.last_reconciliation_date)
                     AND l.state <> 'draft'
                     GROUP BY l.partner_id, p.last_reconciliation_date
                 ) AS s
-                WHERE debit > 0 AND credit > 0
+                WHERE debit > 0 AND credit > 0 AND (last_reconciliation_date IS NULL OR max_reconcil_date > last_reconciliation_date)
                 ORDER BY last_reconciliation_date""")
         ids = cr.fetchall()
         ids = len(ids) and [x[0] for x in ids] or []