From bbfdc4429e78bf392ec4e6c92f9bda500c861e4b Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Thu, 3 Mar 2016 16:52:00 +0100 Subject: [PATCH] [IMP] account_financial_report_webkit: Allow to select account level on trial balance --- .../report/common_balance_reports.py | 12 ++++++++---- .../report/common_reports.py | 9 ++++++++- .../wizard/balance_common.py | 7 ++++++- .../wizard/trial_balance_wizard_view.xml | 3 +++ 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/account_financial_report_webkit/report/common_balance_reports.py b/account_financial_report_webkit/report/common_balance_reports.py index c9e236cb..4f5fbea3 100644 --- a/account_financial_report_webkit/report/common_balance_reports.py +++ b/account_financial_report_webkit/report/common_balance_reports.py @@ -230,8 +230,8 @@ class CommonBalanceReportHeaderWebkit(CommonReportHeaderWebkit): return start_period, stop_period, start, stop def compute_balance_data(self, data, filter_report_type=None): - new_ids = data['form']['account_ids'] or data[ - 'form']['chart_account_id'] + new_ids = (data['form']['account_ids'] or + [data['form']['chart_account_id']]) max_comparison = self._get_form_param( 'max_comparison', data, default=0) main_filter = self._get_form_param('filter', data, default='filter_no') @@ -259,10 +259,14 @@ class CommonBalanceReportHeaderWebkit(CommonReportHeaderWebkit): start) or False # Retrieving accounts + ctx = {} + if data['form'].get('account_level'): + # Filter by account level + ctx['account_level'] = int(data['form']['account_level']) account_ids = self.get_all_accounts( - new_ids, only_type=filter_report_type) + new_ids, only_type=filter_report_type, context=ctx) - # get details for each accounts, total of debit / credit / balance + # get details for each account, total of debit / credit / balance accounts_by_ids = self._get_account_details( account_ids, target_move, fiscalyear, main_filter, start, stop, initial_balance_mode) diff --git a/account_financial_report_webkit/report/common_reports.py b/account_financial_report_webkit/report/common_reports.py index cd7af7eb..240148bb 100644 --- a/account_financial_report_webkit/report/common_reports.py +++ b/account_financial_report_webkit/report/common_reports.py @@ -195,8 +195,15 @@ class CommonReportHeaderWebkit(common_report_header): acc_obj = self.pool.get('account.account') for account_id in account_ids: accounts.append(account_id) - accounts += acc_obj._get_children_and_consol( + children_acc_ids = acc_obj._get_children_and_consol( self.cursor, self.uid, account_id, context=context) + if context.get('account_level'): + domain = [('level', '<=', context['account_level']), + ('id', 'in', children_acc_ids)] + accounts += self.pool['account.account'].search( + self.cursor, self.uid, domain) + else: + accounts += children_acc_ids res_ids = list(set(accounts)) res_ids = self.sort_accounts_with_structure( account_ids, res_ids, context=context) diff --git a/account_financial_report_webkit/wizard/balance_common.py b/account_financial_report_webkit/wizard/balance_common.py index 97a67ec5..fe4b85d0 100644 --- a/account_financial_report_webkit/wizard/balance_common.py +++ b/account_financial_report_webkit/wizard/balance_common.py @@ -96,6 +96,11 @@ class AccountBalanceCommonWizard(orm.TransientModel): help='Filter by date: no opening balance will be displayed. ' '(opening balance can only be computed based on period to be \ correct).'), + # Set statically because of the impossibility of changing the selection + # field when changing chart_account_id + 'account_level': fields.selection( + [('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'), + ('6', '6')], string="Account level"), } for index in range(COMPARISON_LEVEL): @@ -394,7 +399,7 @@ class AccountBalanceCommonWizard(orm.TransientModel): # will be used to attach the report on the main account data['ids'] = [data['form']['chart_account_id']] - fields_to_read = ['account_ids', ] + fields_to_read = ['account_ids', 'account_level'] fields_to_read += self.DYNAMIC_FIELDS vals = self.read(cr, uid, ids, fields_to_read, context=context)[0] diff --git a/account_financial_report_webkit/wizard/trial_balance_wizard_view.xml b/account_financial_report_webkit/wizard/trial_balance_wizard_view.xml index c488a3fd..19d56efe 100644 --- a/account_financial_report_webkit/wizard/trial_balance_wizard_view.xml +++ b/account_financial_report_webkit/wizard/trial_balance_wizard_view.xml @@ -22,6 +22,9 @@ + + +