Commit 41df40f3 authored by Jérome Perrin's avatar Jérome Perrin

for expense or income accounts, only consider movements from the current

period. Apply this for UI, Account Statements and GL reports.
Also fix a problem with URL method for initial balance line.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@14052 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 25d35488
...@@ -82,7 +82,6 @@ traverse = context.getPortalObject().restrictedTraverse\n ...@@ -82,7 +82,6 @@ traverse = context.getPortalObject().restrictedTraverse\n
# for preference info fields on Account_viewAccountingTransactionList\n # for preference info fields on Account_viewAccountingTransactionList\n
request.set(\'is_accounting_report\', True)\n request.set(\'is_accounting_report\', True)\n
\n \n
\n
at_date = request[\'at_date\']\n at_date = request[\'at_date\']\n
section_uid = context.Base_getSectionUidListForSectionCategory(\n section_uid = context.Base_getSectionUidListForSectionCategory(\n
request[\'section_category\'])\n request[\'section_category\'])\n
...@@ -95,6 +94,10 @@ simulation_state = request[\'simulation_state\']\n ...@@ -95,6 +94,10 @@ simulation_state = request[\'simulation_state\']\n
from_date = request.get(\'from_date\', None)\n from_date = request.get(\'from_date\', None)\n
omit_grouping_reference = request.get(\'omit_grouping_reference\', 0)\n omit_grouping_reference = request.get(\'omit_grouping_reference\', 0)\n
parent_portal_type = request.get(\'portal_type\')\n parent_portal_type = request.get(\'portal_type\')\n
period_start_date = context\\\n
.Base_getAccountingPeriodStartDateForSectionCategory(\n
section_category=request[\'section_category\'],\n
date=from_date or at_date)\n
\n \n
# Also get the currency, to know the precision\n # Also get the currency, to know the precision\n
currency = context.Base_getCurrencyForSection(request[\'section_category\'])\n currency = context.Base_getCurrencyForSection(request[\'section_category\'])\n
...@@ -103,9 +106,9 @@ precision = context.account_module.getQuantityPrecisionFromResource(currency)\n ...@@ -103,9 +106,9 @@ precision = context.account_module.getQuantityPrecisionFromResource(currency)\n
request.set(\'precision\', precision)\n request.set(\'precision\', precision)\n
\n \n
params = dict(at_date=at_date,\n params = dict(at_date=at_date,\n
period_start_date=period_start_date,\n
section_uid=section_uid,\n section_uid=section_uid,\n
node_uid=traverse(node).getUid(),\n node_uid=traverse(node).getUid(),\n
from_date_summary=1,\n
simulation_state=simulation_state, )\n simulation_state=simulation_state, )\n
if from_date:\n if from_date:\n
params[\'from_date\'] = from_date\n params[\'from_date\'] = from_date\n
...@@ -199,6 +202,7 @@ return [ ReportSection(\n ...@@ -199,6 +202,7 @@ return [ ReportSection(\n
<string>from_date</string> <string>from_date</string>
<string>omit_grouping_reference</string> <string>omit_grouping_reference</string>
<string>parent_portal_type</string> <string>parent_portal_type</string>
<string>period_start_date</string>
<string>currency</string> <string>currency</string>
<string>precision</string> <string>precision</string>
<string>dict</string> <string>dict</string>
......
...@@ -80,12 +80,16 @@ N_ = context.Base_translateString\n ...@@ -80,12 +80,16 @@ N_ = context.Base_translateString\n
at_date = request[\'at_date\']\n at_date = request[\'at_date\']\n
section_category = request[\'section_category\']\n section_category = request[\'section_category\']\n
section_uid = context.Base_getSectionUidListForSectionCategory(\n section_uid = context.Base_getSectionUidListForSectionCategory(\n
request[\'section_category\'])\n section_category)\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 omit_empty_accounts = request.get(\'omit_empty_accounts\', True)\n
display_categories = request.get(\'display_categories\', False)\n display_categories = request.get(\'display_categories\', False)\n
period_start_date = context\\\n
.Base_getAccountingPeriodStartDateForSectionCategory(\n
section_category=section_category, date=from_date or at_date)\n
\n
# TODO\n # TODO\n
omit_grouping_reference = request.get(\'omit_grouping_reference\', False)\n omit_grouping_reference = request.get(\'omit_grouping_reference\', False)\n
\n \n
...@@ -95,17 +99,14 @@ params = dict(at_date=at_date,\n ...@@ -95,17 +99,14 @@ params = dict(at_date=at_date,\n
section_uid=section_uid,\n section_uid=section_uid,\n
simulation_state=simulation_state,\n simulation_state=simulation_state,\n
omit_grouping_reference=omit_grouping_reference,\n omit_grouping_reference=omit_grouping_reference,\n
from_date_summary=True,\n period_start_date=period_start_date,\n
no_mirror_section_uid_cache=1)\n no_mirror_section_uid_cache=1)\n
\n \n
if from_date:\n if from_date:\n
params[\'from_date\'] = from_date\n params[\'from_date\'] = from_date\n
else:\n
params[\'no_from_date\'] = True\n
\n \n
result = []\n result = []\n
\n \n
\n
account_columns = (\n account_columns = (\n
(\'Movement_getSpecificReference\', \'Reference\'),\n (\'Movement_getSpecificReference\', \'Reference\'),\n
(\'Movement_getExplanationTitle\', \'Title\'),\n (\'Movement_getExplanationTitle\', \'Title\'),\n
...@@ -310,6 +311,7 @@ return result\n ...@@ -310,6 +311,7 @@ return result\n
<string>omit_empty_accounts</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>omit_grouping_reference</string> <string>omit_grouping_reference</string>
<string>_write_</string> <string>_write_</string>
<string>dict</string> <string>dict</string>
......
...@@ -100,6 +100,7 @@ elif selection is not None:\n ...@@ -100,6 +100,7 @@ elif selection is not None:\n
selection_params = selection.getParams()\n selection_params = selection.getParams()\n
preference = context.getPortalObject().portal_preferences\n preference = context.getPortalObject().portal_preferences\n
\n \n
from_date = None\n
if wants_from_date:\n if wants_from_date:\n
from_date = selection_params.get(\'from_date\',\n from_date = selection_params.get(\'from_date\',\n
preference.getPreferredAccountingTransactionFromDate())\n preference.getPreferredAccountingTransactionFromDate())\n
...@@ -120,6 +121,14 @@ if section_category:\n ...@@ -120,6 +121,14 @@ if section_category:\n
# an instance of Base, so we call it on account_module.\n # an instance of Base, so we call it on account_module.\n
params[\'precision\'] = context.account_module\\\n params[\'precision\'] = context.account_module\\\n
.getQuantityPrecisionFromResource(currency)\n .getQuantityPrecisionFromResource(currency)\n
\n
# calculate the period_start_date for this section\n
# note that reports that precalculate a section_uid but no section_category\n
# will have to calculate period_start_date themselves.\n
if from_date or at_date:\n
params[\'period_start_date\'] = \\\n
context.Base_getAccountingPeriodStartDateForSectionCategory(\n
section_category=section_category, date=from_date or at_date)\n
\n \n
# if we have a section uid, it haves priority\n # if we have a section uid, it haves priority\n
section_uid = selection_params.get(\'section_uid\', None)\n section_uid = selection_params.get(\'section_uid\', None)\n
......
...@@ -83,11 +83,6 @@ if not from_date:\n ...@@ -83,11 +83,6 @@ if not from_date:\n
from_date = portal.portal_preferences\\\n from_date = portal.portal_preferences\\\n
.getPreferredAccountingTransactionFromDate()\n .getPreferredAccountingTransactionFromDate()\n
\n \n
# XXX needed ?\n
if kw.get(\'no_from_date\') and from_date:\n
from_date = None\n
\n
\n
# this script can be used for Node, Section or Payment\n # this script can be used for Node, Section or Payment\n
if kw.get(\'node_uid\'):\n if kw.get(\'node_uid\'):\n
params[\'node_uid\'] = kw[\'node_uid\']\n params[\'node_uid\'] = kw[\'node_uid\']\n
...@@ -104,17 +99,40 @@ if node_category:\n ...@@ -104,17 +99,40 @@ if node_category:\n
new_result = []\n new_result = []\n
net_balance = 0.0\n net_balance = 0.0\n
\n \n
if from_date:\n node_account_type = None\n
if params.get(\'node_uid\'):\n
if context.getUid() == params[\'node_uid\']:\n
node_account_type = context.getAccountTypeId()\n
else:\n
node = portal.portal_catalog.getObject(params[\'node_uid\'])\n
node_account_type = node.getAccountTypeId()\n
\n
if from_date or node_account_type in (\'expense\', \'income\'):\n
period_start_date = None\n
# Create a new parameter list to get the previous balance\n # Create a new parameter list to get the previous balance\n
get_inventory_kw = params.copy() # do not include omit_grouping here\n get_inventory_kw = params.copy()\n
get_inventory_kw[\'to_date\'] = from_date\n get_inventory_kw[\'to_date\'] = from_date\n
# TODO: using a list of section_uid \n \n
# \'where_expression\': " section.portal_type = \'Organisation\' " \n # ignore any at_date that could lay in params\n
get_inventory_kw.pop(\'at_date\', None)\n get_inventory_kw.pop(\'at_date\', None)\n
\n
# if we have on an expense / income account, only take into account movements\n
# from the current period.\n
if params.has_key(\'period_start_date\') and \\\n
node_account_type in (\'expense\', \'income\'):\n
period_start_date = params[\'period_start_date\']\n
get_inventory_kw[\'from_date\'] = period_start_date\n
if from_date:\n
from_date = max(period_start_date, from_date)\n
else:\n
from_date = period_start_date\n
\n \n
# Get previous debit and credit\n # Get previous debit and credit\n
if from_date == period_start_date:\n
previous_total_debit = previous_total_credit = 0\n
else:\n
getInventoryAssetPrice = portal.portal_simulation.getInventoryAssetPrice\n getInventoryAssetPrice = portal.portal_simulation.getInventoryAssetPrice\n
# XXX missing Inventory API Feature: this could be retrived in 1 SQL Query\n # XXX missing Inventory API Feature ? this could be retrived in 1 SQL Query\n
previous_total_debit = getInventoryAssetPrice(omit_output=True,\n previous_total_debit = getInventoryAssetPrice(omit_output=True,\n
**get_inventory_kw)\n **get_inventory_kw)\n
previous_total_credit = getInventoryAssetPrice(omit_input =True,\n previous_total_credit = getInventoryAssetPrice(omit_input =True,\n
...@@ -144,6 +162,7 @@ if from_date:\n ...@@ -144,6 +162,7 @@ if from_date:\n
Movement_getExplanationReference=\'\',\n Movement_getExplanationReference=\'\',\n
Movement_getMirrorSectionTitle=\'\',\n Movement_getMirrorSectionTitle=\'\',\n
Movement_getNodeGapId=\'\',\n Movement_getNodeGapId=\'\',\n
Movement_getExplanationUrl=lambda **kw: \'\',\n
Node_statAccountingBalance=\'\',\n Node_statAccountingBalance=\'\',\n
getTranslatedSimulationStateTitle=\'\',\n getTranslatedSimulationStateTitle=\'\',\n
)\n )\n
...@@ -239,12 +258,16 @@ return portal.portal_simulation.getMovementHistoryList(\n ...@@ -239,12 +258,16 @@ return portal.portal_simulation.getMovementHistoryList(\n
<string>_write_</string> <string>_write_</string>
<string>new_result</string> <string>new_result</string>
<string>net_balance</string> <string>net_balance</string>
<string>node_account_type</string>
<string>node</string>
<string>period_start_date</string>
<string>get_inventory_kw</string> <string>get_inventory_kw</string>
<string>max</string>
<string>previous_total_debit</string>
<string>previous_total_credit</string>
<string>getInventoryAssetPrice</string> <string>getInventoryAssetPrice</string>
<string>_apply_</string> <string>_apply_</string>
<string>True</string> <string>True</string>
<string>previous_total_debit</string>
<string>previous_total_credit</string>
<string>Products.ERP5Type.Document</string> <string>Products.ERP5Type.Document</string>
<string>newTempAccountingTransaction</string> <string>newTempAccountingTransaction</string>
<string>previous_balance</string> <string>previous_balance</string>
......
...@@ -73,6 +73,7 @@ params = portal.ERP5Accounting_getParams(selection_name)\n ...@@ -73,6 +73,7 @@ params = portal.ERP5Accounting_getParams(selection_name)\n
\n \n
if kw.get(\'node_uid\'):\n if kw.get(\'node_uid\'):\n
params[\'node_uid\'] = kw[\'node_uid\']\n params[\'node_uid\'] = kw[\'node_uid\']\n
\n
if kw.get(\'mirror_section_uid\'):\n if kw.get(\'mirror_section_uid\'):\n
params[\'mirror_section_uid\'] = kw[\'mirror_section_uid\']\n params[\'mirror_section_uid\'] = kw[\'mirror_section_uid\']\n
\n \n
...@@ -91,10 +92,16 @@ if kw.get(\'node_category\'):\n ...@@ -91,10 +92,16 @@ if kw.get(\'node_category\'):\n
if kw.get(\'where_expression\'):\n if kw.get(\'where_expression\'):\n
params[\'where_expression\'] = kw[\'where_expression\']\n params[\'where_expression\'] = kw[\'where_expression\']\n
\n \n
# Don\'t use the from_date parameter if from_date_summary is present\n # For expense or income accounts, we only take into account transactions from the\n
# XXX actually I never use from date here -jerome\n # beginning of the period.\n
if kw.get(\'from_date_summary\', 0) and params.has_key(\'from_date\'):\n if params.get(\'period_start_date\', 0) and params.get(\'node_uid\'):\n
del params[\'from_date\']\n # find the node for this node_uid\n
if context.getUid() == params[\'node_uid\']: # I bet it\'s context\n
node = context\n
else:\n
node = portal.portal_catalog.getObject(params[\'node_uid\'])\n
if node.getAccountTypeId() in (\'expense\', \'income\'):\n
params[\'from_date\'] = params[\'period_start_date\']\n
\n \n
return portal.portal_simulation.getInventoryAssetPrice(\n return portal.portal_simulation.getInventoryAssetPrice(\n
omit_input=omit_input,\n omit_input=omit_input,\n
...@@ -162,6 +169,7 @@ return portal.portal_simulation.getInventoryAssetPrice(\n ...@@ -162,6 +169,7 @@ return portal.portal_simulation.getInventoryAssetPrice(\n
<string>params</string> <string>params</string>
<string>_getitem_</string> <string>_getitem_</string>
<string>_write_</string> <string>_write_</string>
<string>node</string>
<string>_apply_</string> <string>_apply_</string>
</tuple> </tuple>
</value> </value>
......
244 250
\ 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