diff --git a/addons/account/account_financial_report.py b/addons/account/account_financial_report.py index 0688d6f12b1..62bcf9dcbcd 100644 --- a/addons/account/account_financial_report.py +++ b/addons/account/account_financial_report.py @@ -55,39 +55,37 @@ class account_financial_report(osv.osv): res += self._get_children_by_order(cr, uid, ids2, context=context) return res - def _get_balance(self, cr, uid, ids, name, args, context=None): + def _get_balance(self, cr, uid, ids, field_names, args, context=None): account_obj = self.pool.get('account.account') res = {} - res_all = {} for report in self.browse(cr, uid, ids, context=context): - balance = 0.0 - if report.id in res_all: - balance = res_all[report.id] - elif report.type == 'accounts': - # it's the sum of balance of the linked accounts + if report.id in res: + continue + res[report.id] = dict((fn, 0.0) for fn in field_names) + if report.type == 'accounts': + # it's the sum of the linked accounts for a in report.account_ids: - balance += a.balance + for field in field_names: + res[report.id][field] += getattr(a, field) elif report.type == 'account_type': - # it's the sum of balance of the leaf accounts with such an account type + # it's the sum 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 + for field in field_names: + res[report.id][field] += getattr(a, field) 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) - res_all.update(res2) + res2 = self._get_balance(cr, uid, [report.account_report_id.id], field_names, False, context=context) for key, value in res2.items(): - balance += value + for field in field_names: + res[report.id][field] += value[field] elif report.type == 'sum': - # it's the sum of balance of the children of this account.report - #for child in report.children_ids: - res2 = self._get_balance(cr, uid, [rec.id for rec in report.children_ids], 'balance', False, context=context) - res_all.update(res2) + # it's the sum of the children of this account.report + res2 = self._get_balance(cr, uid, [rec.id for rec in report.children_ids], field_names, False, context=context) for key, value in res2.items(): - balance += value - res[report.id] = balance - res_all[report.id] = balance + for field in field_names: + res[report.id][field] += value[field] return res _columns = { @@ -95,7 +93,9 @@ class account_financial_report(osv.osv): 'parent_id': fields.many2one('account.financial.report', 'Parent'), 'children_ids': fields.one2many('account.financial.report', 'parent_id', 'Account Report'), 'sequence': fields.integer('Sequence'), - 'balance': fields.function(_get_balance, 'Balance'), + 'balance': fields.function(_get_balance, 'Balance', multi='balance'), + 'debit': fields.function(_get_balance, 'Debit', multi='balance'), + 'credit': fields.function(_get_balance, 'Credit', multi="balance"), 'level': fields.function(_get_level, string='Level', store=True, type='integer'), 'type': fields.selection([ ('sum','View'), diff --git a/addons/account/report/account_financial_report.py b/addons/account/report/account_financial_report.py index eed42230aaf..4952814888a 100644 --- a/addons/account/report/account_financial_report.py +++ b/addons/account/report/account_financial_report.py @@ -61,6 +61,9 @@ class report_account_common(report_sxw.rml_parse, common_report_header): 'level': bool(report.style_overwrite) and report.style_overwrite or report.level, 'account_type': report.type =='sum' and 'view' or False, #used to underline the financial report balances } + if data['form']['debit_credit']: + vals['debit'] = report.debit + vals['credit'] = report.credit if data['form']['enable_filter']: vals['balance_cmp'] = self.pool.get('account.financial.report').browse(self.cr, self.uid, report.id, context=data['form']['comparison_context']).balance lines.append(vals) @@ -87,6 +90,11 @@ class report_account_common(report_sxw.rml_parse, common_report_header): 'level': report.display_detail == 'detail_with_hierarchy' and min(account.level + 1,6) or 6, #account.level + 1 'account_type': account.type, } + + if data['form']['debit_credit']: + vals['debit'] = account.debit + vals['credit'] = account.credit + lines.append(vals) if not currency_obj.is_zero(self.cr, self.uid, account.company_id.currency_id, vals['balance']): flag = True if data['form']['enable_filter']: diff --git a/addons/account/report/account_financial_report.rml b/addons/account/report/account_financial_report.rml index be2e349bd0c..6f0ddd0d625 100644 --- a/addons/account/report/account_financial_report.rml +++ b/addons/account/report/account_financial_report.rml @@ -143,7 +143,7 @@ - + @@ -205,8 +205,40 @@ + + + [[ data['form']['debit_credit'] == 1 or removeParentNode('blockTable') ]] + + + Name + + + Debit + + + Credit + + + Balance + + + + [[ repeatIn(get_lines(data), 'a') ]] + [[ (a.get('level') <> 0) or removeParentNode('tr') ]] + [[ setTag('tr','tr',{'style': 'Table'+str(min(3,'level' in a and a.get('level') or 1))}) ]] + [[ setTag('para','para',{'style': 'terp_level_'+str(min(6,a.get('level')))+'_name'}) ]][[ a.get('name') ]] + [[ setTag('para','para',{'style': 'terp_level_'+str(min(6,a.get('level')))+'_balance'}) ]][[ formatLang(a.get('debit',0.0), currency_obj = company.currency_id) ]] + [[ setTag('para','para',{'style': 'terp_level_'+str(min(6,a.get('level')))+'_balance'}) ]][[ formatLang(a.get('credit',0.0), currency_obj = company.currency_id) ]] + [[ (a.get('account_type') =='view' and a.get('level') <> 1) or removeParentNode('td') ]] + [[ setTag('para','para',{'style': 'terp_level_'+str(min(6,a.get('level')))+'_balance'}) ]][[ formatLang(a.get('balance'), currency_obj = company.currency_id) ]] + [[ (a.get('account_type') <>'view' or a.get('level') == 1) or removeParentNode('td') ]] + [[ setTag('para','para',{'style': 'terp_level_'+str(min(6,a.get('level')))+'_balance'}) ]][[ formatLang(a.get('balance'), currency_obj = company.currency_id) ]] + + + + - [[ data['form']['enable_filter'] == 0 or removeParentNode('blockTable') ]] + [[ (not data['form']['enable_filter'] and not data['form']['debit_credit']) or removeParentNode('blockTable') ]] Name @@ -229,8 +261,10 @@ + + - [[ data['form']['enable_filter'] == 1 or removeParentNode('blockTable') ]] + [[ (data['form']['enable_filter'] == 1 and not data['form']['debit_credit']) or removeParentNode('blockTable') ]] Name diff --git a/addons/account/wizard/account_financial_report.py b/addons/account/wizard/account_financial_report.py index e0a55374f29..0ddc50f4859 100644 --- a/addons/account/wizard/account_financial_report.py +++ b/addons/account/wizard/account_financial_report.py @@ -36,6 +36,7 @@ class accounting_report(osv.osv_memory): 'period_to_cmp': fields.many2one('account.period', 'End Period'), 'date_from_cmp': fields.date("Start Date"), 'date_to_cmp': fields.date("End Date"), + 'debit_credit': fields.boolean('Display Debit/Credit Columns', help="This option allow you to get more details about your the way your balances are computed. Because it is space consumming, we do not allow to use it while doing a comparison"), } def _get_account_report(self, cr, uid, context=None): @@ -85,7 +86,7 @@ class accounting_report(osv.osv_memory): return res def _print_report(self, cr, uid, ids, data, context=None): - data['form'].update(self.read(cr, uid, ids, ['date_from_cmp', 'date_to_cmp', 'fiscalyear_id_cmp', 'period_from_cmp', 'period_to_cmp', 'filter_cmp', 'account_report_id', 'enable_filter', 'label_filter'], context=context)[0]) + data['form'].update(self.read(cr, uid, ids, ['date_from_cmp', 'debit_credit', 'date_to_cmp', 'fiscalyear_id_cmp', 'period_from_cmp', 'period_to_cmp', 'filter_cmp', 'account_report_id', 'enable_filter', 'label_filter'], context=context)[0]) return { 'type': 'ir.actions.report.xml', 'report_name': 'account.financial.report', diff --git a/addons/account/wizard/account_financial_report_view.xml b/addons/account/wizard/account_financial_report_view.xml index 07f3e109ef8..f587141da1e 100644 --- a/addons/account/wizard/account_financial_report_view.xml +++ b/addons/account/wizard/account_financial_report_view.xml @@ -11,6 +11,7 @@ +