[Erp5-report] r17006 - in /erp5/trunk/bt5/erp5_accounting: SkinTemplateItem/portal_skins/er...
nobody at svn.erp5.org
nobody at svn.erp5.org
Mon Oct 15 17:17:13 CEST 2007
Author: jerome
Date: Mon Oct 15 17:17:12 2007
New Revision: 17006
URL: http://svn.erp5.org?rev=17006&view=rev
Log:
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.
Modified:
erp5/trunk/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountModule_getAccountListForTrialBalance.xml
erp5/trunk/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/Node_getAccountingTransactionList.xml
erp5/trunk/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/Node_statAccountingBalance.xml
erp5/trunk/bt5/erp5_accounting/bt/revision
Modified: erp5/trunk/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountModule_getAccountListForTrialBalance.xml
URL: http://svn.erp5.org/erp5/trunk/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountModule_getAccountListForTrialBalance.xml?rev=17006&r1=17005&r2=17006&view=diff
==============================================================================
--- erp5/trunk/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountModule_getAccountListForTrialBalance.xml (original)
+++ erp5/trunk/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountModule_getAccountListForTrialBalance.xml Mon Oct 15 17:17:12 2007
@@ -303,6 +303,22 @@
# 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 @@
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 @@
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 @@
\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 @@
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 @@
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 @@
\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 @@
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 @@
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 @@
\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 @@
<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>
Modified: erp5/trunk/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/Node_getAccountingTransactionList.xml
URL: http://svn.erp5.org/erp5/trunk/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/Node_getAccountingTransactionList.xml?rev=17006&r1=17005&r2=17006&view=diff
==============================================================================
--- erp5/trunk/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/Node_getAccountingTransactionList.xml (original)
+++ erp5/trunk/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/Node_getAccountingTransactionList.xml Mon Oct 15 17:17:12 2007
@@ -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 @@
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
@@ -209,6 +227,12 @@
</item>
<item>
<key> <string>_filepath</string> </key>
+ <value>
+ <none/>
+ </value>
+ </item>
+ <item>
+ <key> <string>_owner</string> </key>
<value>
<none/>
</value>
@@ -250,6 +274,8 @@
<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 @@
<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>
Modified: erp5/trunk/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/Node_statAccountingBalance.xml
URL: http://svn.erp5.org/erp5/trunk/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/Node_statAccountingBalance.xml?rev=17006&r1=17005&r2=17006&view=diff
==============================================================================
--- erp5/trunk/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/Node_statAccountingBalance.xml (original)
+++ erp5/trunk/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/Node_statAccountingBalance.xml Mon Oct 15 17:17:12 2007
@@ -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 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 @@
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
-\n
-return portal.portal_simulation.getInventoryAssetPrice(\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 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>
@@ -121,6 +143,12 @@
</item>
<item>
<key> <string>_filepath</string> </key>
+ <value>
+ <none/>
+ </value>
+ </item>
+ <item>
+ <key> <string>_owner</string> </key>
<value>
<none/>
</value>
@@ -170,10 +198,17 @@
<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>
Modified: erp5/trunk/bt5/erp5_accounting/bt/revision
URL: http://svn.erp5.org/erp5/trunk/bt5/erp5_accounting/bt/revision?rev=17006&r1=17005&r2=17006&view=diff
==============================================================================
--- erp5/trunk/bt5/erp5_accounting/bt/revision (original)
+++ erp5/trunk/bt5/erp5_accounting/bt/revision Mon Oct 15 17:17:12 2007
@@ -1,1 +1,1 @@
-434
+440
More information about the Erp5-report
mailing list