_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={}):
'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
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 " \
(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)
-
- # 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()
+ 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 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 {