[FIX] account, automatic reconcile wizard: major bug due to a wrong indentation fixed + small issue (+refactoring) of previous commit

bzr revid: qdp-launchpad@tinyerp.com-20100923145239-o1f650jf1jjg1ss7
This commit is contained in:
qdp-launchpad@tinyerp.com 2010-09-23 16:52:39 +02:00
parent 48215275b6
commit 78b33ac2c4
1 changed files with 55 additions and 56 deletions

View File

@ -141,23 +141,24 @@ class account_automatic_reconcile(osv.osv_memory):
if context is None:
context = {}
form = self.read(cr, uid, ids, [])[0]
max_amount = form.get('max_amount', 0.0)
max_amount = form.get('max_amount', False) and form.get('max_amount') or 0.0
power = form['power']
allow_write_off = form['allow_write_off']
reconciled = unreconciled = 0
if not form['account_ids']:
raise osv.except_osv(_('UserError'), _('You must select accounts to reconcile'))
for account_id in form['account_ids']:
params = (account_id,)
if not allow_write_off:
query = """SELECT partner_id FROM account_move_line WHERE account_id=%s AND reconcile_id IS NULL
AND state <> 'draft' GROUP BY partner_id
HAVING ABS(SUM(debit-credit)) = %s AND count(*)>0"""
HAVING ABS(SUM(debit-credit)) = 0.0 AND count(*)>0"""
else:
query = """SELECT partner_id FROM account_move_line WHERE account_id=%s AND reconcile_id IS NULL
AND state <> 'draft' GROUP BY partner_id
HAVING ABS(SUM(debit-credit)) < %s AND count(*)>0"""
params.append(max_amount)
# reconcile automatically all transactions from partners whose balance is 0
params = (account_id, max_amount)
cr.execute(query, params)
partner_ids = [id for (id,) in cr.fetchall()]
for partner_id in partner_ids:
@ -174,65 +175,63 @@ class account_automatic_reconcile(osv.osv_memory):
reconciled += len(line_ids)
if allow_write_off:
move_line_obj.reconcile(cr, uid, line_ids, 'auto', form['writeoff_acc_id'], form['period_id'], form['journal_id'], context)
# move_line_obj.reconcile_partial(cr, uid, line_ids, 'manual', context={})
else:
move_line_obj.reconcile_partial(cr, uid, line_ids, 'manual', context={})
# move_line_obj.reconcile(cr, uid, line_ids, 'auto', form['writeoff_acc_id'], form['period_id'], form['journal_id'], context)
# 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()]
#filter?
for partner_id in partner_ids:
# 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 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()]
#filter?
for partner_id in partner_ids:
# 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()
# 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
(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]
unreconciled = unreconciled + additional_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]
unreconciled = unreconciled + additional_unrec
context.update({'reconciled': reconciled, 'unreconciled': unreconciled})
model_data_ids = obj_model.search(cr,uid,[('model','=','ir.ui.view'),('name','=','account_automatic_reconcile_view1')])
resource_id = obj_model.read(cr, uid, model_data_ids, fields=['res_id'])[0]['res_id']