From ae2c2900641ef3f3a4eebb897b58f20dfcf89b1b Mon Sep 17 00:00:00 2001 From: "pap (openerp)" Date: Fri, 11 Jun 2010 18:37:35 +0530 Subject: [PATCH 1/2] [IMP]:improved automatic reconcile wizard with partial reconciliation bzr revid: pap@tinyerp.co.in-20100611130735-vnbtqln7porxml1r --- .../wizard/account_automatic_reconcile.py | 150 ++++++++++-------- .../account_automatic_reconcile_view.xml | 20 ++- 2 files changed, 96 insertions(+), 74 deletions(-) diff --git a/addons/account/wizard/account_automatic_reconcile.py b/addons/account/wizard/account_automatic_reconcile.py index 2370c6dbe13..56cbd4ce028 100644 --- a/addons/account/wizard/account_automatic_reconcile.py +++ b/addons/account/wizard/account_automatic_reconcile.py @@ -31,15 +31,16 @@ class account_automatic_reconcile(osv.osv_memory): _columns = { 'account_ids': fields.many2many('account.account', 'reconcile_account_rel', 'reconcile_id', 'account_id', 'Account to reconcile', domain = [('reconcile','=',1)], \ help = 'If no account is specified, the reconciliation will be made using every accounts that can be reconcilied'), - 'writeoff_acc_id': fields.many2one('account.account', 'Account', required=True), - 'journal_id': fields.many2one('account.journal', 'Journal', required=True), - 'period_id': fields.many2one('account.period', 'Period', required=True), + 'writeoff_acc_id': fields.many2one('account.account', 'Account'), + 'journal_id': fields.many2one('account.journal', 'Journal'), + 'period_id': fields.many2one('account.period', 'Period'), 'max_amount': fields.float('Maximum write-off amount'), 'power': fields.selection([(p, str(p)) for p in range(2, 10)], 'Power', required=True), 'date1': fields.date('Start of period', required=True), 'date2': fields.date('End of period', required=True), 'reconciled': fields.integer('Reconciled transactions', readonly=True), 'unreconciled': fields.integer('Not reconciled transactions', readonly=True), + 'allow_write_off': fields.boolean('Allow write off') } def _get_reconciled(self, cr, uid, context={}): @@ -53,6 +54,7 @@ class account_automatic_reconcile(osv.osv_memory): 'date2': time.strftime('%Y-%m-%d'), 'reconciled': _get_reconciled, 'unreconciled': _get_unreconciled, + 'allow_write_off' : lambda *a: False } #TODO: cleanup and comment this code... For now, it is awfulllll @@ -146,18 +148,23 @@ class account_automatic_reconcile(osv.osv_memory): 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): + 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) +# query="SELECT partner_id FROM account_move_line WHERE account_id=%s AND reconcile_id IS NULL \ +# AND state <> 'draft' GROUP BY partner_id AND debit = credi"%(account_id) + print "query---\n",query + 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) # reconcile automatically all transactions from partners whose balance is 0 - cr.execute( - "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)) + cr.execute(query) partner_ids = [id for (id,) in cr.fetchall()] + print "\n\npartners--",partner_ids for partner_id in partner_ids: + print "partner''",partner_id cr.execute( "SELECT id " \ "FROM account_move_line " \ @@ -168,63 +175,70 @@ class account_automatic_reconcile(osv.osv_memory): (account_id, partner_id)) line_ids = [id for (id,) in cr.fetchall()] if len(line_ids): - move_line_obj.reconcile(cr, uid, line_ids, 'auto', form['writeoff_acc_id'], form['period_id'], form['journal_id'], context) - reconciled += 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: + 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 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}) 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'] return { diff --git a/addons/account/wizard/account_automatic_reconcile_view.xml b/addons/account/wizard/account_automatic_reconcile_view.xml index 5afbbed7eed..3e17c1df0d9 100644 --- a/addons/account/wizard/account_automatic_reconcile_view.xml +++ b/addons/account/wizard/account_automatic_reconcile_view.xml @@ -8,20 +8,28 @@ form
+ + - - - - - + + + + + + + + + +