'returns a dictionary with key=the ID of a record and value=the credit, debit and balance amount
computed for this record. If the record is of typeÂ :
\'accounts\'Â : it\'s the sum of the linked accounts
\'account_type\'Â : it\'s the sum of leaf accoutns with such an account_type
\'account_report\'Â : it\'s the amount of the related report
\'sum\'Â : it\'s the sum of the children of this record (aka a \'view\' record)'

def _compute_report_balance(self, reports):

    res = {}
    fields = ['credit', 'debit', 'balance']
    for report in reports:
        if (report.id in res):
            continue
        res[report.id] = dict(((fn, 0.0) for fn in fields))
        if (report.type == 'accounts'):
            res[report.id]['account'] = self._compute_account_balance(report.account_ids)
            for value in res[report.id]['account'].values():
                for field in fields:
                    res[report.id][field] += value.get(field)
        elif (report.type == 'account_type'):
            accounts = self.env['account.account'].search([('user_type_id', 'in', report.account_type_ids.ids)])
            res[report.id]['account'] = self._compute_account_balance(accounts)
            for value in res[report.id]['account'].values():
                for field in fields:
                    res[report.id][field] += value.get(field)
        elif ((report.type == 'account_report') and report.account_report_id):
            res2 = self._compute_report_balance(report.account_report_id)
            for (key, value) in res2.items():
                for field in fields:
                    res[report.id][field] += value[field]
        elif (report.type == 'sum'):
            res2 = self._compute_report_balance(report.children_ids)
            for (key, value) in res2.items():
                for field in fields:
                    res[report.id][field] += value[field]
    return res
