Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] being able to customize context when running reports #1

Open
wants to merge 2 commits into
base: 8.0-webkit_report_account_multilang_fix
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions account_financial_report_webkit/report/common_balance_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def _get_account_details(self, account_ids, target_move, fiscalyear,
return accounts_by_id

def _get_comparison_details(self, data, account_ids, target_move,
comparison_filter, index):
comparison_filter, index, context=None):
"""

@param data: data of the wizard form
Expand Down Expand Up @@ -154,7 +154,7 @@ def _get_comparison_details(self, data, account_ids, target_move,
and self._get_initial_balance_mode(start) or False
accounts_by_ids = self._get_account_details(
account_ids, target_move, fiscalyear, details_filter,
start, stop, initial_balance_mode)
start, stop, initial_balance_mode, context=context)
comp_params = {
'comparison_filter': comparison_filter,
'fiscalyear': fiscalyear,
Expand Down Expand Up @@ -230,6 +230,11 @@ def _get_start_stop_for_filter(self, main_filter, fiscalyear, start_date,
return start_period, stop_period, start, stop

def compute_balance_data(self, data, filter_report_type=None):
lang = self.localcontext.get('lang')
lang_ctx = lang and {'lang': lang} or {}

lang_ctx.update(self._get_customized_context(data))

new_ids = data['form']['account_ids'] or data[
'form']['chart_account_id']
max_comparison = self._get_form_param(
Expand Down Expand Up @@ -265,20 +270,22 @@ def compute_balance_data(self, data, filter_report_type=None):
# get details for each accounts, total of debit / credit / balance
accounts_by_ids = self._get_account_details(
account_ids, target_move, fiscalyear, main_filter, start, stop,
initial_balance_mode)
initial_balance_mode, context=lang_ctx)

comparison_params = []
comp_accounts_by_ids = []
for index in range(max_comparison):
if comp_filters[index] != 'filter_no':
comparison_result, comp_params = self._get_comparison_details(
data, account_ids, target_move, comp_filters[index], index)
data, account_ids, target_move, comp_filters[index], index,
context=lang_ctx)
comparison_params.append(comp_params)
comp_accounts_by_ids.append(comparison_result)

objects = self.pool.get('account.account').browse(self.cursor,
self.uid,
account_ids)
account_ids,
context=lang_ctx)

to_display_accounts = dict.fromkeys(account_ids, True)
init_balance_accounts = dict.fromkeys(account_ids, False)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ def _get_partners_comparison_details(self, data, account_ids, target_move,
return accounts_details_by_ids, comp_params

def compute_partner_balance_data(self, data, filter_report_type=None):
lang = self.localcontext.get('lang')
lang_ctx = lang and {'lang': lang} or {}

lang_ctx.update(self._get_customized_context(data))

new_ids = data['form']['account_ids'] or data[
'form']['chart_account_id']
max_comparison = self._get_form_param(
Expand Down Expand Up @@ -259,7 +264,7 @@ def compute_partner_balance_data(self, data, filter_report_type=None):
# get details for each accounts, total of debit / credit / balance
accounts_by_ids = self._get_account_details(
account_ids, target_move, fiscalyear, main_filter, start, stop,
initial_balance_mode)
initial_balance_mode, context=lang_ctx)

partner_details_by_ids = self._get_account_partners_details(
accounts_by_ids, main_filter, target_move, start, stop,
Expand All @@ -280,7 +285,8 @@ def compute_partner_balance_data(self, data, filter_report_type=None):
comp_accounts_by_ids.append(comparison_result)
objects = self.pool.get('account.account').browse(self.cursor,
self.uid,
account_ids)
account_ids,
context=lang_ctx)

init_balance_accounts = {}
comparisons_accounts = {}
Expand Down
7 changes: 6 additions & 1 deletion account_financial_report_webkit/report/common_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,14 @@ class CommonReportHeaderWebkit(common_report_header):
"""Define common helper for financial report"""

######################################################################
# From getter helper #
# context customizer #
######################################################################
def _get_customized_context(self, data):
return {}

######################################################################
# From getter helper #
######################################################################
def get_start_period_br(self, data):
return self._get_info(data, 'period_from', 'account.period')

Expand Down
8 changes: 7 additions & 1 deletion account_financial_report_webkit/report/general_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ def __init__(self, cursor, uid, name, context):
def set_context(self, objects, data, ids, report_type=None):
"""Populate a ledger_lines attribute on each browse record that will be
used by mako template"""
lang = self.localcontext.get('lang')
lang_ctx = lang and {'lang': lang} or {}

lang_ctx.update(self._get_customized_context(data))

new_ids = data['form']['account_ids'] or data[
'form']['chart_account_id']

Expand Down Expand Up @@ -121,7 +126,8 @@ def set_context(self, objects, data, ids, report_type=None):
stop)
objects = self.pool.get('account.account').browse(self.cursor,
self.uid,
accounts)
accounts,
context=lang_ctx)

init_balance = {}
ledger_lines = {}
Expand Down
8 changes: 7 additions & 1 deletion account_financial_report_webkit/report/open_invoices.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ def _group_lines_by_currency(self, account_br):
def set_context(self, objects, data, ids, report_type=None):
"""Populate a ledger_lines attribute on each browse record that will
be used by mako template"""
lang = self.localcontext.get('lang')
lang_ctx = lang and {'lang': lang} or {}

lang_ctx.update(self._get_customized_context(data))

new_ids = data['form']['chart_account_id']
# Account initial balance memoizer
init_balance_memoizer = {}
Expand Down Expand Up @@ -147,7 +152,8 @@ def set_context(self, objects, data, ids, report_type=None):
partner_filter=partner_ids)
objects = self.pool.get('account.account').browse(self.cursor,
self.uid,
account_ids)
account_ids,
context=lang_ctx)

ledger_lines = {}
init_balance = {}
Expand Down
8 changes: 7 additions & 1 deletion account_financial_report_webkit/report/partners_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ def _get_initial_balance_mode(self, start_period):
def set_context(self, objects, data, ids, report_type=None):
"""Populate a ledger_lines attribute on each browse record that will
be used by mako template"""
lang = self.localcontext.get('lang')
lang_ctx = lang and {'lang': lang} or {}

lang_ctx.update(self._get_customized_context(data))

new_ids = data['form']['chart_account_id']

# account partner memoizer
Expand Down Expand Up @@ -148,7 +153,8 @@ def set_context(self, objects, data, ids, report_type=None):
partner_filter=partner_ids)
objects = self.pool.get('account.account').browse(self.cursor,
self.uid,
accounts)
accounts,
context=lang_ctx)

init_balance = {}
ledger_lines_dict = {}
Expand Down