diff --git a/addons/account/wizard/account_automatic_reconcile.py b/addons/account/wizard/account_automatic_reconcile.py index a1798ae9cbf..2a81dd9e62d 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={}): @@ -145,16 +146,18 @@ 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) + 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()] for partner_id in partner_ids: cr.execute( @@ -167,63 +170,67 @@ 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) + 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 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] - context.update({'reconciled': reconciled, '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'] return { @@ -239,4 +246,4 @@ class account_automatic_reconcile(osv.osv_memory): account_automatic_reconcile() -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file diff --git a/addons/account/wizard/account_automatic_reconcile_view.xml b/addons/account/wizard/account_automatic_reconcile_view.xml index 5afbbed7eed..4cb5915f8e4 100644 --- a/addons/account/wizard/account_automatic_reconcile_view.xml +++ b/addons/account/wizard/account_automatic_reconcile_view.xml @@ -8,20 +8,28 @@ form
+ + - - - - - + + + + + + + + + +