From 8bc2adadc2c482acf48ee1ca004ea435adc860a4 Mon Sep 17 00:00:00 2001
From: Julien Muchembled <jm@nexedi.com>
Date: Sat, 7 Aug 2010 00:42:45 +0000
Subject: [PATCH] Move conflicting classes from ERP5Legacy product to
 erp5_legacy BT

git-svn-id: https://svn.erp5.org/repos/public/erp5/sandbox/amount_generator@37616 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../DeliveryRootSimulationRule.py             |  0
 .../DeliverySimulationRule.py                 |  0
 .../InvoiceRootSimulationRule.py              |  0
 .../InvoiceSimulationRule.py                  |  0
 .../InvoiceTransactionSimulationRule.py       |  0
 .../OrderRootSimulationRule.py                |  0
 .../PaymentSimulationRule.py                  |  0
 .../RootAppliedRuleCausalityMovementGroup.py  |  0
 .../TradeModelSimulationRule.py               |  0
 bt5/erp5_legacy/bt/template_document_id_list  |  9 +++++
 product/ERP5Legacy/Document/Rule.py           | 37 ++++++++++++++++++-
 product/ERP5Legacy/Document/TradeModelRule.py |  8 ++--
 product/ERP5Legacy/tests/testLegacyBPMCore.py |  2 +-
 .../tests/testLegacyConversionInSimulation.py |  4 +-
 product/ERP5Legacy/tests/testLegacyInvoice.py |  2 +-
 product/ERP5Legacy/tests/testLegacyOrder.py   |  2 +-
 .../tests/testLegacyProductionOrder.py        |  2 +-
 .../tests/testLegacySimulationInvoice.py      |  2 +-
 .../tests/testLegacyTradeCondition.py         |  3 +-
 19 files changed, 59 insertions(+), 12 deletions(-)
 rename {product/ERP5Legacy/Document => bt5/erp5_legacy/DocumentTemplateItem}/DeliveryRootSimulationRule.py (100%)
 rename {product/ERP5Legacy/Document => bt5/erp5_legacy/DocumentTemplateItem}/DeliverySimulationRule.py (100%)
 rename {product/ERP5Legacy/Document => bt5/erp5_legacy/DocumentTemplateItem}/InvoiceRootSimulationRule.py (100%)
 rename {product/ERP5Legacy/Document => bt5/erp5_legacy/DocumentTemplateItem}/InvoiceSimulationRule.py (100%)
 rename {product/ERP5Legacy/Document => bt5/erp5_legacy/DocumentTemplateItem}/InvoiceTransactionSimulationRule.py (100%)
 rename {product/ERP5Legacy/Document => bt5/erp5_legacy/DocumentTemplateItem}/OrderRootSimulationRule.py (100%)
 rename {product/ERP5Legacy/Document => bt5/erp5_legacy/DocumentTemplateItem}/PaymentSimulationRule.py (100%)
 rename {product/ERP5Legacy/Document => bt5/erp5_legacy/DocumentTemplateItem}/RootAppliedRuleCausalityMovementGroup.py (100%)
 rename {product/ERP5Legacy/Document => bt5/erp5_legacy/DocumentTemplateItem}/TradeModelSimulationRule.py (100%)

diff --git a/product/ERP5Legacy/Document/DeliveryRootSimulationRule.py b/bt5/erp5_legacy/DocumentTemplateItem/DeliveryRootSimulationRule.py
similarity index 100%
rename from product/ERP5Legacy/Document/DeliveryRootSimulationRule.py
rename to bt5/erp5_legacy/DocumentTemplateItem/DeliveryRootSimulationRule.py
diff --git a/product/ERP5Legacy/Document/DeliverySimulationRule.py b/bt5/erp5_legacy/DocumentTemplateItem/DeliverySimulationRule.py
similarity index 100%
rename from product/ERP5Legacy/Document/DeliverySimulationRule.py
rename to bt5/erp5_legacy/DocumentTemplateItem/DeliverySimulationRule.py
diff --git a/product/ERP5Legacy/Document/InvoiceRootSimulationRule.py b/bt5/erp5_legacy/DocumentTemplateItem/InvoiceRootSimulationRule.py
similarity index 100%
rename from product/ERP5Legacy/Document/InvoiceRootSimulationRule.py
rename to bt5/erp5_legacy/DocumentTemplateItem/InvoiceRootSimulationRule.py
diff --git a/product/ERP5Legacy/Document/InvoiceSimulationRule.py b/bt5/erp5_legacy/DocumentTemplateItem/InvoiceSimulationRule.py
similarity index 100%
rename from product/ERP5Legacy/Document/InvoiceSimulationRule.py
rename to bt5/erp5_legacy/DocumentTemplateItem/InvoiceSimulationRule.py
diff --git a/product/ERP5Legacy/Document/InvoiceTransactionSimulationRule.py b/bt5/erp5_legacy/DocumentTemplateItem/InvoiceTransactionSimulationRule.py
similarity index 100%
rename from product/ERP5Legacy/Document/InvoiceTransactionSimulationRule.py
rename to bt5/erp5_legacy/DocumentTemplateItem/InvoiceTransactionSimulationRule.py
diff --git a/product/ERP5Legacy/Document/OrderRootSimulationRule.py b/bt5/erp5_legacy/DocumentTemplateItem/OrderRootSimulationRule.py
similarity index 100%
rename from product/ERP5Legacy/Document/OrderRootSimulationRule.py
rename to bt5/erp5_legacy/DocumentTemplateItem/OrderRootSimulationRule.py
diff --git a/product/ERP5Legacy/Document/PaymentSimulationRule.py b/bt5/erp5_legacy/DocumentTemplateItem/PaymentSimulationRule.py
similarity index 100%
rename from product/ERP5Legacy/Document/PaymentSimulationRule.py
rename to bt5/erp5_legacy/DocumentTemplateItem/PaymentSimulationRule.py
diff --git a/product/ERP5Legacy/Document/RootAppliedRuleCausalityMovementGroup.py b/bt5/erp5_legacy/DocumentTemplateItem/RootAppliedRuleCausalityMovementGroup.py
similarity index 100%
rename from product/ERP5Legacy/Document/RootAppliedRuleCausalityMovementGroup.py
rename to bt5/erp5_legacy/DocumentTemplateItem/RootAppliedRuleCausalityMovementGroup.py
diff --git a/product/ERP5Legacy/Document/TradeModelSimulationRule.py b/bt5/erp5_legacy/DocumentTemplateItem/TradeModelSimulationRule.py
similarity index 100%
rename from product/ERP5Legacy/Document/TradeModelSimulationRule.py
rename to bt5/erp5_legacy/DocumentTemplateItem/TradeModelSimulationRule.py
diff --git a/bt5/erp5_legacy/bt/template_document_id_list b/bt5/erp5_legacy/bt/template_document_id_list
index e69de29bb2..4dba4a881b 100644
--- a/bt5/erp5_legacy/bt/template_document_id_list
+++ b/bt5/erp5_legacy/bt/template_document_id_list
@@ -0,0 +1,9 @@
+DeliveryRootSimulationRule
+DeliverySimulationRule
+InvoiceRootSimulationRule
+InvoiceSimulationRule
+InvoiceTransactionSimulationRule
+OrderRootSimulationRule
+PaymentSimulationRule
+RootAppliedRuleCausalityMovementGroup
+TradeModelSimulationRule
\ No newline at end of file
diff --git a/product/ERP5Legacy/Document/Rule.py b/product/ERP5Legacy/Document/Rule.py
index 7bc9dc3a05..51c7467ee6 100644
--- a/product/ERP5Legacy/Document/Rule.py
+++ b/product/ERP5Legacy/Document/Rule.py
@@ -35,6 +35,40 @@ from Products.ERP5Type.XMLObject import XMLObject
 from Products.ERP5.Document.Predicate import Predicate
 from Acquisition import aq_base
 
+
+# resurrected from old AppliedRule class
+def AppliedRule_getExplanationSpecialiseValue(self, portal_type_list):
+  """Returns first found specialise value of delivery or order
+  In case if self is root Applied Rule uses causality
+  Otherwise uses delivery, than order of parent movements
+  Recurses to parents"""
+  def findSpecialiseValueBySimulation(movement):
+    specialise_value = None
+    if movement.getPortalType() != 'Simulation Movement':
+      return None
+    delivery, order = movement.getDeliveryValue(), movement.getOrderValue()
+
+    if delivery is not None:
+      specialise_value = delivery.getExplanationValue() \
+          .getRootSpecialiseValue(portal_type_list)
+      if specialise_value is not None:
+        return specialise_value
+    # 'order' category is deprecated. it is kept for compatibility.
+    if order is not None:
+      specialise_value = order.getExplanationValue() \
+          .getRootSpecialiseValue(portal_type_list)
+      if specialise_value is not None:
+        return specialise_value
+    return findSpecialiseValueBySimulation(movement.getParentValue() \
+        .getParentValue())
+
+  if self.getRootAppliedRule() == self:
+    return self.getCausalityValue() \
+        .getRootSpecialiseValue(portal_type_list)
+  movement = self.getParentValue()
+  return findSpecialiseValueBySimulation(movement)
+
+
 class Rule(Predicate, XMLObject):
   """
     Rule objects implement the simulation algorithm
@@ -353,7 +387,8 @@ class Rule(Predicate, XMLObject):
   def _getInputMovementAndPathTupleList(self, applied_rule):
     """Returns list of tuples (movement, business_path)"""
     input_movement_list = self._getInputMovementList(applied_rule)
-    business_process = applied_rule.getBusinessProcessValue()
+    business_process = AppliedRule_getExplanationSpecialiseValue(applied_rule,
+      ('Business Process',))
     trade_phase_list = self.getTradePhaseList()
 
     # In non-BPM case, we have no business path.
diff --git a/product/ERP5Legacy/Document/TradeModelRule.py b/product/ERP5Legacy/Document/TradeModelRule.py
index 4d62810e5c..c30fc8d3ba 100644
--- a/product/ERP5Legacy/Document/TradeModelRule.py
+++ b/product/ERP5Legacy/Document/TradeModelRule.py
@@ -30,7 +30,8 @@
 from AccessControl import ClassSecurityInfo
 from Products.ERP5Type import Permissions
 
-from Products.ERP5Legacy.Document.Rule import Rule
+from Products.ERP5Legacy.Document.Rule import Rule, \
+  AppliedRule_getExplanationSpecialiseValue
 
 class TradeModelRule(Rule):
   """
@@ -59,9 +60,10 @@ class TradeModelRule(Rule):
     """Generates list of movements (as dicts), and let parent class to decide
     which is to add, modify or delete"""
     movement_list = []
-    trade_condition = applied_rule._getExplanationSpecialiseValue(
+    trade_condition = AppliedRule_getExplanationSpecialiseValue(applied_rule,
         ('Purchase Trade Condition', 'Sale Trade Condition'))
-    business_process = applied_rule.getBusinessProcessValue()
+    business_process = AppliedRule_getExplanationSpecialiseValue(applied_rule,
+        ('Business Process',))
 
     if trade_condition is None or business_process is None:
       return movement_list
diff --git a/product/ERP5Legacy/tests/testLegacyBPMCore.py b/product/ERP5Legacy/tests/testLegacyBPMCore.py
index d828a3b819..371d3673cf 100644
--- a/product/ERP5Legacy/tests/testLegacyBPMCore.py
+++ b/product/ERP5Legacy/tests/testLegacyBPMCore.py
@@ -42,7 +42,7 @@ class TestBPMMixin(ERP5TypeTestCase):
 
   def getBusinessTemplateList(self):
     return ('erp5_base', 'erp5_pdm', 'erp5_trade', 'erp5_accounting',
-      'erp5_invoicing', 'erp5_simplified_invoicing')
+      'erp5_invoicing', 'erp5_simplified_invoicing', 'erp5_legacy')
 
   business_process_portal_type = 'Business Process'
   business_path_portal_type = 'Business Path'
diff --git a/product/ERP5Legacy/tests/testLegacyConversionInSimulation.py b/product/ERP5Legacy/tests/testLegacyConversionInSimulation.py
index 9abd6ed9c0..304a291872 100644
--- a/product/ERP5Legacy/tests/testLegacyConversionInSimulation.py
+++ b/product/ERP5Legacy/tests/testLegacyConversionInSimulation.py
@@ -168,8 +168,8 @@ class TestConversionInSimulation(AccountingTestCase,ERP5TypeTestCase):
             'erp5_accounting',
 	    'erp5_accounting_ui_test',
 	    'erp5_invoicing',
-            'erp5_simplified_invoicing'
-            )
+            'erp5_simplified_invoicing',
+            'erp5_legacy')
 
   @UnrestrictedMethod
   def createInvoiceTransactionRule(self, resource=None):
diff --git a/product/ERP5Legacy/tests/testLegacyInvoice.py b/product/ERP5Legacy/tests/testLegacyInvoice.py
index 856d8d72c7..0e08b686bd 100644
--- a/product/ERP5Legacy/tests/testLegacyInvoice.py
+++ b/product/ERP5Legacy/tests/testLegacyInvoice.py
@@ -84,7 +84,7 @@ class TestInvoiceMixin(TestPackingListMixin,
   def getBusinessTemplateList(self):
     return ('erp5_base', 'erp5_pdm', 'erp5_trade', 'erp5_accounting',
             'erp5_invoicing', 'erp5_simplified_invoicing', 'erp5_apparel',
-            'erp5_project', 'erp5_administration')
+            'erp5_project', 'erp5_legacy', 'erp5_administration')
 
   @UnrestrictedMethod
   def createCategories(self):
diff --git a/product/ERP5Legacy/tests/testLegacyOrder.py b/product/ERP5Legacy/tests/testLegacyOrder.py
index 080b764c1d..6ed902e84a 100644
--- a/product/ERP5Legacy/tests/testLegacyOrder.py
+++ b/product/ERP5Legacy/tests/testLegacyOrder.py
@@ -61,7 +61,7 @@ class TestOrderMixin:
     """
     """
     return ('erp5_base','erp5_pdm', 'erp5_trade', 'erp5_apparel',
-            'erp5_project', 'erp5_administration')
+            'erp5_project', 'erp5_legacy', 'erp5_administration')
 
   def login(self, quiet=0, run=1):
     uf = self.getPortal().acl_users
diff --git a/product/ERP5Legacy/tests/testLegacyProductionOrder.py b/product/ERP5Legacy/tests/testLegacyProductionOrder.py
index b6e6810f17..dd555755d3 100644
--- a/product/ERP5Legacy/tests/testLegacyProductionOrder.py
+++ b/product/ERP5Legacy/tests/testLegacyProductionOrder.py
@@ -65,7 +65,7 @@ class TestProductionOrderMixin(TestOrderMixin):
   def getBusinessTemplateList(self):
     """
     """
-    return ('erp5_base','erp5_pdm', 'erp5_trade', 'erp5_mrp',)
+    return ('erp5_base','erp5_pdm', 'erp5_trade', 'erp5_mrp', 'erp5_legacy')
 
   def setUpPreferences(self):
     portal = self.getPortal()
diff --git a/product/ERP5Legacy/tests/testLegacySimulationInvoice.py b/product/ERP5Legacy/tests/testLegacySimulationInvoice.py
index 9872c42e21..3d0051a492 100644
--- a/product/ERP5Legacy/tests/testLegacySimulationInvoice.py
+++ b/product/ERP5Legacy/tests/testLegacySimulationInvoice.py
@@ -83,7 +83,7 @@ class TestInvoiceMixin(TestPackingListMixin,
   def getBusinessTemplateList(self):
     return ('erp5_base', 'erp5_pdm', 'erp5_trade', 'erp5_accounting',
             'erp5_invoicing', 'erp5_simplified_invoicing', 'erp5_apparel',
-            'erp5_project', 'erp5_administration')
+            'erp5_project', 'erp5_legacy', 'erp5_administration')
 
   @UnrestrictedMethod
   def createCategories(self):
diff --git a/product/ERP5Legacy/tests/testLegacyTradeCondition.py b/product/ERP5Legacy/tests/testLegacyTradeCondition.py
index 904b8ee10f..2808be4a22 100644
--- a/product/ERP5Legacy/tests/testLegacyTradeCondition.py
+++ b/product/ERP5Legacy/tests/testLegacyTradeCondition.py
@@ -39,7 +39,8 @@ class TradeConditionTestCase(ERP5TypeTestCase):
   def getBusinessTemplateList(self):
     return ('erp5_base', 'erp5_pdm', 'erp5_trade', 'erp5_accounting',
             'erp5_invoicing', 'erp5_tax_resource', 'erp5_discount_resource',
-            'erp5_legacy_tax_system', 'erp5_simplified_invoicing',)
+            'erp5_legacy_tax_system', 'erp5_simplified_invoicing',
+            'erp5_legacy')
 
   def validateRules(self):
     """
-- 
2.30.9