Browse Source

[CHG]account_financial_report_webkit: Migration to v8

pull/20/head
Anthony Muschang 10 years ago
parent
commit
8e76fe6e61
  1. 33
      account_financial_report_webkit/report/aged_partner_balance.py
  2. 53
      account_financial_report_webkit/report/common_balance_reports.py
  3. 52
      account_financial_report_webkit/report/common_partner_balance_reports.py
  4. 27
      account_financial_report_webkit/report/open_invoices.py
  5. 6
      account_financial_report_webkit/report/templates/account_report_partner_balance.mako
  6. 12
      account_financial_report_webkit/report/templates/account_report_trial_balance.mako
  7. 10
      account_financial_report_webkit/report/templates/aged_trial_webkit.mako

33
account_financial_report_webkit/report/aged_partner_balance.py

@ -128,6 +128,7 @@ class AccountAgedTrialBalanceWebkit(PartnersOpenInvoicesWebkit):
call to set_context
"""
res = super(AccountAgedTrialBalanceWebkit, self).set_context(
objects,
data,
@ -135,21 +136,35 @@ class AccountAgedTrialBalanceWebkit(PartnersOpenInvoicesWebkit):
report_type=report_type
)
agged_lines_accounts = {}
agged_totals_accounts = {}
agged_percents_accounts = {}
for acc in self.objects:
acc.aged_lines = {}
acc.agged_totals = {}
acc.agged_percents = {}
for part_id, partner_lines in acc.ledger_lines.items():
agged_lines_accounts[acc.id] = {}
agged_totals_accounts[acc.id] = {}
agged_percents_accounts[acc.id] = {}
for part_id, partner_lines in\
self.localcontext['ledger_lines'][acc.id].items():
aged_lines = self.compute_aged_lines(part_id,
partner_lines,
data)
if aged_lines:
acc.aged_lines[part_id] = aged_lines
acc.aged_totals = totals = self.compute_totals(
acc.aged_lines.values())
acc.aged_percents = self.compute_percents(totals)
agged_lines_accounts[acc.id][part_id] = aged_lines
agged_totals_accounts[acc.id] = totals = self.compute_totals(
agged_lines_accounts[acc.id].values())
agged_percents_accounts[acc.id] = self.compute_percents(totals)
self.localcontext.update({
'agged_lines_accounts': agged_lines_accounts,
'agged_totals_accounts': agged_totals_accounts,
'agged_percents_accounts': agged_percents_accounts,
})
# Free some memory
del(acc.ledger_lines)
del(self.localcontext['ledger_lines'])
return res
def compute_aged_lines(self, partner_id, ledger_lines, data):

53
account_financial_report_webkit/report/common_balance_reports.py

@ -276,23 +276,30 @@ class CommonBalanceReportHeaderWebkit(CommonReportHeaderWebkit):
comparison_params.append(comp_params)
comp_accounts_by_ids.append(comparison_result)
to_display = dict.fromkeys(account_ids, True)
objects = []
for account in self.pool.get('account.account').browse(self.cursor,
objects = self.pool.get('account.account').browse(self.cursor,
self.uid,
account_ids):
account_ids)
to_display_accounts = dict.fromkeys(account_ids, True)
init_balance_accounts = dict.fromkeys(account_ids, False)
comparisons_accounts = dict.fromkeys(account_ids, [])
debit_accounts = dict.fromkeys(account_ids, False)
credit_accounts = dict.fromkeys(account_ids, False)
balance_accounts = dict.fromkeys(account_ids, False)
for account in objects:
if not account.parent_id: # hide top level account
continue
if account.type == 'consolidation':
to_display.update(
to_display_accounts.update(
dict([(a.id, False) for a in account.child_consol_ids]))
elif account.type == 'view':
to_display.update(
to_display_accounts.update(
dict([(a.id, True) for a in account.child_id]))
account.debit = accounts_by_ids[account.id]['debit']
account.credit = accounts_by_ids[account.id]['credit']
account.balance = accounts_by_ids[account.id]['balance']
account.init_balance = accounts_by_ids[
debit_accounts['account_id'] = accounts_by_ids[account.id]['debit']
credit_accounts['account_id'] = accounts_by_ids[account.id]['credit']
balance_accounts['account_id'] = accounts_by_ids[account.id]['balance']
init_balance_accounts[account.id] = accounts_by_ids[
account.id].get('init_balance', 0.0)
# if any amount is != 0 in comparisons, we have to display the
@ -308,21 +315,18 @@ class CommonBalanceReportHeaderWebkit(CommonReportHeaderWebkit):
values.get('balance', 0.0),
values.get('init_balance', 0.0)))
comp_accounts.append(values)
account.comparisons = comp_accounts
comparisons_accounts[account.id] = comp_accounts
# we have to display the account if a comparison as an amount or
# if we have an amount in the main column
# we set it as a property to let the data in the report if someone
# want to use it in a custom report
display_account = display_account or any((account.debit,
account.credit,
account.balance,
account.init_balance))
to_display.update(
{account.id: display_account and to_display[account.id]})
objects.append(account)
for account in objects:
account.to_display = to_display[account.id]
display_account = display_account\
or any((account.debit,
account.credit, account.balance,
init_balance_accounts[account.id]))
to_display_accounts.update(
{account.id: display_account and
to_display_accounts[account.id]})
context_report_values = {
'fiscalyear': fiscalyear,
@ -336,5 +340,12 @@ class CommonBalanceReportHeaderWebkit(CommonReportHeaderWebkit):
'initial_balance': init_balance,
'initial_balance_mode': initial_balance_mode,
'comp_params': comparison_params,
'to_display_accounts': to_display_accounts,
'init_balance_accounts': init_balance_accounts,
'comparisons_accounts': comparisons_accounts,
'debit_accounts': debit_accounts,
'credit_accounts': credit_accounts,
'balance_accounts': balance_accounts,
}
return objects, new_ids, context_report_values

52
account_financial_report_webkit/report/common_partner_balance_reports.py

@ -278,19 +278,29 @@ class CommonPartnerBalanceReportHeaderWebkit(CommonBalanceReportHeaderWebkit,
partner_filter_ids=partner_ids)
comparison_params.append(comp_params)
comp_accounts_by_ids.append(comparison_result)
objects = []
for account in self.pool.get('account.account').browse(self.cursor,
objects = self.pool.get('account.account').browse(self.cursor,
self.uid,
account_ids):
account_ids)
init_balance_accounts = {}
comparisons_accounts = {}
partners_order_accounts = {}
partners_amounts_accounts = {}
debit_accounts = {}
credit_accounts = {}
balance_accounts = {}
for account in objects:
if not account.parent_id: # hide top level account
continue
account.debit = accounts_by_ids[account.id]['debit']
account.credit = accounts_by_ids[account.id]['credit']
account.balance = accounts_by_ids[account.id]['balance']
account.init_balance = accounts_by_ids[
debit_accounts[account.id] = accounts_by_ids[account.id]['debit']
credit_accounts[account.id] = accounts_by_ids[account.id]['credit']
balance_accounts[account.id] = \
accounts_by_ids[account.id]['balance']
init_balance_accounts[account.id] = accounts_by_ids[
account.id].get('init_balance', 0.0)
account.partners_amounts = partner_details_by_ids[account.id]
partners_amounts_accounts[account.id] =\
partner_details_by_ids[account.id]
comp_accounts = []
for comp_account_by_id in comp_accounts_by_ids:
values = comp_account_by_id.get(account.id)
@ -302,24 +312,25 @@ class CommonPartnerBalanceReportHeaderWebkit(CommonBalanceReportHeaderWebkit,
for partner_id, partner_values in \
values['partners_amounts'].copy().iteritems():
base_partner_balance = account.partners_amounts[
partner_id]['balance'] if \
account.partners_amounts.get(partner_id) else 0.0
base_partner_balance = partners_amounts_accounts[account.id][partner_id]['balance']\
if partners_amounts_accounts.get(account.id)\
and partners_amounts_accounts.get(account.id)\
.get(partner_id) else 0.0
partner_values.update(self._get_diff(
base_partner_balance,
partner_values.get('balance', 0.0)))
values['partners_amounts'][
partner_id].update(partner_values)
account.comparisons = comp_accounts
comparisons_accounts[account.id] = comp_accounts
all_partner_ids = reduce(add, [comp['partners_amounts'].keys()
for comp in comp_accounts],
account.partners_amounts.keys())
account.partners_order = self._order_partners(all_partner_ids)
partners_amounts_accounts[account.id]
.keys())
objects.append(account)
partners_order_accounts[account.id] = \
self._order_partners(all_partner_ids)
context_report_values = {
'fiscalyear': fiscalyear,
@ -333,6 +344,13 @@ class CommonPartnerBalanceReportHeaderWebkit(CommonBalanceReportHeaderWebkit,
'comp_params': comparison_params,
'initial_balance_mode': initial_balance_mode,
'compute_diff': self._get_diff,
'init_balance_accounts': init_balance_accounts,
'comparisons_accounts': comparisons_accounts,
'partners_order_accounts': partners_order_accounts,
'partners_amounts_accounts': partners_amounts_accounts,
'debit_accounts': debit_accounts,
'credit_accounts': credit_accounts,
'balance_accounts': balance_accounts,
}
return objects, new_ids, context_report_values

27
account_financial_report_webkit/report/open_invoices.py

@ -145,29 +145,35 @@ class PartnersOpenInvoicesWebkit(report_sxw.rml_parse,
ledger_lines_memoizer = self._compute_open_transactions_lines(
account_ids, main_filter, target_move, start, stop, date_until,
partner_filter=partner_ids)
objects = []
for account in self.pool.get('account.account').browse(self.cursor,
objects = self.pool.get('account.account').browse(self.cursor,
self.uid,
account_ids):
account.ledger_lines = ledger_lines_memoizer.get(account.id, {})
account.init_balance = init_balance_memoizer.get(account.id, {})
account_ids)
ledger_lines = {}
init_balance = {}
partners_order = {}
for account in objects:
ledger_lines[account.id] = ledger_lines_memoizer.get(account.id,
{})
init_balance[account.id] = init_balance_memoizer.get(account.id,
{})
# we have to compute partner order based on inital balance
# and ledger line as we may have partner with init bal
# that are not in ledger line and vice versa
ledg_lines_pids = ledger_lines_memoizer.get(account.id, {}).keys()
non_null_init_balances = dict([
(ib, amounts) for ib, amounts
in account.init_balance.iteritems()
in init_balance[account.id].iteritems()
if amounts['init_balance']
or amounts['init_balance_currency']])
init_bal_lines_pids = non_null_init_balances.keys()
account.partners_order = self._order_partners(
partners_order[account.id] = self._order_partners(
ledg_lines_pids, init_bal_lines_pids)
account.ledger_lines = ledger_lines_memoizer.get(account.id, {})
ledger_lines[account.id] = ledger_lines_memoizer.get(account.id,
{})
if group_by_currency:
self._group_lines_by_currency(account)
objects.append(account)
self.localcontext.update({
'fiscalyear': fiscalyear,
@ -178,6 +184,9 @@ class PartnersOpenInvoicesWebkit(report_sxw.rml_parse,
'date_until': date_until,
'partner_ids': partner_ids,
'chart_account': chart_account,
'ledger_lines': ledger_lines,
'init_balance': init_balance,
'partners_order': partners_order
})
return super(PartnersOpenInvoicesWebkit, self).set_context(

6
account_financial_report_webkit/report/templates/account_report_partner_balance.mako

@ -105,13 +105,13 @@
%for current_account in objects:
<%
partners_order = partners_order[current_account.id]
partners_order = partners_order_accounts[current_account.id]
# do not display accounts without partners
if not partners_order:
continue
comparisons = current_account.comparisons
comparisons = comparisons_accounts[current_account.id]
# in multiple columns mode, we do not want to print accounts without any rows
if comparison_mode in ('single', 'multiple'):
@ -121,7 +121,7 @@
if not display_line(all_comparison_lines):
continue
current_partner_amounts = current_account.partners_amounts
current_partner_amounts = partners_amounts_accounts[current_account.id]
total_initial_balance = 0.0
total_debit = 0.0

12
account_financial_report_webkit/report/templates/account_report_trial_balance.mako

@ -161,10 +161,10 @@
%>
%for current_account in objects:
<%
if not current_account.to_display:
if not to_display_accounts[current_account.id]:
continue
comparisons = current_account.comparisons
comparisons = comparisons_accounts[current_account.id]
if current_account.id in last_child_consol_ids:
# current account is a consolidation child of the last account: use the level of last account
@ -185,15 +185,15 @@
%if comparison_mode == 'no_comparison':
%if initial_balance_mode:
## opening balance
<div class="act_as_cell amount">${formatLang(current_account.init_balance) | amount}</div>
<div class="act_as_cell amount">${formatLang(init_balance_accounts[current_account.id]) | amount}</div>
%endif
## debit
<div class="act_as_cell amount">${formatLang(current_account.debit) | amount}</div>
<div class="act_as_cell amount">${formatLang(debit_accounts[current_account.id]) | amount}</div>
## credit
<div class="act_as_cell amount">${formatLang(current_account.credit) | amount}</div>
<div class="act_as_cell amount">${formatLang(credit_accounts[current_account.id]) | amount}</div>
%endif
## balance
<div class="act_as_cell amount">${formatLang(current_account.balance) | amount}</div>
<div class="act_as_cell amount">${formatLang(balance_accounts[current_account.id]) | amount}</div>
%if comparison_mode in ('single', 'multiple'):
%for comp_account in comparisons:

10
account_financial_report_webkit/report/templates/aged_trial_webkit.mako

@ -89,7 +89,7 @@
</div>
</div>
%for acc in objects:
%if acc.aged_lines:
%if agged_lines_accounts[acc.id]:
<div class="account_title bg" style="width: 1080px; margin-top: 20px; font-size: 12px;">${acc.code} - ${acc.name}</div>
@ -111,11 +111,11 @@
</div>
<div class="act_as_tbody">
%for partner_name, p_id, p_ref, p_name in partners_order[acc.id]:
%if acc.aged_lines.get(p_id):
%if agged_lines_accounts[acc.id].get(p_id):
<div class="act_as_row lines">
<%line = acc.aged_lines[p_id]%>
<%percents = acc.aged_percents%>
<%totals = acc.aged_totals%>
<%line = agged_lines_accounts[acc.id][p_id]%>
<%percents = agged_percents_accounts[acc.id]%>
<%totals = agged_totals_accounts[acc.id]%>
<div class="act_as_cell first_column">${partner_name}</div>
<div class="act_as_cell">${p_ref or ''}</div>

Loading…
Cancel
Save