[Erp5-report] r43548 seb - in /erp5/trunk/bt5/erp5_trade: ActionTemplateItem/portal_types/D...
nobody at svn.erp5.org
nobody at svn.erp5.org
Tue Feb 22 11:37:46 CET 2011
Author: seb
Date: Tue Feb 22 11:37:46 2011
New Revision: 43548
URL: http://svn.erp5.org?rev=43548&view=rev
Log:
make DuplicateInventoryConstraint a new style constraint
Added:
erp5/trunk/bt5/erp5_trade/ActionTemplateItem/portal_types/Duplicate%20Inventory%20Constraint/
erp5/trunk/bt5/erp5_trade/ActionTemplateItem/portal_types/Duplicate%20Inventory%20Constraint/view.xml
erp5/trunk/bt5/erp5_trade/DocumentTemplateItem/
erp5/trunk/bt5/erp5_trade/DocumentTemplateItem/DuplicateInventoryConstraint.py
erp5/trunk/bt5/erp5_trade/PortalTypeTemplateItem/portal_types/Duplicate%20Inventory%20Constraint.xml
erp5/trunk/bt5/erp5_trade/bt/template_document_id_list
Removed:
erp5/trunk/bt5/erp5_trade/ConstraintTemplateItem/
erp5/trunk/bt5/erp5_trade/bt/template_constraint_id_list
Modified:
erp5/trunk/bt5/erp5_trade/bt/revision
erp5/trunk/bt5/erp5_trade/bt/template_action_path_list
erp5/trunk/bt5/erp5_trade/bt/template_portal_type_id_list
Added: erp5/trunk/bt5/erp5_trade/ActionTemplateItem/portal_types/Duplicate%20Inventory%20Constraint/view.xml
URL: http://svn.erp5.org/erp5/trunk/bt5/erp5_trade/ActionTemplateItem/portal_types/Duplicate%2520Inventory%2520Constraint/view.xml?rev=43548&view=auto
==============================================================================
--- erp5/trunk/bt5/erp5_trade/ActionTemplateItem/portal_types/Duplicate%20Inventory%20Constraint/view.xml (added)
+++ erp5/trunk/bt5/erp5_trade/ActionTemplateItem/portal_types/Duplicate%20Inventory%20Constraint/view.xml [utf8] Tue Feb 22 11:37:46 2011
@@ -0,0 +1,85 @@
+<?xml version="1.0"?>
+<ZopeData>
+ <record id="1" aka="AAAAAAAAAAE=">
+ <pickle>
+ <global name="ActionInformation" module="Products.CMFCore.ActionInformation"/>
+ </pickle>
+ <pickle>
+ <dictionary>
+ <item>
+ <key> <string>action</string> </key>
+ <value>
+ <persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
+ </value>
+ </item>
+ <item>
+ <key> <string>categories</string> </key>
+ <value>
+ <tuple>
+ <string>action_type/object_view</string>
+ </tuple>
+ </value>
+ </item>
+ <item>
+ <key> <string>category</string> </key>
+ <value> <string>object_view</string> </value>
+ </item>
+ <item>
+ <key> <string>condition</string> </key>
+ <value> <string></string> </value>
+ </item>
+ <item>
+ <key> <string>description</string> </key>
+ <value>
+ <none/>
+ </value>
+ </item>
+ <item>
+ <key> <string>icon</string> </key>
+ <value> <string></string> </value>
+ </item>
+ <item>
+ <key> <string>id</string> </key>
+ <value> <string>view</string> </value>
+ </item>
+ <item>
+ <key> <string>permissions</string> </key>
+ <value>
+ <tuple>
+ <string>View</string>
+ </tuple>
+ </value>
+ </item>
+ <item>
+ <key> <string>portal_type</string> </key>
+ <value> <string>Action Information</string> </value>
+ </item>
+ <item>
+ <key> <string>priority</string> </key>
+ <value> <float>1.0</float> </value>
+ </item>
+ <item>
+ <key> <string>title</string> </key>
+ <value> <string>View</string> </value>
+ </item>
+ <item>
+ <key> <string>visible</string> </key>
+ <value> <int>1</int> </value>
+ </item>
+ </dictionary>
+ </pickle>
+ </record>
+ <record id="2" aka="AAAAAAAAAAI=">
+ <pickle>
+ <global name="Expression" module="Products.CMFCore.Expression"/>
+ </pickle>
+ <pickle>
+ <dictionary>
+ <item>
+ <key> <string>text</string> </key>
+ <value> <string>string:${object_url}/Constraint_view</string> </value>
+ </item>
+ </dictionary>
+ </pickle>
+ </record>
+</ZopeData>
Added: erp5/trunk/bt5/erp5_trade/DocumentTemplateItem/DuplicateInventoryConstraint.py
URL: http://svn.erp5.org/erp5/trunk/bt5/erp5_trade/DocumentTemplateItem/DuplicateInventoryConstraint.py?rev=43548&view=auto
==============================================================================
--- erp5/trunk/bt5/erp5_trade/DocumentTemplateItem/DuplicateInventoryConstraint.py (added)
+++ erp5/trunk/bt5/erp5_trade/DocumentTemplateItem/DuplicateInventoryConstraint.py [utf8] Tue Feb 22 11:37:46 2011
@@ -0,0 +1,119 @@
+##############################################################################
+#
+# Copyright (c) 2002-2007 Nexedi SARL and Contributors. All Rights Reserved.
+#
+# WARNING: This program as such is intended to be used by professional
+# programmers who take the whole responsability of assessing all potential
+# consequences resulting from its eventual inadequacies and bugs
+# End users who are looking for a ready-to-use solution with commercial
+# garantees and support are strongly adviced to contract a Free Software
+# Service Company
+#
+# This program is Free Software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+##############################################################################
+
+from Products.ERP5Type.mixin.constraint import ConstraintMixin
+from zLOG import LOG
+
+class DuplicateInventoryConstraint(ConstraintMixin):
+ """
+ We want to check here that there is not 2 or more inventories with:
+ - the same resource
+ - the same date
+ - the same node
+ """
+
+ def _generateDuplicateError(self, portal, obj, resource, variation_text):
+ """
+ Use a single method in order to generate the message
+ """
+ resource_value = portal.restrictedTraverse(resource)
+ resource_title = resource_value.getTitle()
+ variation_description = ''
+ variation_title = ''
+ if len(variation_text) > 0:
+ variation_title_list = []
+ for variation in variation_text.split('\n'):
+ variation_value = portal.portal_categories\
+ .getCategoryValue(variation)
+ variation_title_list.append(variation_value.getTitle())
+ variation_title = ("(%s)" % ''.join(variation_title_list))
+ variation_description = "and variation $variation_title "
+ error_message = "%s%s%s" % \
+ ("There is already an inventory for $resource_title ",
+ variation_description, "on this node and date")
+ return self._generateError(obj, error_message,
+ mapping={'variation_title' : variation_title,
+ 'resource_title' : resource_title})
+
+ def _checkConsistency(self, obj, fixit = 0):
+ """
+ Implement here the consistency checker
+ whenever fixit is not 0, object data should be updated to
+ satisfy the constraint
+ """
+
+ errors = []
+
+ inventory = obj
+ node = inventory.getDestination()
+ node_value = inventory.getDestinationValue()
+ # Make sure to raise conflict error when two inventories are
+ # validated in the same time for the same node, this is the only
+ # 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
+ # 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)
+ 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
Added: erp5/trunk/bt5/erp5_trade/PortalTypeTemplateItem/portal_types/Duplicate%20Inventory%20Constraint.xml
URL: http://svn.erp5.org/erp5/trunk/bt5/erp5_trade/PortalTypeTemplateItem/portal_types/Duplicate%2520Inventory%2520Constraint.xml?rev=43548&view=auto
==============================================================================
--- erp5/trunk/bt5/erp5_trade/PortalTypeTemplateItem/portal_types/Duplicate%20Inventory%20Constraint.xml (added)
+++ erp5/trunk/bt5/erp5_trade/PortalTypeTemplateItem/portal_types/Duplicate%20Inventory%20Constraint.xml [utf8] Tue Feb 22 11:37:46 2011
@@ -0,0 +1,113 @@
+<?xml version="1.0"?>
+<ZopeData>
+ <record id="1" aka="AAAAAAAAAAE=">
+ <pickle>
+ <global name="Base Type" module="erp5.portal_type"/>
+ </pickle>
+ <pickle>
+ <dictionary>
+ <item>
+ <key> <string>_property_domain_dict</string> </key>
+ <value>
+ <dictionary>
+ <item>
+ <key> <string>short_title</string> </key>
+ <value>
+ <persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
+ </value>
+ </item>
+ <item>
+ <key> <string>title</string> </key>
+ <value>
+ <persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
+ </value>
+ </item>
+ </dictionary>
+ </value>
+ </item>
+ <item>
+ <key> <string>content_icon</string> </key>
+ <value>
+ <none/>
+ </value>
+ </item>
+ <item>
+ <key> <string>description</string> </key>
+ <value>
+ <none/>
+ </value>
+ </item>
+ <item>
+ <key> <string>id</string> </key>
+ <value> <string>Duplicate Inventory Constraint</string> </value>
+ </item>
+ <item>
+ <key> <string>init_script</string> </key>
+ <value>
+ <none/>
+ </value>
+ </item>
+ <item>
+ <key> <string>permission</string> </key>
+ <value>
+ <none/>
+ </value>
+ </item>
+ <item>
+ <key> <string>portal_type</string> </key>
+ <value> <string>Base Type</string> </value>
+ </item>
+ <item>
+ <key> <string>type_class</string> </key>
+ <value> <string>DuplicateInventoryConstraint</string> </value>
+ </item>
+ <item>
+ <key> <string>type_interface</string> </key>
+ <value>
+ <tuple/>
+ </value>
+ </item>
+ <item>
+ <key> <string>type_mixin</string> </key>
+ <value>
+ <tuple/>
+ </value>
+ </item>
+ </dictionary>
+ </pickle>
+ </record>
+ <record id="2" aka="AAAAAAAAAAI=">
+ <pickle>
+ <global name="TranslationInformation" module="Products.ERP5Type.TranslationProviderBase"/>
+ </pickle>
+ <pickle>
+ <dictionary>
+ <item>
+ <key> <string>domain_name</string> </key>
+ <value> <string>erp5_content</string> </value>
+ </item>
+ <item>
+ <key> <string>property_name</string> </key>
+ <value> <string>short_title</string> </value>
+ </item>
+ </dictionary>
+ </pickle>
+ </record>
+ <record id="3" aka="AAAAAAAAAAM=">
+ <pickle>
+ <global name="TranslationInformation" module="Products.ERP5Type.TranslationProviderBase"/>
+ </pickle>
+ <pickle>
+ <dictionary>
+ <item>
+ <key> <string>domain_name</string> </key>
+ <value> <string>erp5_content</string> </value>
+ </item>
+ <item>
+ <key> <string>property_name</string> </key>
+ <value> <string>title</string> </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=43548&r1=43547&r2=43548&view=diff
==============================================================================
--- erp5/trunk/bt5/erp5_trade/bt/revision [utf8] (original)
+++ erp5/trunk/bt5/erp5_trade/bt/revision [utf8] Tue Feb 22 11:37:46 2011
@@ -1 +1 @@
-1103
\ No newline at end of file
+1104
\ No newline at end of file
Modified: erp5/trunk/bt5/erp5_trade/bt/template_action_path_list
URL: http://svn.erp5.org/erp5/trunk/bt5/erp5_trade/bt/template_action_path_list?rev=43548&r1=43547&r2=43548&view=diff
==============================================================================
--- erp5/trunk/bt5/erp5_trade/bt/template_action_path_list [utf8] (original)
+++ erp5/trunk/bt5/erp5_trade/bt/template_action_path_list [utf8] Tue Feb 22 11:37:46 2011
@@ -9,6 +9,7 @@ Container | view
Delivery Cell | view
Delivery Root Simulation Rule | view
Delivery Simulation Rule | view
+Duplicate Inventory Constraint | view
First Causality Movement Group | view
Internal Order Cell | view
Internal Order Line | price_view
Removed: erp5/trunk/bt5/erp5_trade/bt/template_constraint_id_list
URL: http://svn.erp5.org/erp5/trunk/bt5/erp5_trade/bt/template_constraint_id_list?rev=43547&view=auto
==============================================================================
--- erp5/trunk/bt5/erp5_trade/bt/template_constraint_id_list [utf8] (original)
+++ erp5/trunk/bt5/erp5_trade/bt/template_constraint_id_list (removed)
@@ -1 +0,0 @@
-DuplicateInventory
\ No newline at end of file
Added: erp5/trunk/bt5/erp5_trade/bt/template_document_id_list
URL: http://svn.erp5.org/erp5/trunk/bt5/erp5_trade/bt/template_document_id_list?rev=43548&view=auto
==============================================================================
--- erp5/trunk/bt5/erp5_trade/bt/template_document_id_list (added)
+++ erp5/trunk/bt5/erp5_trade/bt/template_document_id_list [utf8] Tue Feb 22 11:37:46 2011
@@ -0,0 +1 @@
+DuplicateInventoryConstraint
\ No newline at end of file
Modified: erp5/trunk/bt5/erp5_trade/bt/template_portal_type_id_list
URL: http://svn.erp5.org/erp5/trunk/bt5/erp5_trade/bt/template_portal_type_id_list?rev=43548&r1=43547&r2=43548&view=diff
==============================================================================
--- erp5/trunk/bt5/erp5_trade/bt/template_portal_type_id_list [utf8] (original)
+++ erp5/trunk/bt5/erp5_trade/bt/template_portal_type_id_list [utf8] Tue Feb 22 11:37:46 2011
@@ -7,6 +7,7 @@ Container Line
Delivery Cell
Delivery Root Simulation Rule
Delivery Simulation Rule
+Duplicate Inventory Constraint
First Causality Movement Group
Internal Order
Internal Order Cell
More information about the Erp5-report
mailing list