diff --git a/addons/account/account.py b/addons/account/account.py index 081f8fe1568..38c489f6da4 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -2954,6 +2954,7 @@ class account_financial_report(osv.osv): return res def _get_balance(self, cr, uid, ids, name, args, context=None): + account_obj = self.pool.get('account.account') res = {} res_all = {} for report in self.browse(cr, uid, ids, context=context): @@ -2964,6 +2965,12 @@ class account_financial_report(osv.osv): # it's the sum of balance of the linked accounts for a in report.account_ids: balance += a.balance + elif report.type == 'account_type': + # it's the sum of balance of the leaf accounts with such an account type + report_types = [x.id for x in report.account_type_ids] + account_ids = account_obj.search(cr, uid, [('user_type','in', report_types), ('type','!=','view')], context=context) + for a in account_obj.browse(cr, uid, account_ids, context=context): + balance += a.balance elif report.type == 'account_report' and report.account_report_id: # it's the amount of the linked report res2 = self._get_balance(cr, uid, [report.account_report_id.id], 'balance', False, context=context) diff --git a/addons/account/report/account_financial_report.py b/addons/account/report/account_financial_report.py index ab8f3f7cb6f..837b3dee6ff 100644 --- a/addons/account/report/account_financial_report.py +++ b/addons/account/report/account_financial_report.py @@ -65,32 +65,28 @@ class report_account_common(report_sxw.rml_parse, common_report_header): lines.append(vals) account_ids = [] if report.type == 'accounts' and report.account_ids: - if report.display_detail == 'only_detail': - account_ids = account_obj._get_children_and_consol(self.cr, self.uid, [x.id for x in report.account_ids]) - elif report.display_detail == 'detail_with_hierarchy': - account_ids = [x.id for x in report.account_ids] + account_ids = account_obj._get_children_and_consol(self.cr, self.uid, [x.id for x in report.account_ids]) elif report.type == 'account_type' and report.account_type_ids: account_ids = account_obj.search(self.cr, self.uid, [('user_type','in', [x.id for x in report.account_type_ids])]) account_ids.sort() if account_ids: for account in account_obj.browse(self.cr, self.uid, account_ids, context=data['form']['used_context']): - if report.display_detail == 'detail_with_hierarchy' or account.type != 'view': - flag = False - vals = { - 'name': account.code + ' ' + account.name, - 'balance': account.balance != 0 and account.balance * report.sign or account.balance, - 'type': 'account', - 'level': 6, - 'account_type': account.type, - } - if not currency_obj.is_zero(self.cr, self.uid, account.company_id.currency_id, vals['balance']): + flag = False + vals = { + 'name': account.code + ' ' + account.name, + 'balance': account.balance != 0 and account.balance * report.sign or account.balance, + 'type': 'account', + 'level': report.display_detail == 'detail_with_hierarchy' and min(account.level,6) or 6, + 'account_type': account.type, + } + if not currency_obj.is_zero(self.cr, self.uid, account.company_id.currency_id, vals['balance']): + flag = True + if data['form']['enable_filter']: + vals['balance_cmp'] = account_obj.browse(self.cr, self.uid, account.id, context=data['form']['comparison_context']).balance + if not currency_obj.is_zero(self.cr, self.uid, account.company_id.currency_id, vals['balance_cmp']): flag = True - if data['form']['enable_filter']: - vals['balance_cmp'] = account_obj.browse(self.cr, self.uid, account.id, context=data['form']['comparison_context']).balance - if not currency_obj.is_zero(self.cr, self.uid, account.company_id.currency_id, vals['balance_cmp']): - flag = True - if flag: - lines.append(vals) + if flag: + lines.append(vals) return lines report_sxw.report_sxw('report.account.financial.report', 'account.financial.report',