Commit 4c9c4542 authored by Jérome Perrin's avatar Jérome Perrin

Rewrite the script returning report sections for general ledger to use...

Rewrite the script returning report sections for general ledger to use getInventoryList to know which section should be used or not, which is faster and better than iterating on all accounts. At the same time fix a problem with expense or income accounts, they were empty when specifying a from_date, and if the from_date is for a period which is in the past

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@26621 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent b1e9fa38
...@@ -71,13 +71,16 @@ section_uid = context.Base_getSectionUidListForSectionCategory(\n ...@@ -71,13 +71,16 @@ section_uid = context.Base_getSectionUidListForSectionCategory(\n
simulation_state = request[\'simulation_state\']\n simulation_state = request[\'simulation_state\']\n
from_date = request.get(\'from_date\', None)\n from_date = request.get(\'from_date\', None)\n
gap = request.get(\'gap\', None)\n gap = request.get(\'gap\', None)\n
omit_empty_accounts = request.get(\'omit_empty_accounts\', True)\n # XXX the field should maybe use base=1 on the category...\n
if gap:\n
gap = \'gap/%s\' % gap\n
display_categories = request.get(\'display_categories\', False)\n display_categories = request.get(\'display_categories\', False)\n
period_start_date = context\\\n period_start_date = context\\\n
.Base_getAccountingPeriodStartDateForSectionCategory(\n .Base_getAccountingPeriodStartDateForSectionCategory(\n
section_category=section_category, date=from_date or at_date)\n section_category=section_category, date=from_date or at_date)\n
gap_root = request.get(\'gap_root\')\n gap_root = request.get(\'gap_root\')\n
\n \n
\n
# currency precision\n # currency precision\n
currency = portal.Base_getCurrencyForSection(request[\'section_category\'])\n currency = portal.Base_getCurrencyForSection(request[\'section_category\'])\n
precision = portal.account_module.getQuantityPrecisionFromResource(currency)\n precision = portal.account_module.getQuantityPrecisionFromResource(currency)\n
...@@ -94,11 +97,6 @@ params = dict(at_date=at_date,\n ...@@ -94,11 +97,6 @@ params = dict(at_date=at_date,\n
no_mirror_section_uid_cache=1,\n no_mirror_section_uid_cache=1,\n
hide_grouping=request.get(\'omit_grouping_reference\', False))\n hide_grouping=request.get(\'omit_grouping_reference\', False))\n
\n \n
if from_date:\n
params[\'from_date\'] = from_date\n
\n
result = []\n
\n
if len(simulation_state) > 1:\n if len(simulation_state) > 1:\n
account_columns = (\n account_columns = (\n
(\'Movement_getSpecificReference\', \'Reference\'),\n (\'Movement_getSpecificReference\', \'Reference\'),\n
...@@ -123,136 +121,199 @@ else:\n ...@@ -123,136 +121,199 @@ else:\n
(\'credit\', \'Credit\'),\n (\'credit\', \'Credit\'),\n
(\'running_total_price\', \'Net\'), )\n (\'running_total_price\', \'Net\'), )\n
\n \n
# XXX getting all gap is wrong approach, it represents more than 1000\n # utility functions\n
# objects\n traverse = portal.restrictedTraverse\n
if gap:\n account_name_cache = {}\n
gap_value_list = cat_tool.gap.restrictedTraverse(gap)\\\n def getAccountName(account_relative_url):\n
.getCategoryChildValueList(is_self_excluded=0)\n try:\n
else:\n return account_name_cache[account_relative_url]\n
cat = gap_root or (\'gap/%s\' % (\n except KeyError:\n
context.portal_preferences.getPreferredAccountingTransactionGap()))\n name = traverse(account_relative_url).Account_getFormattedTitle(gap_root=gap_root)\n
account_name_cache[account_relative_url] = name\n
return name\n
\n
getObject = portal.portal_catalog.getObject\n
\n
title_for_uid_cache = {}\n
def getTitleForUid(uid):\n
try:\n
return title_for_uid_cache[uid]\n
except KeyError:\n
name = \'\'\n
if uid:\n
document = getObject(uid)\n
if document is not None:\n
name = document.getTitle()\n
title_for_uid_cache[uid] = name\n
return name\n
\n
def getFullAccountName(account_info):\n
account_relative_url, mirror_section_uid, payment_uid = account_info\n
account_name = getAccountName(account_relative_url)\n
mirror_section_name = getTitleForUid(mirror_section_uid)\n
if mirror_section_name:\n
account_name = \'%s (%s)\' % (account_name, mirror_section_name)\n
payment_name = getTitleForUid(payment_uid)\n
if payment_name:\n
account_name = \'%s (%s)\' % (account_name, payment_name)\n
return account_name\n
\n \n
gap_value_list = cat_tool.resolveCategory(cat).getCategoryChildValueList()\n
\n \n
# we don\'t want to display accounts that don\'t have any transactions\n
# associated, so we use a cache to see if the account contains transaction or\n
# not ( regardless of from_date )\n
account_inventory_list_cache = {}\n
account_inventory_list_cache_params = params.copy()\n
if account_inventory_list_cache_params.has_key(\'from_date\'):\n
del account_inventory_list_cache_params[\'from_date\']\n
\n \n
for c in gap_value_list:\n # look at inventories to decide which sections will be shown\n
# FIXME: this part is not working !\n account_type_to_group_by_node = [\n
account_list = c.getGapRelatedValueList(portal_type="Account")\n \'account_type/asset\',\n
strict_account_list = c.getGapRelatedValueList(portal_type="Account",\n \'account_type/asset/cash\',\n
strict_membership=1)\n \'account_type/asset/receivable/refundable_vat\',\n
\'account_type/liability/payable/collected_vat\',\n
\'account_type/equity\',\n
\'account_type/liability\',]\n
\n \n
skip_branch = 1\n profit_and_loss_account_type = [\n
for account in account_list:\n \'account_type/expense\',\n
if account.getUid() not in account_inventory_list_cache:\n \'account_type/income\',]\n
account_inventory_list_cache[account.getUid()] = len(\n
sim_tool.getMovementHistoryList(\n
omit_simulation=1,\n
node_uid=account.getUid(),\n
**account_inventory_list_cache_params))\n
if account_inventory_list_cache[account.getUid()] != 0:\n
skip_branch = 0\n
\n \n
if skip_branch:\n account_type_to_group_by_payment = [ \'account_type/asset/cash/bank\' ]\n
continue\n
\n \n
if display_categories and \\\n account_type_to_group_by_mirror_section = [\n
len(account_list) and \\\n \'account_type/asset/receivable\',\n
len(strict_account_list) != 1:\n \'account_type/liability/payable\', ]\n
result.append(ReportSection( path = c.getPhysicalPath()\n
, title = "%s: %s" % (c.getId(), c.getTitle())\n
, level = len(c.getPhysicalPath()) - 4\n
, form_id = None\n
))\n
\n \n
if len(strict_account_list):\n \n
for account in strict_account_list:\n if gap or gap_root:\n
if account.getAccountTypeId() in (\'payable\', \'receivable\'):\n params[\'node_category\'] = gap or gap_root\n
for third_party_brain in context.Account_zDistinctSectionList(\n \n
at_date=at_date,\n report_section_list = []\n
simulation_state=simulation_state):\n \n
third_party_params = params.copy()\n # group by node\n
third_party_uid = third_party_brain.uid or " = NULL"\n for inventory in portal.portal_simulation.getInventoryList(\n
third_party_params[\'mirror_section_uid\'] = third_party_uid\n node_category_strict_membership=account_type_to_group_by_node,\n
title = "%s: %s (%s)" % ( c.getId()\n portal_type=portal.getPortalAccountingMovementTypeList(),\n
, account.getTitle()\n from_date=from_date,\n
, third_party_brain.title\n group_by_node=1,\n
)\n group_by_section=0,\n
if len(sim_tool.getMovementHistoryList(\n group_by_mirror_section=0,\n
mirror_section_uid=third_party_uid,\n group_by_resource=0,\n
node_uid=account.getUid(),\n **params):\n
**account_inventory_list_cache_params)):\n key = (inventory.node_relative_url, None, None)\n
result.append(ReportSection(\n \n
path=account.getPhysicalPath(),\n selection_params = params.copy()\n
title=title,\n selection_params[\'from_date\'] = from_date\n
selection_params[\'node_uid\'] = inventory.node_uid\n
selection_params[\'payment_uid\'] = None\n
selection_params[\'mirror_section_uid\'] = None\n
report_section_list.append(\n
ReportSection(\n
path=inventory.node_relative_url,\n
title=getFullAccountName(key),\n
form_id=\'Account_viewAccountingTransactionList\',\n form_id=\'Account_viewAccountingTransactionList\',\n
selection_name=\'acount_preference_selection\',\n selection_name=\'account_preference_selection\',\n
selection_params=third_party_params.copy(),\n selection_params=selection_params,\n
selection_columns=account_columns,\n selection_columns=account_columns,\n
listbox_display_mode=\'FlatListMode\',\n listbox_display_mode=\'FlatListMode\',\n
selection_sort_order=[(\'stock.date\',\n selection_sort_order=[(\'stock.date\',\n
\'ascending\')]))\n \'ascending\')]))\n
\n \n
elif account.isMemberOf(\'account_type/asset/cash/bank\'):\n \n
# Bank Account\n # profit & loss -> same, but from date limited to the current period\n
for bank_account_brain in account.Account_zGetDistinctPaymentList(\n for inventory in portal.portal_simulation.getInventoryList(\n
at_date=at_date,\n node_category_strict_membership=profit_and_loss_account_type,\n
simulation_state=simulation_state):\n portal_type=portal.getPortalAccountingMovementTypeList(),\n
bank_params = params.copy()\n from_date=max(from_date, period_start_date),\n
if bank_account_brain.path is not None:\n group_by_node=1,\n
bank_account_uid = bank_account_brain.uid or " = NULL"\n group_by_section=0,\n
bank_params[\'payment_uid\'] = bank_account_uid\n group_by_mirror_section=0,\n
title = "%s: %s (%s)" % ( c.getId()\n group_by_resource=0,\n
, account.getTitle()\n **params):\n
, bank_account_brain.title\n key = (inventory.node_relative_url, None, None)\n
)\n selection_params = params.copy()\n
else :\n selection_params[\'from_date\'] = max(from_date, period_start_date)\n
bank_params[\'no_payment_uid\'] = 1\n selection_params[\'period_start_date\'] = max(from_date, period_start_date)\n
title = "%s: %s" % ( c.getId(), account.getTitle())\n selection_params[\'node_uid\'] = inventory.node_uid\n
if len(sim_tool.getMovementHistoryList(\n selection_params[\'payment_uid\'] = None\n
payment_uid=bank_account_uid,\n selection_params[\'mirror_section_uid\'] = None\n
node_uid=account.getUid(),\n report_section_list.append(\n
**account_inventory_list_cache_params)):\n ReportSection(\n
result.append(ReportSection(\n path=inventory.node_relative_url,\n
path=account.getPhysicalPath(),\n title=getFullAccountName(key),\n
title=title,\n
form_id=\'Account_viewAccountingTransactionList\',\n form_id=\'Account_viewAccountingTransactionList\',\n
selection_name=\'accounting_report_selection\',\n selection_name=\'account_preference_selection\',\n
selection_params=bank_params.copy(),\n selection_params=selection_params,\n
selection_columns=account_columns,\n selection_columns=account_columns,\n
listbox_display_mode=\'FlatListMode\',\n listbox_display_mode=\'FlatListMode\',\n
selection_sort_order=[(\'stock.date\',\n selection_sort_order=[(\'stock.date\',\n
\'ascending\')]))\n \'ascending\')]))\n
elif len(sim_tool.getMovementHistoryList(\n \n
node_uid=account.getUid(),\n # group by mirror_section\n
**account_inventory_list_cache_params)):\n for inventory in portal.portal_simulation.getInventoryList(\n
result.append(ReportSection(\n node_category_strict_membership=account_type_to_group_by_mirror_section,\n
path=account.getPhysicalPath(),\n portal_type=portal.getPortalAccountingMovementTypeList(),\n
title="%s: %s" % (c.getId(), account.getTitle()),\n from_date=from_date,\n
form_id=\'Account_viewAccountingTransactionList\',\n group_by_node=1,\n
selection_name=\'accounting_report_selection\',\n group_by_section=0,\n
selection_params=params,\n group_by_mirror_section=1,\n
selection_columns=account_columns,\n group_by_resource=0,\n
listbox_display_mode=\'FlatListMode\',\n **params):\n
selection_sort_order=[(\'stock.date\',\n key = (inventory.node_relative_url, inventory.mirror_section_uid, None)\n
\'ascending\')]))\n \n
selection_params = params.copy()\n
selection_params[\'from_date\'] = from_date\n
selection_params[\'node_uid\'] = inventory.node_uid\n
selection_params[\'payment_uid\'] = None\n
selection_params[\'mirror_section_uid\'] = inventory.mirror_section_uid\n
report_section_list.append(\n
ReportSection(\n
path=inventory.node_relative_url,\n
title=getFullAccountName(key),\n
form_id=\'Account_viewAccountingTransactionList\',\n
selection_name=\'account_preference_selection\',\n
selection_params=selection_params,\n
selection_columns=account_columns,\n
listbox_display_mode=\'FlatListMode\',\n
selection_sort_order=[(\'stock.date\',\n
\'ascending\')]))\n
\n
\n
# group by payment\n
for inventory in portal.portal_simulation.getInventoryList(\n
node_category_strict_membership=account_type_to_group_by_payment,\n
portal_type=portal.getPortalAccountingMovementTypeList(),\n
from_date=from_date,\n
group_by_node=1,\n
group_by_section=0,\n
group_by_paymnent=1,\n
group_by_resource=0,\n
**params):\n
key = (inventory.node_relative_url, None, inventory.payment_uid)\n
\n
selection_params = params.copy()\n
selection_params[\'from_date\'] = from_date\n
selection_params[\'node_uid\'] = inventory.node_uid\n
selection_params[\'payment_uid\'] = inventory.payment_uid\n
selection_params[\'mirror_section_uid\'] = None\n
report_section_list.append(\n
ReportSection(\n
path=inventory.node_relative_url,\n
title=getFullAccountName(key),\n
form_id=\'Account_viewAccountingTransactionList\',\n
selection_name=\'account_preference_selection\',\n
selection_params=selection_params,\n
selection_columns=account_columns,\n
listbox_display_mode=\'FlatListMode\',\n
selection_sort_order=[(\'stock.date\',\n
\'ascending\')]))\n
\n
report_section_list.sort(key=ReportSection.getTitle)\n
\n
total_params = params.copy()\n total_params = params.copy()\n
if gap:\n report_section_list.append(ReportSection(\n
total_params[\'node_category\'] = \'gap/%s\' % gap\n
result.append(ReportSection(\n
path=context.getPhysicalPath(),\n path=context.getPhysicalPath(),\n
title=Base_translateString("Total"),\n title=Base_translateString("Total"),\n
form_id=\'AccountModule_viewGeneralLedgerSummary\',\n form_id=\'AccountModule_viewGeneralLedgerSummary\',\n
selection_name=\'accounting_report_selection\',\n selection_name=\'accounting_report_selection\',\n
selection_params=total_params))\n selection_params=total_params))\n
\n \n
return result\n return report_section_list\n
]]></string> </value> ]]></string> </value>
...@@ -308,38 +369,36 @@ return result\n ...@@ -308,38 +369,36 @@ return result\n
<string>None</string> <string>None</string>
<string>from_date</string> <string>from_date</string>
<string>gap</string> <string>gap</string>
<string>True</string>
<string>omit_empty_accounts</string>
<string>False</string> <string>False</string>
<string>display_categories</string> <string>display_categories</string>
<string>period_start_date</string> <string>period_start_date</string>
<string>gap_root</string> <string>gap_root</string>
<string>currency</string> <string>currency</string>
<string>precision</string> <string>precision</string>
<string>True</string>
<string>_write_</string> <string>_write_</string>
<string>dict</string> <string>dict</string>
<string>params</string> <string>params</string>
<string>result</string>
<string>len</string> <string>len</string>
<string>account_columns</string> <string>account_columns</string>
<string>gap_value_list</string> <string>traverse</string>
<string>cat</string> <string>account_name_cache</string>
<string>account_inventory_list_cache</string> <string>getAccountName</string>
<string>account_inventory_list_cache_params</string> <string>getObject</string>
<string>title_for_uid_cache</string>
<string>getTitleForUid</string>
<string>getFullAccountName</string>
<string>account_type_to_group_by_node</string>
<string>profit_and_loss_account_type</string>
<string>account_type_to_group_by_payment</string>
<string>account_type_to_group_by_mirror_section</string>
<string>report_section_list</string>
<string>_getiter_</string> <string>_getiter_</string>
<string>c</string>
<string>account_list</string>
<string>strict_account_list</string>
<string>skip_branch</string>
<string>account</string>
<string>_apply_</string> <string>_apply_</string>
<string>third_party_brain</string> <string>inventory</string>
<string>third_party_params</string> <string>key</string>
<string>third_party_uid</string> <string>selection_params</string>
<string>title</string> <string>max</string>
<string>bank_account_brain</string>
<string>bank_params</string>
<string>bank_account_uid</string>
<string>total_params</string> <string>total_params</string>
</tuple> </tuple>
</value> </value>
......
904 905
\ No newline at end of file \ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment