Commit 192cd81b authored by Jérome Perrin's avatar Jérome Perrin

Refactor initial balance calculation in Trial Balance and account statements....

Refactor initial balance calculation in Trial Balance and account statements. The initial balance for debit and credit is now : balance at the beginning of period + sum of movement until the initial balance date.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@17006 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent cbeaf104
......@@ -303,6 +303,22 @@ initial_balance_date = (from_date - 1).latestTime()\n
# Initial Balance\n
\n
# standards accounts {{{\n
# balance at period start date\n
for node in getInventoryList(\n
node_category_strict_membership=account_type_to_group_by_node,\n
group_by_node=1,\n
to_date=period_start_date,\n
portal_type=accounting_movement_type_list +\n
balance_movement_type_list,\n
**inventory_params):\n
account_props = line_per_account.setdefault(\n
(node[\'node_relative_url\'], MARKER, MARKER),\n
dict(debit=0, credit=0))\n
account_props[\'initial_debit_balance\'] = account_props.get(\n
\'initial_debit_balance\', 0) + max(node[\'total_price\'], 0)\n
account_props[\'initial_credit_balance\'] = account_props.get(\n
\'initial_credit_balance\', 0) + max(-node[\'total_price\'], 0)\n
\n
# Balance Transaction\n
for node in getInventoryList(\n
node_category_strict_membership=account_type_to_group_by_node,\n
......@@ -334,7 +350,8 @@ for node in getInventoryList(\n
node_category_strict_membership=account_type_to_group_by_node,\n
group_by_node=1,\n
omit_output=1,\n
at_date=initial_balance_date,\n
from_date=period_start_date,\n
to_date=from_date,\n
portal_type=accounting_movement_type_list,\n
**inventory_params):\n
account_props = line_per_account.setdefault(\n
......@@ -347,7 +364,8 @@ for node in getInventoryList(\n
node_category_strict_membership=account_type_to_group_by_node,\n
group_by_node=1,\n
omit_input=1,\n
at_date=initial_balance_date,\n
from_date=period_start_date,\n
to_date=from_date,\n
portal_type=accounting_movement_type_list,\n
**inventory_params):\n
account_props = line_per_account.setdefault(\n
......@@ -391,7 +409,25 @@ for node in getInventoryList(\n
\n
# payable / receivable accounts {{{\n
if account_type_to_group_by_mirror_section:\n
# Balance\n
# initial balance\n
for node in getInventoryList(\n
node_category_strict_membership=\n
account_type_to_group_by_mirror_section,\n
group_by_mirror_section=1,\n
group_by_node=1,\n
to_date=period_start_date,\n
portal_type=accounting_movement_type_list +\n
balance_movement_type_list,\n
**inventory_params):\n
account_props = line_per_account.setdefault(\n
(node[\'node_relative_url\'], node[\'mirror_section_uid\'], MARKER),\n
dict(debit=0, credit=0))\n
account_props[\'initial_debit_balance\'] = account_props.get(\n
\'initial_debit_balance\', 0) + max(node[\'total_price\'], 0)\n
account_props[\'initial_credit_balance\'] = account_props.get(\n
\'initial_credit_balance\', 0) + max(-node[\'total_price\'], 0)\n
\n
# Balance Transactions\n
for node in getInventoryList(\n
node_category_strict_membership=\n
account_type_to_group_by_mirror_section,\n
......@@ -428,7 +464,8 @@ if account_type_to_group_by_mirror_section:\n
group_by_mirror_section=1,\n
group_by_node=1,\n
omit_output=1,\n
at_date=initial_balance_date,\n
from_date=period_start_date,\n
to_date=from_date,\n
portal_type=accounting_movement_type_list,\n
**inventory_params):\n
account_props = line_per_account.setdefault(\n
......@@ -443,7 +480,8 @@ if account_type_to_group_by_mirror_section:\n
group_by_mirror_section=1,\n
group_by_node=1,\n
omit_input=1,\n
at_date=initial_balance_date,\n
from_date=period_start_date,\n
to_date=from_date,\n
portal_type=accounting_movement_type_list,\n
**inventory_params):\n
account_props = line_per_account.setdefault(\n
......@@ -455,7 +493,25 @@ if account_type_to_group_by_mirror_section:\n
\n
# bank accounts {{{\n
if account_type_to_group_by_payment:\n
# Balance\n
# Initial balance\n
for node in getInventoryList(\n
node_category_strict_membership=\n
account_type_to_group_by_payment,\n
group_by_payment=1,\n
group_by_node=1,\n
to_date=period_start_date,\n
portal_type=accounting_movement_type_list +\n
balance_movement_type_list,\n
**inventory_params):\n
account_props = line_per_account.setdefault(\n
(node[\'node_relative_url\'], MARKER, node[\'payment_uid\']),\n
dict(debit=0, credit=0))\n
account_props[\'initial_debit_balance\'] = account_props.get(\n
\'initial_debit_balance\', 0) + max(node[\'total_price\'], 0)\n
account_props[\'initial_credit_balance\'] = account_props.get(\n
\'initial_credit_balance\', 0) + max(-node[\'total_price\'], 0)\n
\n
# Balance Transaction\n
for node in getInventoryList(\n
node_category_strict_membership=\n
account_type_to_group_by_payment,\n
......@@ -494,7 +550,8 @@ if account_type_to_group_by_payment:\n
group_by_payment=1,\n
group_by_node=1,\n
omit_output=1,\n
at_date=initial_balance_date,\n
from_date=period_start_date,\n
to_date=from_date,\n
portal_type=accounting_movement_type_list,\n
**inventory_params):\n
account_used[node[\'node_relative_url\']] = 1\n
......@@ -510,7 +567,8 @@ if account_type_to_group_by_payment:\n
group_by_payment=1,\n
group_by_node=1,\n
omit_input=1,\n
at_date=initial_balance_date,\n
from_date=period_start_date,\n
to_date=from_date,\n
portal_type=accounting_movement_type_list,\n
**inventory_params):\n
account_used[node[\'node_relative_url\']] = 1\n
......@@ -544,11 +602,6 @@ for (node_relative_url, mirror_section_uid, payment_uid), data in \\\n
\n
initial_debit_balance = data.get(\'initial_debit_balance\', 0)\n
initial_credit_balance = data.get(\'initial_credit_balance\', 0)\n
\n
initial_balance = initial_debit_balance - initial_credit_balance\n
# initial debit balance actually shows \n
initial_debit_balance = round(max(initial_balance, 0), precision)\n
initial_credit_balance = round(max(-initial_balance, 0) or 0, precision)\n
\n
total_initial_debit_balance += round(initial_debit_balance, precision)\n
total_initial_credit_balance += round(initial_credit_balance, precision)\n
......@@ -718,7 +771,6 @@ return line_list\n
<string>payment</string>
<string>initial_debit_balance</string>
<string>initial_credit_balance</string>
<string>initial_balance</string>
<string>final_debit_balance</string>
<string>final_credit_balance</string>
<string>closing_balance</string>
......
......@@ -71,8 +71,9 @@
<value> <string encoding="cdata"><![CDATA[
from Products.ERP5Type.Message import Message\n
from Products.ERP5Type.Log import log\n
portal = context.getPortalObject()\n
params = portal.ERP5Accounting_getParams(selection_name)\n
params = portal.ERP5Accounting_getParams(selection_name=selection_name)\n
N_ = lambda msg: Message(\'erp5_ui\', msg)\n
\n
if params.get(\'precision\', None) is not None:\n
......@@ -114,32 +115,49 @@ 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
get_inventory_kw = params.copy()\n
get_inventory_kw[\'to_date\'] = from_date\n
\n
# ignore any at_date that could lay in params\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
if params.has_key(\'period_start_date\'):\n
if node_account_type in (\'expense\', \'income\'):\n
# if we have on an expense / income account, only take into account\n
# movements from the current period.\n
period_start_date = params[\'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
else:\n
from_date = period_start_date\n
# for all other accounts, we calculate initial balance\n
period_start_date = params[\'period_start_date\']\n
if not from_date:\n
# I don\'t think this should happen\n
log(\'from_date not passed, defaulting to period_start_date\')\n
from_date = period_start_date\n
\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
# XXX missing Inventory API Feature ? this could be retrived in 1 SQL Query\n
# first to the balance at the period start date\n
if node_account_type in (\'expense\', \'income\'):\n
period_openning_balance = 0\n
else:\n
period_openning_balance = getInventoryAssetPrice(\n
to_date=period_start_date,\n
**get_inventory_kw)\n
# then all movement between period_start_date and from_date\n
previous_total_debit = getInventoryAssetPrice(omit_output=True,\n
**get_inventory_kw)\n
previous_total_credit = getInventoryAssetPrice(omit_input =True,\n
**get_inventory_kw)\n
from_date=period_start_date,\n
to_date=from_date,\n
**get_inventory_kw) + max(period_openning_balance, 0)\n
previous_total_credit = getInventoryAssetPrice(omit_input=True,\n
from_date=period_start_date,\n
to_date=from_date,\n
**get_inventory_kw) - max(-period_openning_balance, 0)\n
\n
if previous_total_credit != 0:\n
previous_total_credit = - previous_total_credit\n
\n
......@@ -213,6 +231,12 @@ return portal.portal_simulation.getMovementHistoryList(\n
<none/>
</value>
</item>
<item>
<key> <string>_owner</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>selection=None, sort_on=[], node_category=None, node_category_strict_membership=None, from_date=None, selection_name=None, **kw</string> </value>
......@@ -250,6 +274,8 @@ return portal.portal_simulation.getMovementHistoryList(\n
<string>kw</string>
<string>Products.ERP5Type.Message</string>
<string>Message</string>
<string>Products.ERP5Type.Log</string>
<string>log</string>
<string>_getattr_</string>
<string>context</string>
<string>portal</string>
......@@ -268,6 +294,7 @@ return portal.portal_simulation.getMovementHistoryList(\n
<string>previous_total_debit</string>
<string>previous_total_credit</string>
<string>getInventoryAssetPrice</string>
<string>period_openning_balance</string>
<string>_apply_</string>
<string>True</string>
<string>Products.ERP5Type.Document</string>
......
......@@ -69,7 +69,9 @@
<item>
<key> <string>_body</string> </key>
<value> <string>portal = context.getPortalObject()\n
params = portal.ERP5Accounting_getParams(selection_name)\n
params = portal.ERP5Accounting_getParams(selection_name=selection_name)\n
getInventoryAssetPrice = portal.portal_simulation.getInventoryAssetPrice\n
getSelectionDomainDictFor = context.portal_selections.getSelectionDomainDictFor\n
\n
if kw.get(\'node_uid\'):\n
params[\'node_uid\'] = kw[\'node_uid\']\n
......@@ -95,8 +97,6 @@ if kw.get(\'where_expression\'):\n
if not \'parent_portal_type\' in params:\n
params.setdefault(\'portal_type\', portal.getPortalAccountingMovementTypeList())\n
\n
# For expense or income accounts, we only take into account transactions from the\n
# beginning of the period.\n
if params.get(\'period_start_date\', 0) and params.get(\'node_uid\'):\n
# find the node for this node_uid\n
if context.getUid() == params[\'node_uid\']: # I bet it\'s context\n
......@@ -104,12 +104,34 @@ if params.get(\'period_start_date\', 0) and params.get(\'node_uid\'):\n
else:\n
node = portal.portal_catalog.getObject(params[\'node_uid\'])\n
if node.getAccountTypeId() in (\'expense\', \'income\'):\n
# For expense or income accounts, we only take into account transactions\n
# from the beginning of the period.\n
params[\'from_date\'] = params[\'period_start_date\']\n
else:\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
# beginning of period to the from_date\n
period_start_date = params[\'period_start_date\']\n
at_date = params.pop(\'at_date\', None)\n
period_openning_balance = getInventoryAssetPrice(\n
selection_domain=getSelectionDomainDictFor(selection_name),\n
to_date=period_start_date,\n
**params)\n
if omit_output:\n
return getInventoryAssetPrice(omit_output=1,\n
from_date=period_start_date,\n
at_date=at_date,\n
**params) + max(period_openning_balance, 0)\n
elif omit_input:\n
return getInventoryAssetPrice(omit_input=1,\n
from_date=period_start_date,\n
at_date=at_date,\n
**params) - max(-period_openning_balance, 0)\n
\n
return portal.portal_simulation.getInventoryAssetPrice(\n
return getInventoryAssetPrice(\n
omit_input=omit_input,\n
omit_output=omit_output,\n
selection_domain=context.portal_selections.getSelectionDomainDictFor(selection_name),\n
selection_domain=getSelectionDomainDictFor(selection_name),\n
**params)\n
</string> </value>
</item>
......@@ -125,6 +147,12 @@ return portal.portal_simulation.getInventoryAssetPrice(\n
<none/>
</value>
</item>
<item>
<key> <string>_owner</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>selection=None, omit_input=0, omit_output=0, selection_name=None, **kw</string> </value>
......@@ -170,10 +198,17 @@ return portal.portal_simulation.getInventoryAssetPrice(\n
<string>context</string>
<string>portal</string>
<string>params</string>
<string>getInventoryAssetPrice</string>
<string>getSelectionDomainDictFor</string>
<string>_getitem_</string>
<string>_write_</string>
<string>node</string>
<string>period_start_date</string>
<string>None</string>
<string>at_date</string>
<string>_apply_</string>
<string>period_openning_balance</string>
<string>max</string>
</tuple>
</value>
</item>
......
434
\ No newline at end of file
440
\ 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