Speed Improvement: accounting

bzr revid: fp@tinyerp.com-20080818210808-01v66l4mnwef6umw
This commit is contained in:
Fabien Pinckaers 2008-08-18 23:08:08 +02:00
parent b9b673502d
commit 9ab39c25da
2 changed files with 28 additions and 16 deletions

View File

@ -195,7 +195,6 @@ class account_account(osv.osv):
for i in ids2:
for a in range(len(field_names)):
res[id][a] += accounts.get(i, (0.0,0.0,0.0))[a]
print res
return res
def _get_company_currency(self, cr, uid, ids, field_name, arg, context={}):

View File

@ -35,20 +35,33 @@ class res_partner(osv.osv):
_name = 'res.partner'
_inherit = 'res.partner'
_description = 'Partner'
def _credit_get(self, cr, uid, ids, name, arg, context):
res={}
def _credit_debit_get(self, cr, uid, ids, field_names, arg, context):
query = self.pool.get('account.move.line')._query_get(cr, uid, context=context)
for id in ids:
cr.execute("select sum(debit-credit) from account_move_line as l where account_id in (select id from account_account where type = %s and active) and partner_id=%d and reconcile_id is null and "+query, ('receivable', id))
res[id]=cr.fetchone()[0] or 0.0
return res
def _debit_get(self, cr, uid, ids, name, arg, context):
res={}
query = self.pool.get('account.move.line')._query_get(cr, uid, context=context)
for id in ids:
cr.execute("select sum(debit-credit) from account_move_line as l where account_id in (select id from account_account where type = %s and active) and partner_id=%d and reconcile_id is null and "+query, ('payable', id))
res[id]=cr.fetchone()[0] or 0.0
cr.execute(("""select
l.partner_id, a.type, sum(l.debit-l.credit)
from
account_move_line l
left join
account_account a on (l.account_id=a.id)
where
a.type in ('receivable','payable') and
l.partner_id in (%s) and
l.reconcile_id is null and
""" % (','.join(map(str, ids)),))+query+"""
group by
l.partner_id, a.type
""")
tinvert = {
'credit': 'receivable',
'debit': 'payable'
}
maps = {}
for i in range(len(field_names)):
maps[{'credit': 'receivable', 'debit': 'payable' }[field_names[i]]] = i
res = {}.fromkeys(ids, map(lambda x: 0.0, field_names))
for pid,type,val in cr.fetchall():
if type in maps:
res[pid][maps[type]] = val
return res
def _credit_search(self, cr, uid, obj, name, args):
@ -74,8 +87,8 @@ class res_partner(osv.osv):
return [('id','in',map(lambda x:x[0], res))]
_columns = {
'credit': fields.function(_credit_get, fnct_search=_credit_search, method=True, string='Total Receivable'),
'debit': fields.function(_debit_get, fnct_search=_debit_search, method=True, string='Total Payable'),
'credit': fields.function(_credit_debit_get, fnct_search=_credit_search, method=True, string='Total Receivable', multi='dc'),
'debit': fields.function(_credit_debit_get, fnct_search=_debit_search, method=True, string='Total Payable', multi='dc'),
'debit_limit': fields.float('Payable Limit'),
'property_account_payable': fields.property(
'account.account',