ProductionOrderRule.py 4.33 KB
Newer Older
Romain Courteaud's avatar
Romain Courteaud committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
##############################################################################
#
# Copyright (c) 2005 Nexedi SARL and Contributors. All Rights Reserved.
#                    Romain Courteaud <romain@nexedi.com>
#
# 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 AccessControl import ClassSecurityInfo
30
from Products.ERP5Type import Permissions, PropertySheet, Constraint, interfaces
Romain Courteaud's avatar
Romain Courteaud committed
31 32
from Products.ERP5.Document.Rule import Rule
from Products.ERP5.Document.OrderRule import OrderRule
33
from Products.ERP5.Document.TransformationRule import TransformationRuleMixin
Romain Courteaud's avatar
Romain Courteaud committed
34

35
from zLOG import LOG, WARNING
Romain Courteaud's avatar
Romain Courteaud committed
36 37 38 39 40 41 42 43 44 45 46 47 48

class ProductionOrderRule(OrderRule):
    """
      Prouction Order Rule object use a Supply Chain to expand a 
      Production Order.
    """

    # CMF Type Definition
    meta_type = 'ERP5 Production Order Rule'
    portal_type = 'Production Order Rule'

    # Declarative security
    security = ClassSecurityInfo()
49
    security.declareObjectProtected(Permissions.AccessContentsInformation)
Romain Courteaud's avatar
Romain Courteaud committed
50

51 52
    __implements = ( interfaces.IPredicate,
                     interfaces.IRule )
Jérome Perrin's avatar
Jérome Perrin committed
53

Romain Courteaud's avatar
Romain Courteaud committed
54 55 56 57 58
    # Default Properties
    property_sheets = ( PropertySheet.Base
                      , PropertySheet.XMLObject
                      , PropertySheet.CategoryCore
                      , PropertySheet.DublinCore
59
                      , PropertySheet.Task
60
                      , PropertySheet.AppliedRule
Romain Courteaud's avatar
Romain Courteaud committed
61 62 63
                      )

    # Simulation workflow
64 65
    security.declareProtected(Permissions.AccessContentsInformation,
                              '_getExpandablePropertyDict')
66
    def _getExpandablePropertyDict(self, applied_rule, movement, **kw):
Romain Courteaud's avatar
Romain Courteaud committed
67
      """
68 69
      Return a Dictionary with the Properties used to edit 
      the simulation movement.
Romain Courteaud's avatar
Romain Courteaud committed
70
      """
71 72
      property_dict = {}

73 74 75 76 77 78 79
      default_property_list = self.getExpandablePropertyList()
      # For backward compatibility, we keep for some time the list
      # of hardcoded properties. Theses properties should now be
      # defined on the rule itself
      if len(default_property_list) == 0:
        LOG("Order Rule , _getExpandablePropertyDict", WARNING,
                   "Hardcoded properties set, please define your rule correctly")
80
        default_property_list = (
81
          'destination', 
82
          'destination_section',
83 84 85
          'start_date', 
          'stop_date',
          'resource', 
86
          'variation_category_list',
87
          'variation_property_dict', 
88
          'aggregate_list',
89 90 91 92 93
          'price', 
          'price_currency',
          'quantity', 
          'quantity_unit', 
        )
94
    
95 96 97 98 99 100 101 102 103 104
      root_explanation = self.getRootExplanation(
          self.getBusinessProcess(applied_rule=applied_rule))
      property_dict['source_section'] = root_explanation.getSourceSection()
      source_method_id = root_explanation.getSourceMethodId()
      if source_method_id is None:
        property_dict['source'] = root_explanation.getSource()
      else:
        property_dict['source'] = getattr(root_explanation, source_method_id)()
      property_dict['causality'] = root_explanation.getRelativeUrl()

105 106 107 108
      for prop in default_property_list:
        property_dict[prop] = movement.getProperty(prop)
    
      return property_dict
Romain Courteaud's avatar
Romain Courteaud committed
109 110

from Products.ERP5Type.Utils import monkeyPatch
111
monkeyPatch(TransformationRuleMixin, ProductionOrderRule)