[FIX] Account: automatic reconciliation

bzr revid: mra@mra-laptop-20100908074618-k5lvbkbe10m2vv28
This commit is contained in:
Mustufa Rangwala 2010-09-08 13:16:18 +05:30
parent 92a04d862c
commit 68464d2e8a
1 changed files with 11 additions and 7 deletions

View File

@ -144,18 +144,21 @@ class account_automatic_reconcile(osv.osv_memory):
form = self.read(cr, uid, ids, [])[0]
max_amount = form.get('max_amount', 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']:
if not context.get('allow_write_off', False):
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"%(account_id, 0.0)
HAVING ABS(SUM(debit-credit)) = %s AND count(*)>0"%(account_id, 0.0)
# HAVING ABS(SUM(debit-credit)) <> %s AND count(*)>0"%(account_id, 0.0)
# HAVING count(*)>0"%(account_id,)
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"%(account_id, max_amount or 0.0)
HAVING ABS(SUM(debit-credit)) < %s AND count(*)>0"%(account_id, max_amount or 0.0)
# reconcile automatically all transactions from partners whose balance is 0
cr.execute(query)
partner_ids = [id for (id,) in cr.fetchall()]
@ -171,10 +174,12 @@ class account_automatic_reconcile(osv.osv_memory):
line_ids = [id for (id,) in cr.fetchall()]
if len(line_ids):
reconciled += len(line_ids)
if not context.get('allow_write_off', False):
move_line_obj.reconcile_partial(cr, uid, line_ids, 'manual', context={})
else:
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(
@ -241,7 +246,6 @@ class account_automatic_reconcile(osv.osv_memory):
'type': 'ir.actions.act_window',
'target': 'new',
'context': context,
'nodestroy':True, #remove me
}
account_automatic_reconcile()