[MERGE] merge pap branch for account auto reconcile with boolean field and improved it
bzr revid: mra@mra-laptop-20100614114611-35tk2vzq4dizmmb4
This commit is contained in:
parent
3976bb7ce7
commit
e5404a2936
|
@ -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:
|
|
@ -8,20 +8,28 @@
|
|||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Reconciliation">
|
||||
<group width="660" height="430">
|
||||
<separator string="Options" colspan="4"/>
|
||||
<group>
|
||||
<field name="account_ids" colspan="4" domain="[('reconcile','=',1)]"/>
|
||||
<field name="date1"/>
|
||||
<field name="date2"/>
|
||||
<field name="power"/>
|
||||
<separator string="Write-Off Move" colspan="4"/>
|
||||
<field name="max_amount"/>
|
||||
<field name="writeoff_acc_id"/>
|
||||
<field name="journal_id"/>
|
||||
<field name="period_id"/>
|
||||
<field name="allow_write_off"/>
|
||||
</group>
|
||||
<newline/>
|
||||
<group attrs="{'readonly':[('allow_write_off', '!=', True)]}">
|
||||
<separator string="Write-Off Move" colspan="4"/>
|
||||
<field name="max_amount"/>
|
||||
<field name="writeoff_acc_id" attrs="{ 'required':[('allow_write_off', '=', True)]}"/>
|
||||
<field name="journal_id" attrs="{ 'required':[('allow_write_off', '=', True)]}"/>
|
||||
<field name="period_id" attrs="{ 'required':[('allow_write_off', '=', True)]}"/>
|
||||
</group>
|
||||
<separator string ="" colspan="4"/>
|
||||
<group colspan="2" col="4">
|
||||
<button special="cancel" string="Cancel" icon="gtk-cancel"/>
|
||||
<button name="reconcile" string="Reconcile" type="object" icon="gtk-ok"/>
|
||||
<button name="reconcile" string="Reconcile" type="object" icon="gtk-ok" context="{'allow_write_off': allow_write_off}"/>
|
||||
</group>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
|
@ -64,4 +72,3 @@
|
|||
|
||||
</data>
|
||||
</openerp>
|
||||
|
||||
|
|
Loading…
Reference in New Issue