From c8de7eb1842a68d0aa6597c1f46fd1322cf6e4b0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Mon, 5 Nov 2007 15:54:02 +0000
Subject: [PATCH] When checking debit == credit, use the currency precision
 from section's price currencies

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@17389 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../scripts/validateTransactionLines.xml      | 22 +++++++++++++++----
 bt5/erp5_accounting/bt/revision               |  2 +-
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_workflow/scripts/validateTransactionLines.xml b/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_workflow/scripts/validateTransactionLines.xml
index 6e38327fe1..062ed82d85 100644
--- a/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_workflow/scripts/validateTransactionLines.xml
+++ b/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_workflow/scripts/validateTransactionLines.xml
@@ -222,12 +222,22 @@ if transaction.getPortalType() not in (\'Balance Transaction\',) :\n
                                  \'bank_account_currency\':\n
                      unicode(payment.getPriceCurrencyReference(), \'utf8\')})\n
     \n
-  # TODO: should use currency precision instead of hardcoding 100 !\n
-  if int(source_sum*100) != 0:\n
+  source_precision = destination_precision = 2\n
+  if source_section is not None and\\\n
+               source_section.getPortalType() == \'Organisation\':\n
+    source_currency = source_section.getPriceCurrencyValue()\n
+    if source_currency is not None:\n
+      source_precision = source_currency.getQuantityPrecision()\n
+  if round(source_sum, source_precision) != 0:\n
     raise ValidationFailed, N_(\n
             \'Action failed: transaction is not balanced for source section.\')\n
 \n
-  if int(destination_sum*100) != 0:\n
+  if destination_section is not None and\\\n
+               destination_section.getPortalType() == \'Organisation\':\n
+    destination_currency = destination_section.getPriceCurrencyValue()\n
+    if destination_currency is not None:\n
+      destination_precision = destination_currency.getQuantityPrecision()\n
+  if round(destination_sum, destination_precision) != 0:\n
     raise ValidationFailed, N_(\n
         \'Action failed: transaction is not balanced for destination section.\')\n
 \n
@@ -326,7 +336,11 @@ transaction.AccountingTransaction_deleteEmptyLines(redirect=0)\n
                             <string>third_party</string>
                             <string>unicode</string>
                             <string>bank_account_currency</string>
-                            <string>int</string>
+                            <string>source_precision</string>
+                            <string>destination_precision</string>
+                            <string>source_currency</string>
+                            <string>round</string>
+                            <string>destination_currency</string>
                           </tuple>
                         </value>
                     </item>
diff --git a/bt5/erp5_accounting/bt/revision b/bt5/erp5_accounting/bt/revision
index 6efca19ea0..34c3a209c7 100644
--- a/bt5/erp5_accounting/bt/revision
+++ b/bt5/erp5_accounting/bt/revision
@@ -1 +1 @@
-481
\ No newline at end of file
+487
\ No newline at end of file
-- 
2.30.9