From 31de44c546d4506a40b9c109e5b7285e37e1703e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Wed, 15 Feb 2006 10:12:26 +0000
Subject: [PATCH] use catalog to calculate per line total debit / credit

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@5697 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 ...ntingTransactionModule_getSourceCredit.xml | 48 ++++++++-----------
 ...untingTransactionModule_getSourceDebit.xml | 47 ++++++++----------
 2 files changed, 41 insertions(+), 54 deletions(-)

diff --git a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionModule_getSourceCredit.xml b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionModule_getSourceCredit.xml
index 874171763f..d99f5a4777 100755
--- a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionModule_getSourceCredit.xml
+++ b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionModule_getSourceCredit.xml
@@ -66,25 +66,20 @@
         </item>
         <item>
             <key> <string>_body</string> </key>
-            <value> <string>accounting_transaction_lines_portal_types = context.getPortalAccountingMovementTypeList()\n
+            <value> <string>if selection is not None:\n
+  params = selection.getParams()\n
+else:\n
+  params = {}\n
+kw = {} \n
+kw[\'section_category\'] = params.get(\'section_category\')\n
+kw[\'stat\'] = 1\n
+kw[\'omit_output\'] = 1\n
+kw[\'transaction\'] = context.getUid()\n
+kw[\'delivery.start_date\'] = "%"\n
 \n
-if brain is not None :\n
-  transaction = brain.getObject()\n
-transaction = context\n
-\n
-credit = 0\n
-group_category = context.getPortalObject().portal_preferences\\\n
-                        .getPreferredAccountingTransactionSectionCategory()\n
-\n
-for line in transaction.contentValues(\n
-       filter={\'portal_type\': accounting_transaction_lines_portal_types} ) :\n
-  source_section = line.getSourceSectionValue()\n
-  if source_section is not None and source_section.isMemberOf(group_category) :\n
-    credit += line.getSourceInventoriatedTotalAssetCredit() or 0\n
-  destination_section = line.getDestinationSectionValue()\n
-  if destination_section is not None and destination_section.isMemberOf(group_category) :\n
-    credit += line.getDestinationInventoriatedTotalAssetCredit() or 0\n
-return credit\n
+result = context.AccountingTransactionModule_zGetAccountingTransactionList(selection=selection, **kw)\n
+row = result[0]\n
+return float(\'%.02f\' % (row.total_price or 0.0))\n
 </string> </value>
         </item>
         <item>
@@ -134,17 +129,16 @@ return credit\n
                             <string>brain</string>
                             <string>selection</string>
                             <string>kw</string>
+                            <string>None</string>
                             <string>_getattr_</string>
+                            <string>params</string>
+                            <string>_write_</string>
                             <string>context</string>
-                            <string>accounting_transaction_lines_portal_types</string>
-                            <string>None</string>
-                            <string>transaction</string>
-                            <string>credit</string>
-                            <string>group_category</string>
-                            <string>_getiter_</string>
-                            <string>line</string>
-                            <string>source_section</string>
-                            <string>destination_section</string>
+                            <string>_apply_</string>
+                            <string>result</string>
+                            <string>_getitem_</string>
+                            <string>row</string>
+                            <string>float</string>
                           </tuple>
                         </value>
                     </item>
diff --git a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionModule_getSourceDebit.xml b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionModule_getSourceDebit.xml
index e973d87cd2..cf2da90bc9 100755
--- a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionModule_getSourceDebit.xml
+++ b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionModule_getSourceDebit.xml
@@ -66,25 +66,19 @@
         </item>
         <item>
             <key> <string>_body</string> </key>
-            <value> <string>accounting_transaction_lines_portal_types = context.getPortalAccountingMovementTypeList()\n
+            <value> <string>if selection is not None:\n
+  params = selection.getParams()\n
+else:\n
+  params = {}\n
+kw = {}\n
+kw[\'section_category\'] = params.get(\'section_category\')\n
+kw[\'stat\'] = 1\n
+kw[\'omit_input\'] = 1\n
+kw[\'transaction\'] = context.getUid()\n
 \n
-if brain is not None :\n
-  transaction = brain.getObject()\n
-transaction = context\n
-debit = 0\n
-\n
-group_category = context.getPortalObject().portal_preferences\\\n
-                        .getPreferredAccountingTransactionSectionCategory()\n
-\n
-for line in transaction.contentValues(\n
-       filter={\'portal_type\': accounting_transaction_lines_portal_types} ) :\n
-  source_section = line.getSourceSectionValue()\n
-  if source_section is not None and source_section.isMemberOf(group_category) :\n
-    debit += line.getSourceInventoriatedTotalAssetDebit() or 0\n
-  destination_section = line.getDestinationSectionValue()\n
-  if destination_section is not None and destination_section.isMemberOf(group_category) :\n
-    debit += line.getDestinationInventoriatedTotalAssetDebit() or 0\n
-return debit\n
+result = context.AccountingTransactionModule_zGetAccountingTransactionList(selection=selection, selection_params=kw, **kw)\n
+row = result[0]\n
+return float(\'%.02f\' % (row.total_price and - row.total_price or 0.0))\n
 </string> </value>
         </item>
         <item>
@@ -134,17 +128,16 @@ return debit\n
                             <string>brain</string>
                             <string>selection</string>
                             <string>kw</string>
+                            <string>None</string>
                             <string>_getattr_</string>
+                            <string>params</string>
+                            <string>_write_</string>
                             <string>context</string>
-                            <string>accounting_transaction_lines_portal_types</string>
-                            <string>None</string>
-                            <string>transaction</string>
-                            <string>debit</string>
-                            <string>group_category</string>
-                            <string>_getiter_</string>
-                            <string>line</string>
-                            <string>source_section</string>
-                            <string>destination_section</string>
+                            <string>_apply_</string>
+                            <string>result</string>
+                            <string>_getitem_</string>
+                            <string>row</string>
+                            <string>float</string>
                           </tuple>
                         </value>
                     </item>
-- 
2.30.9