From c3ae6bc62d9039ccefd5d7b2fff47bdca2cb1082 Mon Sep 17 00:00:00 2001
From: Kazuhiko Shiozaki <kazuhiko@nexedi.com>
Date: Tue, 23 Feb 2010 07:08:58 +0000
Subject: [PATCH] try to find payment conditions in the following order. *
 local payment conditions * payment conditions specified in specialised trade
 conditions * payment conditions specified in BPM configuration

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@32993 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../ERP5/Document/PaymentSimulationRule.py    | 22 ++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/product/ERP5/Document/PaymentSimulationRule.py b/product/ERP5/Document/PaymentSimulationRule.py
index 10f15b9944..6d58fd556c 100644
--- a/product/ERP5/Document/PaymentSimulationRule.py
+++ b/product/ERP5/Document/PaymentSimulationRule.py
@@ -63,7 +63,27 @@ class PaymentSimulationRule(Rule, PredicateMatrix):
     movement_and_tuple_list = self._getInputMovementAndPathTupleList(
         applied_rule)
     input_movement = movement_and_tuple_list[0][0]
-    payment_condition_list = [x[1] for x in movement_and_tuple_list if x[1] is not None]
+
+    payment_conditon_list = []
+
+    # try to find local payment conditions
+    delivery = input_movement.getDeliveryValue()
+    if delivery is None:
+      delivery = input_movement.getExplanationValue()
+    if delivery is not None:
+      payment_condition_list = delivery.getPaymentConditionValueList()
+
+    # try to find payment conditions in specialised trade conditions
+    if len(payment_condition_list) == 0:
+      specialise = input_movement.getSpecialiseValue()
+      if specialise is None and delivery is not None:
+        specialise = delivery.getSpecialiseValue()
+      if specialise is not None:
+        payment_condition_list = specialise.getPaymentConditionValueList()
+
+    # try to use payment conditions in BPM configuration
+    if len(payment_condition_list) == 0:
+      payment_condition_list = [x[1] for x in movement_and_tuple_list if x[1] is not None]
 
     kw = self._getExpandablePropertyDict(applied_rule, input_movement, None)
     prevision_list = []
-- 
2.30.9