Speed Improvement: accounting
bzr revid: fp@tinyerp.com-20080818210808-01v66l4mnwef6umw
This commit is contained in:
parent
b9b673502d
commit
9ab39c25da
|
@ -195,7 +195,6 @@ class account_account(osv.osv):
|
||||||
for i in ids2:
|
for i in ids2:
|
||||||
for a in range(len(field_names)):
|
for a in range(len(field_names)):
|
||||||
res[id][a] += accounts.get(i, (0.0,0.0,0.0))[a]
|
res[id][a] += accounts.get(i, (0.0,0.0,0.0))[a]
|
||||||
print res
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def _get_company_currency(self, cr, uid, ids, field_name, arg, context={}):
|
def _get_company_currency(self, cr, uid, ids, field_name, arg, context={}):
|
||||||
|
|
|
@ -35,20 +35,33 @@ class res_partner(osv.osv):
|
||||||
_name = 'res.partner'
|
_name = 'res.partner'
|
||||||
_inherit = 'res.partner'
|
_inherit = 'res.partner'
|
||||||
_description = 'Partner'
|
_description = 'Partner'
|
||||||
def _credit_get(self, cr, uid, ids, name, arg, context):
|
def _credit_debit_get(self, cr, uid, ids, field_names, arg, context):
|
||||||
res={}
|
|
||||||
query = self.pool.get('account.move.line')._query_get(cr, uid, context=context)
|
query = self.pool.get('account.move.line')._query_get(cr, uid, context=context)
|
||||||
for id in ids:
|
cr.execute(("""select
|
||||||
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))
|
l.partner_id, a.type, sum(l.debit-l.credit)
|
||||||
res[id]=cr.fetchone()[0] or 0.0
|
from
|
||||||
return res
|
account_move_line l
|
||||||
|
left join
|
||||||
def _debit_get(self, cr, uid, ids, name, arg, context):
|
account_account a on (l.account_id=a.id)
|
||||||
res={}
|
where
|
||||||
query = self.pool.get('account.move.line')._query_get(cr, uid, context=context)
|
a.type in ('receivable','payable') and
|
||||||
for id in ids:
|
l.partner_id in (%s) and
|
||||||
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))
|
l.reconcile_id is null and
|
||||||
res[id]=cr.fetchone()[0] or 0.0
|
""" % (','.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
|
return res
|
||||||
|
|
||||||
def _credit_search(self, cr, uid, obj, name, args):
|
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))]
|
return [('id','in',map(lambda x:x[0], res))]
|
||||||
|
|
||||||
_columns = {
|
_columns = {
|
||||||
'credit': fields.function(_credit_get, fnct_search=_credit_search, method=True, string='Total Receivable'),
|
'credit': fields.function(_credit_debit_get, fnct_search=_credit_search, method=True, string='Total Receivable', multi='dc'),
|
||||||
'debit': fields.function(_debit_get, fnct_search=_debit_search, method=True, string='Total Payable'),
|
'debit': fields.function(_credit_debit_get, fnct_search=_debit_search, method=True, string='Total Payable', multi='dc'),
|
||||||
'debit_limit': fields.float('Payable Limit'),
|
'debit_limit': fields.float('Payable Limit'),
|
||||||
'property_account_payable': fields.property(
|
'property_account_payable': fields.property(
|
||||||
'account.account',
|
'account.account',
|
||||||
|
|
Loading…
Reference in New Issue