- # get the list of unreconciled 'credit transactions' for this partner
- cr.execute(
- "SELECT id, credit " \
- "FROM account_move_line " \
- "WHERE account_id=%s " \
- "AND partner_id=%s " \
- "AND reconcile_id IS NULL " \
- "AND state <> 'draft' " \
- "AND credit > 0",
- (account_id, partner_id))
- credits = cr.fetchall()
-
- (rec, unrec) = self.do_reconcile(cr, uid, credits, debits, max_amount, power, form['writeoff_acc_id'], form['period_id'], form['journal_id'], context)
- reconciled += rec
- unreconciled += unrec
-
- # add the number of transactions for partners who have only one
- # unreconciled transactions to the unreconciled count
- partner_filter = partner_ids and 'AND partner_id not in (%s)' % ','.join(map(str, filter(None, partner_ids))) or ''
- cr.execute(
- "SELECT count(*) " \
- "FROM account_move_line " \
- "WHERE account_id=%s " \
- "AND reconcile_id IS NULL " \
- "AND state <> 'draft' " + partner_filter,
- (account_id,))
- additional_unrec = cr.fetchone()[0]
- context.update({'reconciled': reconciled, 'unreconciled': unreconciled + additional_unrec})
+ # get the list of partners who have more than one unreconciled transaction
+ cr.execute(
+ "SELECT partner_id " \
+ "FROM account_move_line " \
+ "WHERE account_id=%s " \
+ "AND reconcile_id IS NULL " \
+ "AND state <> 'draft' " \
+ "AND partner_id IS NOT NULL " \
+ "GROUP BY partner_id " \
+ "HAVING count(*)>1",
+ (account_id,))
+ partner_ids = [id for (id,) in cr.fetchall()]
+ print "partner_ids---",partner_ids
+ #filter?
+ for partner_id in partner_ids:
+ print "partner_id wid 1 unree--",partner_id
+ # get the list of unreconciled 'debit transactions' for this partner
+ cr.execute(
+ "SELECT id, debit " \
+ "FROM account_move_line " \
+ "WHERE account_id=%s " \
+ "AND partner_id=%s " \
+ "AND reconcile_id IS NULL " \
+ "AND state <> 'draft' " \
+ "AND debit > 0",
+ (account_id, partner_id))
+ debits = cr.fetchall()
+
+ # get the list of unreconciled 'credit transactions' for this partner
+ cr.execute(
+ "SELECT id, credit " \
+ "FROM account_move_line " \
+ "WHERE account_id=%s " \
+ "AND partner_id=%s " \
+ "AND reconcile_id IS NULL " \
+ "AND state <> 'draft' " \
+ "AND credit > 0",
+ (account_id, partner_id))
+ credits = cr.fetchall()
+
+ (rec, unrec) = self.do_reconcile(cr, uid, credits, debits, max_amount, power, form['writeoff_acc_id'], form['period_id'], form['journal_id'], context)
+ reconciled += rec
+ unreconciled += unrec
+
+ # add the number of transactions for partners who have only one
+ # unreconciled transactions to the unreconciled count
+ partner_filter = partner_ids and 'AND partner_id not in (%s)' % ','.join(map(str, filter(None, partner_ids))) or ''
+ cr.execute(
+ "SELECT count(*) " \
+ "FROM account_move_line " \
+ "WHERE account_id=%s " \
+ "AND reconcile_id IS NULL " \
+ "AND state <> 'draft' " + partner_filter,
+ (account_id,))
+ additional_unrec = cr.fetchone()[0]
+ print "additional_unrec----",additional_unrec, reconciled, unreconciled
+ unreconciled = unreconciled + additional_unrec
+ context.update({'reconciled': reconciled, 'unreconciled': unreconciled})