From 0fa1d0b812df20cef4f80a87ee9ce9ccc789cb4f Mon Sep 17 00:00:00 2001
From: Fabien Morin <fabien@nexedi.com>
Date: Fri, 19 Jun 2009 11:07:39 +0000
Subject: [PATCH] set some categories on the movement using business path.

In this way, it's possible define that for a precise trade_phase, a precise source and destination will be set on movements.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@27678 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/Document/TradeModelLine.py | 47 +++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/product/ERP5/Document/TradeModelLine.py b/product/ERP5/Document/TradeModelLine.py
index b8b9097acc..1e7e195d18 100644
--- a/product/ERP5/Document/TradeModelLine.py
+++ b/product/ERP5/Document/TradeModelLine.py
@@ -133,6 +133,51 @@ class TradeModelLine(Predicate, XMLMatrix, Amount):
                                                 # having cells
       update = 1
     else:
+      # get source and destination using Business Process
+      document = self.getParentValue()
+      if getattr(document, 'findSpecialiseValueList', None) is None:
+        # if parent don't have findSpecialiseValueList, this mean it's on the
+        # specialise_value
+        document = self.getParentValue().getSpecialiseValue()
+      business_process_list = document.findSpecialiseValueList(\
+          context=self, portal_type_list=['Business Process'])
+      business_process = None
+      property_dict = {}
+      if len(business_process_list):
+        # XXX currently, is too complicated to use more than
+        # one Business Process, so the first (which is the nearest from the
+        # delivery) is took
+        business_process = business_process_list[0]
+        business_path_list = business_process.getPathValueList(trade_phase=\
+            self.getTradePhase())
+        if len(business_path_list) > 1:
+          raise NotImplementedError, 'For now, it can not support more '\
+              'than one business_path with same trade_phase. '\
+              '%s have same trade_phase' % repr(business_path_list)
+        if len(business_path_list) == 1:
+          business_path = business_path_list[0]
+          property_dict={
+            'source_value_list': business_path.getSourceValueList(context=context),
+            'destination_value_list':
+            business_path.getDestinationValueList(context=context),
+            'source_section_value_list':
+            business_path.getSourceSectionValueList(context=context),
+            'destination_section_value_list':
+            business_path.getDestinationSectionValueList(context=context),
+            'source_decision_value_list':
+            business_path.getSourceDecisionValueList(context=context),
+            'source_administration_value_list':
+            business_path.getSourceAdministrationValueList(context=context),
+            'source_payment_value_list':
+            business_path.getSourcePaymentValueList(context=context),
+            'destination_decision_value_list':
+            business_path.getDestinationDecisionValueList(context=context),
+            'destination_administration_value_list':
+            business_path.getDestinationAdministrationValueList(context=context),
+            'destination_payment_value_list':
+            business_path.getDestinationPaymentValueList(context=context)
+          }
+
       common_params = {
         'causality': self.getRelativeUrl(),
         'resource': self.getResource(),
@@ -144,6 +189,8 @@ class TradeModelLine(Predicate, XMLMatrix, Amount):
         'create_line': self.isCreateLine(),
         'trade_phase_list': self.getTradePhaseList(),
       }
+      common_params.update(property_dict)
+
       update = 0
       base_category_list = self.getVariationBaseCategoryList()
       category_list_list = []
-- 
2.30.9