From 681985ad405b84add6d5a744d3fdd514e87718b1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Tue, 15 Apr 2008 09:30:14 +0000
Subject: [PATCH] support tax line with multiple base applications and multiple
 delivery lines

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@20516 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 ...ryMovement_getCorrespondingTaxLineList.xml | 19 +++++++++++--------
 bt5/erp5_trade/bt/revision                    |  2 +-
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/bt5/erp5_trade/SkinTemplateItem/portal_skins/erp5_trade/DeliveryMovement_getCorrespondingTaxLineList.xml b/bt5/erp5_trade/SkinTemplateItem/portal_skins/erp5_trade/DeliveryMovement_getCorrespondingTaxLineList.xml
index e55559049e..a7ce71bf3b 100644
--- a/bt5/erp5_trade/SkinTemplateItem/portal_skins/erp5_trade/DeliveryMovement_getCorrespondingTaxLineList.xml
+++ b/bt5/erp5_trade/SkinTemplateItem/portal_skins/erp5_trade/DeliveryMovement_getCorrespondingTaxLineList.xml
@@ -89,16 +89,17 @@ other_movement_list = [m for m in context.getExplanationValue().getMovementList(
                         portal_type=context.getPortalMovementTypeList())]\n
 # 2 for each tax line, calculate the corresponding ratio\n
 for tax_line in contributed_tax_line_list:\n
-  # XXX only the first one is used here !\n
-  #  this assume that a tax will be applied to only one base_amount\n
-  base_amount = tax_line.getBaseApplication()\n
   base_total_price = 0\n
-  for movement in other_movement_list:\n
-    if base_amount in movement.getBaseContributionList():\n
-      base_total_price += movement.getTotalPrice(fast=0)\n
-  \n
+  added_movement_list = {}\n
+  for base_amount in tax_line.getBaseApplicationList():\n
+    for movement in other_movement_list:\n
+      if base_amount in movement.getBaseContributionList():\n
+        if movement.getRelativeUrl() not in added_movement_list:\n
+          base_total_price += movement.getTotalPrice(fast=0)\n
+          added_movement_list[movement.getRelativeUrl()] = 1\n
+\n
   adjusted_tax_line_list.append(tax_line.asContext(quantity=\n
-    # XXX round ?\n
+        # XXX round ?\n
         tax_line.getQuantity() * total_price / base_total_price))\n
 \n
 return adjusted_tax_line_list\n
@@ -164,8 +165,10 @@ return adjusted_tax_line_list\n
                             <string>m</string>
                             <string>other_movement_list</string>
                             <string>base_total_price</string>
+                            <string>added_movement_list</string>
                             <string>movement</string>
                             <string>_inplacevar_</string>
+                            <string>_write_</string>
                           </tuple>
                         </value>
                     </item>
diff --git a/bt5/erp5_trade/bt/revision b/bt5/erp5_trade/bt/revision
index b1ef57c1f7..4acc65d012 100644
--- a/bt5/erp5_trade/bt/revision
+++ b/bt5/erp5_trade/bt/revision
@@ -1 +1 @@
-265
\ No newline at end of file
+266
\ No newline at end of file
-- 
2.30.9