Commit efb2b589 authored by Jérome Perrin's avatar Jérome Perrin

fix account statement for income & expense accounts with a from date before...

fix account statement for income & expense accounts with a from date before the current accounting period

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@40368 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent a66dc0a4
...@@ -63,10 +63,6 @@ if params.get(\'precision\', None) is not None:\n ...@@ -63,10 +63,6 @@ if params.get(\'precision\', None) is not None:\n
# listbox editable float fields uses request/precision to format the value.\n # listbox editable float fields uses request/precision to format the value.\n
request.set(\'precision\', params[\'precision\'])\n request.set(\'precision\', params[\'precision\'])\n
\n \n
if not from_date:\n
from_date = portal.portal_preferences\\\n
.getPreferredAccountingTransactionFromDate()\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
...@@ -134,10 +130,15 @@ if params.get(\'node_uid\'):\n ...@@ -134,10 +130,15 @@ if params.get(\'node_uid\'):\n
is_pl_account = node.isMemberOf(\'account_type/expense\')\\\n is_pl_account = node.isMemberOf(\'account_type/expense\')\\\n
or node.isMemberOf(\'account_type/income\')\n or node.isMemberOf(\'account_type/income\')\n
\n \n
if is_pl_account and not from_date:\n
from_date = params.get(\'period_start_date\')\n
\n
if from_date or is_pl_account:\n if from_date or is_pl_account:\n
period_start_date = None\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()\n get_inventory_kw = params.copy()\n
\n
initial_balance_from_date = from_date\n
\n \n
# ignore any at_date that could lay in params\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
...@@ -147,20 +148,21 @@ if from_date or is_pl_account:\n ...@@ -147,20 +148,21 @@ if from_date or is_pl_account:\n
# if we have on an expense / income account, only take into account\n # if we have on an expense / income account, only take into account\n
# movements from the current period.\n # movements from the current period.\n
period_start_date = params[\'period_start_date\']\n period_start_date = params[\'period_start_date\']\n
if from_date:\n if initial_balance_from_date:\n
from_date = max(period_start_date, from_date)\n initial_balance_from_date = max(period_start_date,\n
initial_balance_from_date)\n
else:\n else:\n
from_date = period_start_date\n initial_balance_from_date = period_start_date\n
else:\n else:\n
# for all other accounts, we calculate initial balance\n # for all other accounts, we calculate initial balance\n
period_start_date = params[\'period_start_date\']\n period_start_date = params[\'period_start_date\']\n
if not from_date:\n if not initial_balance_from_date:\n
# I don\'t think this should happen\n # I don\'t think this should happen\n
log(\'from_date not passed, defaulting to period_start_date\')\n log(\'from_date not passed, defaulting to period_start_date\')\n
from_date = period_start_date\n initial_balance_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 and is_pl_account:\n if initial_balance_from_date == period_start_date and is_pl_account:\n
previous_total_debit = previous_total_credit = 0\n previous_total_debit = previous_total_credit = 0\n
else:\n else:\n
getInventoryAssetPrice = portal.portal_simulation.getInventoryAssetPrice\n getInventoryAssetPrice = portal.portal_simulation.getInventoryAssetPrice\n
...@@ -170,17 +172,17 @@ if from_date or is_pl_account:\n ...@@ -170,17 +172,17 @@ if from_date or is_pl_account:\n
else:\n else:\n
period_openning_balance = getInventoryAssetPrice(\n period_openning_balance = getInventoryAssetPrice(\n
to_date=min(period_start_date,\n to_date=min(period_start_date,\n
from_date),\n initial_balance_from_date),\n
**get_inventory_kw)\n **get_inventory_kw)\n
\n \n
# then all movement between period_start_date and from_date\n # then all movement between period_start_date and from_date\n
previous_total_debit = getInventoryAssetPrice(omit_asset_decrease=True,\n previous_total_debit = getInventoryAssetPrice(omit_asset_decrease=True,\n
from_date=period_start_date,\n from_date=period_start_date,\n
to_date=from_date,\n to_date=initial_balance_from_date,\n
**get_inventory_kw) + max(period_openning_balance, 0)\n **get_inventory_kw) + max(period_openning_balance, 0)\n
previous_total_credit = getInventoryAssetPrice(omit_asset_increase=True,\n previous_total_credit = getInventoryAssetPrice(omit_asset_increase=True,\n
from_date=period_start_date,\n from_date=period_start_date,\n
to_date=from_date,\n to_date=initial_balance_from_date,\n
**get_inventory_kw) - max(-period_openning_balance, 0)\n **get_inventory_kw) - max(-period_openning_balance, 0)\n
\n \n
if previous_total_credit != 0:\n if previous_total_credit != 0:\n
...@@ -197,7 +199,7 @@ if from_date or is_pl_account:\n ...@@ -197,7 +199,7 @@ if from_date or is_pl_account:\n
previous_balance = newTempBase(portal, \'_temp_accounting_transaction\')\n previous_balance = newTempBase(portal, \'_temp_accounting_transaction\')\n
previous_balance.edit(\n previous_balance.edit(\n
uid=\'new_000\',\n uid=\'new_000\',\n
date=from_date,\n date=initial_balance_from_date,\n
simulation_state_title="",\n simulation_state_title="",\n
credit_price=previous_total_credit,\n credit_price=previous_total_credit,\n
debit_price=previous_total_debit,\n debit_price=previous_total_debit,\n
...@@ -323,6 +325,7 @@ return portal.portal_simulation.getMovementHistoryList(\n ...@@ -323,6 +325,7 @@ return portal.portal_simulation.getMovementHistoryList(\n
<string>node</string> <string>node</string>
<string>period_start_date</string> <string>period_start_date</string>
<string>get_inventory_kw</string> <string>get_inventory_kw</string>
<string>initial_balance_from_date</string>
<string>max</string> <string>max</string>
<string>previous_total_debit</string> <string>previous_total_debit</string>
<string>previous_total_credit</string> <string>previous_total_credit</string>
......
...@@ -125,8 +125,11 @@ if params.get(\'period_start_date\', 0) and params.get(\'node_uid\'):\n ...@@ -125,8 +125,11 @@ if params.get(\'period_start_date\', 0) and params.get(\'node_uid\'):\n
if node.isMemberOf(\'account_type/expense\') or\\\n if node.isMemberOf(\'account_type/expense\') or\\\n
node.isMemberOf(\'account_type/income\'):\n node.isMemberOf(\'account_type/income\'):\n
# For expense or income accounts, we only take into account transactions\n # For expense or income accounts, we only take into account transactions\n
# from the beginning of the period.\n # from the beginning of the period, unless a from_date prior to this\n
params[\'from_date\'] = params[\'period_start_date\']\n # beginning is passed explicitly.\n
# if we are in the regular user interface, we only limit\n
if \'from_date\' in kw:\n
params[\'from_date\'] = min(kw[\'from_date\'], params[\'period_start_date\'])\n
else:\n else:\n
# for other account, we calculate the initial balance as the "absolute"\n # for other account, we calculate the initial balance as the "absolute"\n
# balance at the beginning of the period, plus debit or credit from this\n # balance at the beginning of the period, plus debit or credit from this\n
...@@ -224,6 +227,7 @@ return getInventoryAssetPrice(\n ...@@ -224,6 +227,7 @@ return getInventoryAssetPrice(\n
<string>function_uid</string> <string>function_uid</string>
<string>function_category</string> <string>function_category</string>
<string>node</string> <string>node</string>
<string>min</string>
<string>period_start_date</string> <string>period_start_date</string>
<string>at_date</string> <string>at_date</string>
<string>_apply_</string> <string>_apply_</string>
......
1391 1404
\ 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