Skip to content

Commit

Permalink
Merge 78bb7af into 9390f8a
Browse files Browse the repository at this point in the history
  • Loading branch information
anthony-muschang committed Oct 10, 2014
2 parents 9390f8a + 78bb7af commit 97ca57d
Show file tree
Hide file tree
Showing 65 changed files with 230 additions and 163 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,6 @@
'tests/aged_trial_balance.yml'],
# 'tests/account_move_line.yml'
'active': False,
'installable': False,
'installable': True,
'application': True,
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class AccountAccount(orm.Model):
'Centralized',
help="If flagged, no details will be displayed in "
"the General Ledger report (the webkit one only), "
"only centralized amounts per period.")
"only centralized amounts per period."),
}

_defaults = {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -128,28 +128,43 @@ def set_context(self, objects, data, ids, report_type=None):
call to set_context
"""

res = super(AccountAgedTrialBalanceWebkit, self).set_context(
objects,
data,
ids,
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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,24 +276,34 @@ def compute_balance_data(self, data, filter_report_type=None):
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,
self.uid,
account_ids):
objects = self.pool.get('account.account').browse(self.cursor,
self.uid,
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[
account.id].get('init_balance', 0.0)
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
# whole account
Expand All @@ -308,21 +318,18 @@ def compute_balance_data(self, data, filter_report_type=None):
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,
Expand All @@ -336,5 +343,12 @@ def compute_balance_data(self, data, filter_report_type=None):
'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
Original file line number Diff line number Diff line change
Expand Up @@ -278,19 +278,29 @@ def compute_partner_balance_data(self, data, filter_report_type=None):
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,
self.uid,
account_ids):
objects = self.pool.get('account.account').browse(self.cursor,
self.uid,
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)
Expand All @@ -302,24 +312,25 @@ def compute_partner_balance_data(self, data, filter_report_type=None):

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,
Expand All @@ -333,6 +344,13 @@ def compute_partner_balance_data(self, data, filter_report_type=None):
'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
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,22 @@ def set_context(self, objects, data, ids, report_type=None):
ledger_lines_memoizer = self._compute_account_ledger_lines(
accounts, init_balance_memoizer, main_filter, target_move, start,
stop)
objects = []
for account in self.pool.get('account.account').browse(self.cursor,
self.uid,
accounts):
objects = self.pool.get('account.account').browse(self.cursor,
self.uid,
accounts)

init_balance = {}
ledger_lines = {}
for account in objects:
if do_centralize and account.centralized \
and ledger_lines_memoizer.get(account.id):
account.ledger_lines = self._centralize_lines(
ledger_lines[account.id] = self._centralize_lines(
main_filter, ledger_lines_memoizer.get(account.id, []))
else:
account.ledger_lines = ledger_lines_memoizer.get(
ledger_lines[account.id] = ledger_lines_memoizer.get(
account.id, [])
account.init_balance = init_balance_memoizer.get(account.id, {})

objects.append(account)
init_balance[account.id] = init_balance_memoizer.get(account.id,
{})

self.localcontext.update({
'fiscalyear': fiscalyear,
Expand All @@ -142,6 +144,8 @@ def set_context(self, objects, data, ids, report_type=None):
'stop_period': stop_period,
'chart_account': chart_account,
'initial_balance_mode': initial_balance_mode,
'init_balance': init_balance,
'ledger_lines': ledger_lines,
})

return super(GeneralLedgerWebkit, self).set_context(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@
from mako.template import Template


import openerp.addons
from openerp import pooler
from openerp.osv import osv
from openerp.report import report_sxw
from openerp.tools.translate import _
from openerp.addons.report_webkit import report_helper
from .common_partner_reports import CommonPartnersReportHeaderWebkit
from .webkit_parser_header_fix import HeaderFooterTextWebKitParser
from openerp.modules.module import get_module_resource


def get_mako_template(obj, *args):
template_path = openerp.addons.get_module_resource(*args)
template_path = get_module_resource(*args)
return Template(filename=template_path, input_encoding='utf-8')

report_helper.WebKitHelper.get_mako_template = get_mako_template
Expand Down Expand Up @@ -145,29 +145,35 @@ def set_context(self, objects, data, ids, report_type=None):
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,
self.uid,
account_ids):
account.ledger_lines = ledger_lines_memoizer.get(account.id, {})
account.init_balance = init_balance_memoizer.get(account.id, {})
objects = self.pool.get('account.account').browse(self.cursor,
self.uid,
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,
Expand All @@ -178,6 +184,9 @@ def set_context(self, objects, data, ids, report_type=None):
'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(
Expand Down

0 comments on commit 97ca57d

Please sign in to comment.