[Erp5-report] r20408 - in /erp5/trunk/bt5/erp5_trade: ConstraintTemplateItem/ PropertySheet...

nobody at svn.erp5.org nobody at svn.erp5.org
Thu Apr 10 12:02:40 CEST 2008


Author: seb
Date: Thu Apr 10 12:02:36 2008
New Revision: 20408

URL: http://svn.erp5.org?rev=20408&view=rev
Log:
2008-04-10 Seb
* As suggested by Romain, move some checks from a workflow script to a constraint.

Added:
    erp5/trunk/bt5/erp5_trade/WorkflowTemplateItem/portal_workflow/inventory_workflow/variables/portal_type.xml
Modified:
    erp5/trunk/bt5/erp5_trade/ConstraintTemplateItem/DuplicateInventory.py
    erp5/trunk/bt5/erp5_trade/PropertySheetTemplateItem/InventoryConstraint.py
    erp5/trunk/bt5/erp5_trade/WorkflowTemplateItem/portal_workflow/inventory_workflow/scripts/validateConsistency.xml
    erp5/trunk/bt5/erp5_trade/bt/revision

Modified: erp5/trunk/bt5/erp5_trade/ConstraintTemplateItem/DuplicateInventory.py
URL: http://svn.erp5.org/erp5/trunk/bt5/erp5_trade/ConstraintTemplateItem/DuplicateInventory.py?rev=20408&r1=20407&r2=20408&view=diff
==============================================================================
--- erp5/trunk/bt5/erp5_trade/ConstraintTemplateItem/DuplicateInventory.py (original)
+++ erp5/trunk/bt5/erp5_trade/ConstraintTemplateItem/DuplicateInventory.py Thu Apr 10 12:02:36 2008
@@ -76,49 +76,44 @@
     # way to make sure that it is impossible to validate two inventories
     # in the same time (required because we have message with right tags
     # only when the transaction is finished)
-    node_value.serialize()
+    if node_value is not None:
+      node_value.serialize()
 
-    # For each resource, we look that there is not any inventory for
-    # the same date, the same resource and the same node, or if there
-    # is already such kind of inventories being indexed
-    resource_and_variation_list = []
-    date = inventory.getStartDate()
-    date_string = repr(date)
-    countMessageWithTag = inventory.portal_activities.countMessageWithTag
-    portal = inventory.getPortalObject()
-    getObjectFromUid = portal.portal_catalog.getObject
-    getCurrentInventoryList = portal.portal_simulation.getCurrentInventoryList
-    resource_and_variation_list = []
-    for movement in inventory.getMovementList():
-      resource =  movement.getResource()
-      if resource is not None and movement.getQuantity() not in (None,''):
-        variation_text = movement.getVariationText()
-        if (resource,variation_text) not in resource_and_variation_list:
-          resource_and_variation_list.append((resource,variation_text))
-          tag = '%s_%s_%s' % (date_string, resource, variation_text)
-          if countMessageWithTag(tag) > 0 :
-            errors.append(self.generateDuplicateError(portal, obj, resource,
-                                  variation_text))
-          # Call sql request in order to see if there is another inventory
-          # for this node, resource, variation_text and date
-          inventory_list = getCurrentInventoryList(resource=resource,
-                                   variation_text=variation_text,
-                                   from_date=date, at_date=date,
-                                   default_stock_table='inventory_stock',
-                                   node=node)
-          LOG('inventory_list sql src', 0, getCurrentInventoryList(resource=resource,
-            variation_text=variation_text,
-            from_date=date, at_date=date,
-            default_stock_table='inventory_stock',
-            node=node, src__=1))
-          LOG('len inventory_list',0,len(inventory_list))
-          for inventory in inventory_list:
-            movement = getObjectFromUid(inventory.stock_uid)
-            if movement.getPortalType().find('Inventory') >= 0:
+      # For each resource, we look that there is not any inventory for
+      # the same date, the same resource and the same node, or if there
+      # is already such kind of inventories being indexed
+      resource_and_variation_list = []
+      date = inventory.getStartDate()
+      date_string = repr(date)
+      countMessageWithTag = inventory.portal_activities.countMessageWithTag
+      portal = inventory.getPortalObject()
+      getObjectFromUid = portal.portal_catalog.getObject
+      getCurrentInventoryList = portal.portal_simulation.getCurrentInventoryList
+      resource_and_variation_list = []
+      for movement in inventory.getMovementList():
+        resource =  movement.getResource()
+        if resource is not None and movement.getQuantity() not in (None,''):
+          variation_text = movement.getVariationText()
+          if (resource,variation_text) not in resource_and_variation_list:
+            resource_and_variation_list.append((resource,variation_text))
+            tag = '%s_%s_%s' % (date_string, resource, variation_text)
+            if countMessageWithTag(tag) > 0 :
               errors.append(self.generateDuplicateError(portal, obj, resource,
-                                  variation_text))
-        # Now we must reindex with some particular tags
-        activate_kw = {'tag': tag}
-        movement.reindexObject(activate_kw=activate_kw)
+                                    variation_text))
+            # Call sql request in order to see if there is another inventory
+            # for this node, resource, variation_text and date
+            inventory_list = getCurrentInventoryList(resource=resource,
+                                     variation_text=variation_text,
+                                     from_date=date, at_date=date,
+                                     default_stock_table='inventory_stock',
+                                     node=node)
+            for inventory in inventory_list:
+              movement = getObjectFromUid(inventory.stock_uid)
+              if movement.getPortalType().find('Inventory') >= 0:
+                errors.append(self.generateDuplicateError(portal, obj, resource,
+                                    variation_text))
+          # Now we must reindex with some particular tags
+          activate_kw = {'tag': tag}
+          movement.reindexObject(activate_kw=activate_kw)
     
     return errors

Modified: erp5/trunk/bt5/erp5_trade/PropertySheetTemplateItem/InventoryConstraint.py
URL: http://svn.erp5.org/erp5/trunk/bt5/erp5_trade/PropertySheetTemplateItem/InventoryConstraint.py?rev=20408&r1=20407&r2=20408&view=diff
==============================================================================
--- erp5/trunk/bt5/erp5_trade/PropertySheetTemplateItem/InventoryConstraint.py (original)
+++ erp5/trunk/bt5/erp5_trade/PropertySheetTemplateItem/InventoryConstraint.py Thu Apr 10 12:02:36 2008
@@ -25,6 +25,8 @@
 #
 ##############################################################################
 
+from Products.CMFCore.Expression import Expression
+
 class InventoryConstraint:
   """
   Inventory Constraint
@@ -34,5 +36,22 @@
     'id': 'duplicate_inventory',
     'type': 'DuplicateInventory',
     },
-          
+    { 'id'            : 'category_existence',
+      'description'   : 'Source, Destination and Sections must be defined',
+      'type'          : 'CategoryExistence',
+      'portal_type'   : Expression('python: portal.getPortalNodeTypeList()'),
+      'destination'        : 1,
+      'destination_section': 1,
+    },
+    { 'id'            : 'start_date',
+      'description'   : 'Start Date must be defined',
+      'type'          : 'PropertyExistence',
+      'start_date'    : 1,
+    },
+    { 'id'            : 'resource_on_line',
+      'description'   : 'Resource must be defined on all lines',
+      'type'          : 'TALESConstraint',
+      'expression'    : 'python: None not in [x.getResourceValue() for x in object.getMovementList()]',
+      'message_expression_false': 'You must define a resource on all lines',
+    },
   )

Modified: erp5/trunk/bt5/erp5_trade/WorkflowTemplateItem/portal_workflow/inventory_workflow/scripts/validateConsistency.xml
URL: http://svn.erp5.org/erp5/trunk/bt5/erp5_trade/WorkflowTemplateItem/portal_workflow/inventory_workflow/scripts/validateConsistency.xml?rev=20408&r1=20407&r2=20408&view=diff
==============================================================================
--- erp5/trunk/bt5/erp5_trade/WorkflowTemplateItem/portal_workflow/inventory_workflow/scripts/validateConsistency.xml (original)
+++ erp5/trunk/bt5/erp5_trade/WorkflowTemplateItem/portal_workflow/inventory_workflow/scripts/validateConsistency.xml Thu Apr 10 12:02:36 2008
@@ -65,42 +65,14 @@
         </item>
         <item>
             <key> <string>_body</string> </key>
-            <value> <string encoding="cdata"><![CDATA[
-
-from Products.ERP5Type.Message import Message\n
+            <value> <string>from Products.ERP5Type.Message import Message\n
 from Products.DCWorkflow.DCWorkflow import ValidationFailed\n
 \n
 inventory = state_change[\'object\']\n
 \n
-# Make sure the start_date is defined\n
-start_date = inventory.getStartDate()\n
-if start_date is None:\n
-  text = "Sorry, you must define the inventory date"\n
-  message = Message(domain=\'ui\', message=text)\n
-  raise ValidationFailed, message\n
-\n
-# Make sure the node is defined\n
-node = inventory.getDestination()\n
-if node is None:\n
-  text = "Sorry, you must define the inventory warehouse"\n
-  message = Message(domain=\'ui\', message=text)\n
-  raise ValidationFailed, message\n
-\n
-for line in inventory.getMovementList():\n
-  if line.getResource() is None:\n
-    text = "Sorry, no resource for line $line_title"\n
-    message = Message(domain=\'ui\', message=text,\n
-                      mapping={\'line_title\': line.getTitle()})\n
-    raise ValidationFailed, message\n
-\n
-\n
 # use of the constraint\n
-error_list = inventory.checkConsistency()\n
-if len(error_list) > 0:\n
-  raise ValidationFailed, (error_list[0].getTranslatedMessage(),)\n
-
-
-]]></string> </value>
+inventory.Base_checkConsistency()\n
+</string> </value>
         </item>
         <item>
             <key> <string>_code</string> </key>
@@ -151,15 +123,6 @@
                             <string>_getitem_</string>
                             <string>inventory</string>
                             <string>_getattr_</string>
-                            <string>start_date</string>
-                            <string>None</string>
-                            <string>text</string>
-                            <string>message</string>
-                            <string>node</string>
-                            <string>_getiter_</string>
-                            <string>line</string>
-                            <string>error_list</string>
-                            <string>len</string>
                           </tuple>
                         </value>
                     </item>

Added: erp5/trunk/bt5/erp5_trade/WorkflowTemplateItem/portal_workflow/inventory_workflow/variables/portal_type.xml
URL: http://svn.erp5.org/erp5/trunk/bt5/erp5_trade/WorkflowTemplateItem/portal_workflow/inventory_workflow/variables/portal_type.xml?rev=20408&view=auto
==============================================================================
--- erp5/trunk/bt5/erp5_trade/WorkflowTemplateItem/portal_workflow/inventory_workflow/variables/portal_type.xml (added)
+++ erp5/trunk/bt5/erp5_trade/WorkflowTemplateItem/portal_workflow/inventory_workflow/variables/portal_type.xml Thu Apr 10 12:02:36 2008
@@ -1,0 +1,57 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <tuple>
+        <global name="VariableDefinition" module="Products.DCWorkflow.Variables"/>
+        <tuple/>
+      </tuple>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>__ac_local_roles__</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>default_expr</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>default_value</string> </key>
+            <value> <string></string> </value>
+        </item>
+        <item>
+            <key> <string>description</string> </key>
+            <value> <string></string> </value>
+        </item>
+        <item>
+            <key> <string>for_catalog</string> </key>
+            <value> <int>1</int> </value>
+        </item>
+        <item>
+            <key> <string>for_status</string> </key>
+            <value> <int>0</int> </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>portal_type</string> </value>
+        </item>
+        <item>
+            <key> <string>info_guard</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>update_always</string> </key>
+            <value> <int>0</int> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>

Modified: erp5/trunk/bt5/erp5_trade/bt/revision
URL: http://svn.erp5.org/erp5/trunk/bt5/erp5_trade/bt/revision?rev=20408&r1=20407&r2=20408&view=diff
==============================================================================
--- erp5/trunk/bt5/erp5_trade/bt/revision (original)
+++ erp5/trunk/bt5/erp5_trade/bt/revision Thu Apr 10 12:02:36 2008
@@ -1,1 +1,1 @@
-231
+232




More information about the Erp5-report mailing list