From 007d51db1b004e5bb3e7b0ea91e6fdee10cd93ad Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Thu, 25 Mar 2010 16:23:05 +0000
Subject: [PATCH] make it possible to extend account_type/expense and
 account_type/income

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@34121 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 ...ntModule_getAccountListForTrialBalance.xml |  8 +++----
 ...dule_getGeneralLedgerReportSectionList.xml |  2 +-
 ...ountingPeriod_createBalanceTransaction.xml |  3 ++-
 .../Node_getAccountingTransactionList.xml     | 21 +++++++++++--------
 .../Node_statAccountingBalance.xml            |  3 ++-
 bt5/erp5_accounting/bt/revision               |  2 +-
 6 files changed, 22 insertions(+), 17 deletions(-)

diff --git a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountModule_getAccountListForTrialBalance.xml b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountModule_getAccountListForTrialBalance.xml
index 3daa8bd798..a996fa2bda 100644
--- a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountModule_getAccountListForTrialBalance.xml
+++ b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountModule_getAccountListForTrialBalance.xml
@@ -166,7 +166,7 @@ for node in getInventoryList(\n
 \n
 ### profit & loss accounts {{{\n
 for node in getInventoryList(\n
-                node_category_strict_membership=profit_and_loss_account_type,\n
+                node_category=profit_and_loss_account_type,\n
                 from_date=max(period_start_date, from_date),\n
                 group_by_node=1,\n
                 omit_output=1,\n
@@ -182,7 +182,7 @@ for node in getInventoryList(\n
   total_debit += round(total_price, precision)\n
 \n
 for node in getInventoryList(\n
-                node_category_strict_membership=profit_and_loss_account_type,\n
+                node_category=profit_and_loss_account_type,\n
                 from_date=max(period_start_date, from_date),\n
                 group_by_node=1,\n
                 omit_input=1,\n
@@ -387,7 +387,7 @@ for node in getInventoryList(\n
 \n
 ### profit & loss accounts {{{\n
 for node in getInventoryList(\n
-                node_category_strict_membership=profit_and_loss_account_type,\n
+                node_category=profit_and_loss_account_type,\n
                 omit_output=1,\n
                 from_date=min(period_start_date,\n
                               initial_balance_date),\n
@@ -403,7 +403,7 @@ for node in getInventoryList(\n
                     \'initial_debit_balance\', 0) + total_price\n
 \n
 for node in getInventoryList(\n
-                node_category_strict_membership=profit_and_loss_account_type,\n
+                node_category=profit_and_loss_account_type,\n
                 omit_input=1,\n
                 from_date=min(period_start_date,\n
                               initial_balance_date),\n
diff --git a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountModule_getGeneralLedgerReportSectionList.xml b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountModule_getGeneralLedgerReportSectionList.xml
index 37b7a10f58..e616bd8d18 100644
--- a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountModule_getGeneralLedgerReportSectionList.xml
+++ b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountModule_getGeneralLedgerReportSectionList.xml
@@ -258,7 +258,7 @@ for inventory in portal.portal_simulation.getInventoryList(\n
 \n
 # profit & loss -> same, but from date limited to the current period\n
 for inventory in portal.portal_simulation.getInventoryList(\n
-                            node_category_strict_membership=profit_and_loss_account_type,\n
+                            node_category=profit_and_loss_account_type,\n
                             portal_type=portal.getPortalAccountingMovementTypeList(),\n
                             from_date=max(from_date, period_start_date),\n
                             at_date=at_date,\n
diff --git a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingPeriod_createBalanceTransaction.xml b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingPeriod_createBalanceTransaction.xml
index 11bee6bfe7..11ffd4ae76 100644
--- a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingPeriod_createBalanceTransaction.xml
+++ b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingPeriod_createBalanceTransaction.xml
@@ -113,7 +113,8 @@ for section_uid in \\\n
         \'account_type/asset/receivable\',\n
         \'account_type/liability/payable\'):\n
       group_by_mirror_section_node_category_list.append(node_category_url)\n
-    elif node_category_url in (\'account_type/income\', \'account_type/expense\'):\n
+    elif node_category.isMemberOf(\'account_type/income\') or \\\n
+         node_category.isMemberOf(\'account_type/expense\'):\n
       profit_and_loss_node_category_list.append(node_category_url)\n
     else:\n
       group_by_node_node_category_list.append(node_category_url)\n
diff --git a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/Node_getAccountingTransactionList.xml b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/Node_getAccountingTransactionList.xml
index 760757ec22..31ac02a647 100644
--- a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/Node_getAccountingTransactionList.xml
+++ b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/Node_getAccountingTransactionList.xml
@@ -92,15 +92,18 @@ if not \'parent_portal_type\' in params:\n
 new_result  = []\n
 net_balance = 0.0\n
 \n
-node_account_type = None\n
+# accounts from PL have a balance calculated differently\n
+is_pl_account = False\n
 if params.get(\'node_uid\'):\n
   if context.getUid() == params[\'node_uid\']:\n
-    node_account_type = context.getAccountTypeId()\n
+    is_pl_account = context.isMemberOf(\'account_type/expense\')\\\n
+                 or context.isMemberOf(\'account_type/income\')\n
   else:\n
     node = portal.portal_catalog.getObject(params[\'node_uid\'])\n
-    node_account_type = node.getAccountTypeId()\n
+    is_pl_account = node.isMemberOf(\'account_type/expense\')\\\n
+                 or node.isMemberOf(\'account_type/income\')\n
 \n
-if from_date or node_account_type in (\'expense\', \'income\'):\n
+if from_date or is_pl_account:\n
   period_start_date = None\n
   # Create a new parameter list to get the previous balance\n
   get_inventory_kw = params.copy()\n
@@ -109,7 +112,7 @@ if from_date or node_account_type in (\'expense\', \'income\'):\n
   get_inventory_kw.pop(\'at_date\', None)\n
 \n
   if params.has_key(\'period_start_date\'):\n
-    if node_account_type in (\'expense\', \'income\'):\n
+    if is_pl_account:\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
@@ -126,13 +129,12 @@ if from_date or node_account_type in (\'expense\', \'income\'):\n
         from_date = period_start_date\n
 \n
   # Get previous debit and credit\n
-  if from_date == period_start_date and \\\n
-                      node_account_type in (\'expense\', \'income\'):\n
+  if from_date == period_start_date and is_pl_account:\n
     previous_total_debit = previous_total_credit = 0\n
   else:\n
     getInventoryAssetPrice = portal.portal_simulation.getInventoryAssetPrice\n
     # first to the balance at the period start date\n
-    if node_account_type in (\'expense\', \'income\'):\n
+    if is_pl_account:\n
       period_openning_balance = 0\n
     else:\n
       period_openning_balance = getInventoryAssetPrice(\n
@@ -268,7 +270,8 @@ return portal.portal_simulation.getMovementHistoryList(\n
                             <string>_write_</string>
                             <string>new_result</string>
                             <string>net_balance</string>
-                            <string>node_account_type</string>
+                            <string>False</string>
+                            <string>is_pl_account</string>
                             <string>node</string>
                             <string>period_start_date</string>
                             <string>get_inventory_kw</string>
diff --git a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/Node_statAccountingBalance.xml b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/Node_statAccountingBalance.xml
index cfa859544f..61d8c8c252 100644
--- a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/Node_statAccountingBalance.xml
+++ b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/Node_statAccountingBalance.xml
@@ -93,7 +93,8 @@ if params.get(\'period_start_date\', 0) and params.get(\'node_uid\'):\n
     node = context\n
   else:\n
     node = portal.portal_catalog.getObject(params[\'node_uid\'])\n
-  if node.getAccountTypeId() in (\'expense\', \'income\'):\n
+  if node.isMemberOf(\'account_type/expense\') or\\\n
+        node.isMemberOf(\'account_type/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
diff --git a/bt5/erp5_accounting/bt/revision b/bt5/erp5_accounting/bt/revision
index 43da71c576..d845103a18 100644
--- a/bt5/erp5_accounting/bt/revision
+++ b/bt5/erp5_accounting/bt/revision
@@ -1 +1 @@
-1148
\ No newline at end of file
+1150
\ No newline at end of file
-- 
2.30.9