From 37f60d6a7a4bc510de3e1850d8ab0ce29476a2ce Mon Sep 17 00:00:00 2001
From: Jean-Paul Smets <jp@nexedi.com>
Date: Sun, 8 Feb 2004 17:27:42 +0000
Subject: [PATCH] addPermission changed to addPortalContent fixed Solanes typo
 implementation of deliverable initial implementation of transformation
 filters

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@414 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/Document/TransformationRule.py | 33 ++++++++++++++++-----
 1 file changed, 26 insertions(+), 7 deletions(-)

diff --git a/product/ERP5/Document/TransformationRule.py b/product/ERP5/Document/TransformationRule.py
index 161c056ad3..f48b5e708f 100755
--- a/product/ERP5/Document/TransformationRule.py
+++ b/product/ERP5/Document/TransformationRule.py
@@ -1,7 +1,7 @@
 ##############################################################################
 #
 # Copyright (c) 2002 Nexedi SARL and Contributors. All Rights Reserved.
-#                    Jean-Paul Smets-Solane <jp@nexedi.com>
+#                    Jean-Paul Smets-Solanes <jp@nexedi.com>
 #
 # WARNING: This program as such is intended to be used by professional
 # programmers who take the whole responsability of assessing all potential
@@ -44,7 +44,7 @@ class TransformationRule(Rule):
     # CMF Type Definition
     meta_type = 'ERP5 Transformation Rule'
     portal_type = 'Transformation Rule'
-    add_permission = Permissions.AddERP5Content
+    add_permission = Permissions.AddPortalContent
     isPortalContent = 1
     isRADContent = 1
 
@@ -153,6 +153,14 @@ An ERP5 Rule..."""
           if source.find('site/Piquage') >= 0 :
             return 1
           return 0
+      elif module.id == 'assortiment':
+        destination = movement.getDestination()
+        if type(destination) is type('a'):
+          if destination.find('site/Stock_PF/Gravelines') >= 0 :
+            source = movement.getSource()
+            if type(source) is type('a'):
+              if source.find('site/Stock_PF/Gravelines') >= 0 :
+                return 1
       return 0
 
     # Simulation workflow
@@ -205,17 +213,22 @@ An ERP5 Rule..."""
               container = applied_rule,
               id = new_id,
           ) # quantity
+        lost_quantity = 0.0
+      else:
+        lost_quantity = produced_resource.getLostQuantity()
+
       produced_resource = applied_rule[new_id]
       produced_resource._edit(
         target_start_date = my_context_movement.getTargetStartDate(),
         target_stop_date = my_context_movement.getTargetStartDate(),
         resource = my_context_movement.getResource(),
-        target_quantity = my_context_movement.getTargetQuantity(),
+        target_quantity = my_context_movement.getTargetQuantity() + lost_quantity,
         source_list = (),
         source_section_list = (),
         quantity_unit = my_context_movement.getQuantityUnit(),
         destination_section = production_section,
-        destination = production_node
+        destination = production_node,
+        deliverable = 0
       )
       # Mising quantity unit conversion for my_quantity !!!! XXXX
       produced_resource.setVariationCategoryList(my_context_movement.getVariationCategoryList())
@@ -223,7 +236,12 @@ An ERP5 Rule..."""
       # Add lines
       line_number = 0
       acceptable_id_list = ['produced_resource']
+      production_order = self.getRootAppliedRule().getCausalityValue() # get the production order
+      filter_list = production_order.contentValues(filter={'portal_type': 'Amount Filter'})
       for amount_line in amount_list:
+        # Apply each amount filter
+        for f in filter_list:
+          f.update(amount_line)
         new_id = 'transformed_resource_%s' % line_number
         transformed_resource = applied_rule.get(new_id)
         if transformed_resource is None:
@@ -245,7 +263,8 @@ An ERP5 Rule..."""
             quantity_unit = amount_line['quantity_unit'],
             source = production_node,
             source_section = production_section,
-            destination_list = ()
+            destination_list = (),
+            deliverable = 0
           )
           #LOG('RESOURCE', 0, str(amount_line['resource'].getRelativeUrl()))
           #LOG('VC List', 0, str(amount_line['variation_category_list']))
@@ -266,7 +285,7 @@ An ERP5 Rule..."""
       for movement in applied_rule.objectValues():
         if movement.getId() not in acceptable_id_list:
           movement.flushActivity(invoke=0)
-          applied_rule._delObject(movement.getId())
+          applied_rule._delObject(movement.getId()) # XXXX Make sur this is not deleted if already in delivery
 
       # Pass to base class
       Rule.expand(self, applied_rule)
@@ -311,4 +330,4 @@ An ERP5 Rule..."""
     def getSolverList(self, applied_rule):
       """
         Returns a list Divergence solvers
-      """
+      """
\ No newline at end of file
-- 
2.30.9