ProductionOrderRule.py 4.44 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 34
from Products.ERP5.Document.TransformationSourcingRule import\
                                            TransformationSourcingRuleMixin
Romain Courteaud's avatar
Romain Courteaud committed
35

36
from zLOG import LOG, WARNING
Romain Courteaud's avatar
Romain Courteaud committed
37

38
class ProductionOrderRule(OrderRule):
Romain Courteaud's avatar
Romain Courteaud committed
39 40 41 42 43 44 45 46 47 48 49
    """
      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()
50
    security.declareObjectProtected(Permissions.AccessContentsInformation)
Romain Courteaud's avatar
Romain Courteaud committed
51

52 53 54
    __implements = ( interfaces.IPredicate,
                     interfaces.IRule )

Romain Courteaud's avatar
Romain Courteaud committed
55
    # Simulation workflow
56 57
    security.declareProtected(Permissions.AccessContentsInformation,
                              '_getExpandablePropertyDict')
58 59
    def _getExpandablePropertyDict(self, applied_rule, movement, business_path=None,
                                   **kw):
Romain Courteaud's avatar
Romain Courteaud committed
60
      """
61 62
      Return a Dictionary with the Properties used to edit 
      the simulation movement.
Romain Courteaud's avatar
Romain Courteaud committed
63
      """
64 65
      property_dict = {}

66 67 68 69 70 71 72
      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")
73
        default_property_list = (
74
          'destination', 
75
          'destination_section',
76 77 78
          'start_date', 
          'stop_date',
          'resource', 
79
          'variation_category_list',
80
          'variation_property_dict', 
81
          'aggregate_list',
82 83 84 85 86
          'price', 
          'price_currency',
          'quantity', 
          'quantity_unit', 
        )
87
    
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
      supply_chain = self.getSupplyChain(applied_rule)
      # We got a supply chain
      # Try to get the last SupplyLink
      last_link = supply_chain.getLastLink()
      # We got a valid industrial_phase
      # Now, we have to generate Simulation Movement, in order to
      # create a ProductionPackingList.
      destination_node = last_link.getDestinationValue()
      source_value = destination_node.getDestination()
      source_section_value = last_link.getDestinationSection()
      if source_value is not None:
        property_dict["source"] = source_value
      if source_section_value is not None:
        property_dict["source_section"] = source_section_value
    
103 104 105
      for prop in default_property_list:
        property_dict[prop] = movement.getProperty(prop)
    
106 107 108 109
      # rule specific
      property_dict.update(**self._getExpandablePropertyUpdateDict(applied_rule,
        movement, business_path, property_dict))

110
      return property_dict
111 112 113

from Products.ERP5Type.Utils import monkeyPatch
monkeyPatch(TransformationSourcingRuleMixin, ProductionOrderRule)