Commit d0256637 authored by Sebastien Robin's avatar Sebastien Robin

2008-04-10 Seb

* As suggested by Romain, move some checks from a workflow script to a constraint.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@20408 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 793e16ff
......@@ -76,6 +76,7 @@ class DuplicateInventory(Constraint):
# 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)
if node_value is not None:
node_value.serialize()
# For each resource, we look that there is not any inventory for
......@@ -106,12 +107,6 @@ class DuplicateInventory(Constraint):
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:
......
......@@ -25,6 +25,8 @@
#
##############################################################################
from Products.CMFCore.Expression import Expression
class InventoryConstraint:
"""
Inventory Constraint
......@@ -34,5 +36,22 @@ class InventoryConstraint:
'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',
},
)
......@@ -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 @@ if len(error_list) > 0:\n
<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>
......
<?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>
231
\ No newline at end of file
232
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment