*added computation of debit/credit/balance for consolidation accounts
*small improvements bzr revid: qdp@tinyerp.com-20080925141735-7loyyuoe6cq9pfgr
This commit is contained in:
parent
f475834cfb
commit
703a2410d9
|
@ -160,14 +160,29 @@ class account_account(osv.osv):
|
||||||
return super(account_account,self).search(cr, uid, args, offset, limit,
|
return super(account_account,self).search(cr, uid, args, offset, limit,
|
||||||
order, context=context, count=count)
|
order, context=context, count=count)
|
||||||
|
|
||||||
|
def _get_children_and_consol(self, cr, uid, ids, context={}):
|
||||||
|
#this function search for all the children and all consolidated children (recursively) of the given account ids
|
||||||
|
res = self.search(cr, uid, [('parent_id', 'child_of', ids)])
|
||||||
|
for id in res:
|
||||||
|
this = self.browse(cr, uid, id, context)
|
||||||
|
for child in this.child_consol_ids:
|
||||||
|
if child.id not in res:
|
||||||
|
res.append(child.id)
|
||||||
|
if len(res) != len(ids):
|
||||||
|
return self._get_children_and_consol(cr, uid, res, context)
|
||||||
|
return res
|
||||||
|
|
||||||
def __compute(self, cr, uid, ids, field_names, arg, context={}, query=''):
|
def __compute(self, cr, uid, ids, field_names, arg, context={}, query=''):
|
||||||
|
#compute the balance/debit/credit accordingly to the value of field_name for the given account ids
|
||||||
mapping = {
|
mapping = {
|
||||||
'balance': "COALESCE(SUM(l.debit) - SUM(l.credit), 0) as balance ",
|
'balance': "COALESCE(SUM(l.debit) - SUM(l.credit), 0) as balance ",
|
||||||
'debit': "COALESCE(SUM(l.debit), 0) as debit ",
|
'debit': "COALESCE(SUM(l.debit), 0) as debit ",
|
||||||
'credit': "COALESCE(SUM(l.credit), 0) as credit "
|
'credit': "COALESCE(SUM(l.credit), 0) as credit "
|
||||||
}
|
}
|
||||||
ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)])
|
#get all the necessary accounts
|
||||||
|
ids2 = self._get_children_and_consol(cr, uid, ids, context)
|
||||||
acc_set = ",".join(map(str, ids2))
|
acc_set = ",".join(map(str, ids2))
|
||||||
|
#compute for each account the balance/debit/credit from the move lines
|
||||||
accounts = {}
|
accounts = {}
|
||||||
if ids2:
|
if ids2:
|
||||||
query = self.pool.get('account.move.line')._query_get(cr, uid,
|
query = self.pool.get('account.move.line')._query_get(cr, uid,
|
||||||
|
@ -184,13 +199,29 @@ class account_account(osv.osv):
|
||||||
for res in cr.dictfetchall():
|
for res in cr.dictfetchall():
|
||||||
accounts[res['id']] = res
|
accounts[res['id']] = res
|
||||||
|
|
||||||
|
#for the asked accounts, get from the dictionnary 'accounts' the value of it
|
||||||
res = {}
|
res = {}
|
||||||
for id in ids:
|
for id in ids:
|
||||||
res[id] = {}.fromkeys(field_names, 0.0)
|
res[id] = self._get_account_values(cr, uid, id, accounts, field_names, context)
|
||||||
ids2 = self.search(cr, uid, [('parent_id', 'child_of', [id])])
|
return res
|
||||||
|
|
||||||
|
def _get_account_values(self, cr, uid, id, accounts, field_names, context={}):
|
||||||
|
res = {}.fromkeys(field_names, 0.0)
|
||||||
|
browse_rec = self.browse(cr, uid, id)
|
||||||
|
if browse_rec.type == 'consolidation':
|
||||||
|
ids2 = self.read(cr, uid, [browse_rec.id], ['child_consol_ids'], context)[0]['child_consol_ids']
|
||||||
|
for t in self.search(cr, uid, [('parent_id', 'child_of', [browse_rec.id])]):
|
||||||
|
if t not in ids2 and t != browse_rec.id:
|
||||||
|
ids2.append(t)
|
||||||
|
for i in ids2:
|
||||||
|
tmp = self._get_account_values(cr, uid, i, accounts, field_names, context)
|
||||||
|
for a in field_names:
|
||||||
|
res[a] += tmp[a]
|
||||||
|
else:
|
||||||
|
ids2 = self.search(cr, uid, [('parent_id', 'child_of', [browse_rec.id])])
|
||||||
for i in ids2:
|
for i in ids2:
|
||||||
for a in field_names:
|
for a in field_names:
|
||||||
res[id][a] += accounts.get(i, {}).get(a, 0.0)
|
res[a] += accounts.get(i, {}).get(a, 0.0)
|
||||||
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={}):
|
||||||
|
@ -216,7 +247,7 @@ class account_account(osv.osv):
|
||||||
_columns = {
|
_columns = {
|
||||||
'name': fields.char('Name', size=128, required=True, select=True),
|
'name': fields.char('Name', size=128, required=True, select=True),
|
||||||
'currency_id': fields.many2one('res.currency', 'Secondary Currency', help="Force all moves for this account to have this secondary currency."),
|
'currency_id': fields.many2one('res.currency', 'Secondary Currency', help="Force all moves for this account to have this secondary currency."),
|
||||||
'code': fields.char('Code', size=64),
|
'code': fields.char('Code', size=64, required=True),
|
||||||
'type': fields.selection([
|
'type': fields.selection([
|
||||||
('receivable','Receivable'),
|
('receivable','Receivable'),
|
||||||
('payable','Payable'),
|
('payable','Payable'),
|
||||||
|
@ -229,7 +260,7 @@ class account_account(osv.osv):
|
||||||
'user_type': fields.many2one('account.account.type', 'Account Type', required=True),
|
'user_type': fields.many2one('account.account.type', 'Account Type', required=True),
|
||||||
'parent_id': fields.many2one('account.account','Parent', ondelete='cascade'),
|
'parent_id': fields.many2one('account.account','Parent', ondelete='cascade'),
|
||||||
'child_parent_ids':fields.one2many('account.account','parent_id','Children'),
|
'child_parent_ids':fields.one2many('account.account','parent_id','Children'),
|
||||||
'child_consol_ids':fields.many2many('account.account', 'account_account_consol_rel', 'child_id', 'parent_id', 'Consolidated Children',domain=[('type', '=', 'consolidation')]),
|
'child_consol_ids':fields.many2many('account.account', 'account_account_consol_rel', 'child_id', 'parent_id', 'Consolidated Children'),
|
||||||
'child_id': fields.function(_get_child_ids, method=True, type='many2many',relation="account.account",string="Children Accounts"),
|
'child_id': fields.function(_get_child_ids, method=True, type='many2many',relation="account.account",string="Children Accounts"),
|
||||||
'balance': fields.function(__compute, digits=(16,2), method=True, string='Balance', multi='balance'),
|
'balance': fields.function(__compute, digits=(16,2), method=True, string='Balance', multi='balance'),
|
||||||
'credit': fields.function(__compute, digits=(16,2), method=True, string='Credit', multi='balance'),
|
'credit': fields.function(__compute, digits=(16,2), method=True, string='Credit', multi='balance'),
|
||||||
|
@ -245,7 +276,7 @@ class account_account(osv.osv):
|
||||||
|
|
||||||
'parent_left': fields.integer('Parent Left', select=1),
|
'parent_left': fields.integer('Parent Left', select=1),
|
||||||
'parent_right': fields.integer('Parent Right', select=1),
|
'parent_right': fields.integer('Parent Right', select=1),
|
||||||
'check_history': fields.boolean('Display History', help="Check this box if you want to print all entries otherwise it will print balance of this account")
|
'check_history': fields.boolean('Display History', help="Check this box if you want to print all entries when printing the General Ledger, otherwise it will only print its balance.")
|
||||||
}
|
}
|
||||||
|
|
||||||
def _default_company(self, cr, uid, context={}):
|
def _default_company(self, cr, uid, context={}):
|
||||||
|
|
Loading…
Reference in New Issue