DeliveryCell.py 7.37 KB
Newer Older
1
# -*- coding: utf-8 -*-
Jean-Paul Smets's avatar
Jean-Paul Smets committed
2 3
##############################################################################
#
4
# Copyright (c) 2002, 2004 Nexedi SARL and Contributors. All Rights Reserved.
5
#                    Jean-Paul Smets-Solanes <jp@nexedi.com>
6
#                    Romain Courteaud <romain@nexedi.com>
Jean-Paul Smets's avatar
Jean-Paul Smets committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
#
# 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.
#
##############################################################################

31 32
import zope.interface

33
from Products.ERP5Type.Globals import InitializeClass, PersistentMapping
Jean-Paul Smets's avatar
Jean-Paul Smets committed
34 35 36
from AccessControl import ClassSecurityInfo
from Acquisition import aq_base

37
from Products.ERP5Type import Permissions, PropertySheet, Constraint, interfaces
Sebastien Robin's avatar
Sebastien Robin committed
38
from Products.ERP5Type.Base import Base
Jean-Paul Smets's avatar
Jean-Paul Smets committed
39 40 41

from Products.ERP5.Document.OrderLine import OrderLine
from Products.ERP5.Document.Movement import Movement
42
from Products.ERP5.Document.MappedValue import MappedValue
43
from Products.ERP5.Document.ImmobilisationMovement import ImmobilisationMovement
Jean-Paul Smets's avatar
Jean-Paul Smets committed
44 45 46

from zLOG import LOG

47
class DeliveryCell(MappedValue, Movement, ImmobilisationMovement):
Jean-Paul Smets's avatar
Jean-Paul Smets committed
48 49 50 51 52 53 54 55 56 57 58
    """
      A DeliveryCell allows to define specific quantities
      for each variation of a resource in a delivery line.
    """

    meta_type = 'ERP5 Delivery Cell'
    portal_type = 'Delivery Cell'
    isCell = 1

    # Declarative security
    security = ClassSecurityInfo()
59
    security.declareObjectProtected(Permissions.AccessContentsInformation)
Jean-Paul Smets's avatar
Jean-Paul Smets committed
60 61 62 63 64 65 66 67 68 69 70 71 72 73

    # Declarative properties
    property_sheets = ( PropertySheet.Base
                      , PropertySheet.CategoryCore
                      , PropertySheet.Arrow
                      , PropertySheet.Amount
                      , PropertySheet.Task
                      , PropertySheet.Movement
                      , PropertySheet.Price
                      , PropertySheet.Predicate
                      , PropertySheet.MappedValue
                      , PropertySheet.ItemAggregation
                      )

74 75
    # Declarative interfaces
    zope.interface.implements(interfaces.IDivergenceController,)
76 77
    
    # MatrixBox methods      
78 79
    security.declareProtected( Permissions.AccessContentsInformation,
                               'hasCellContent' )
Jean-Paul Smets's avatar
Jean-Paul Smets committed
80
    def hasCellContent(self, base_id='movement'):
81
      """A cell cannot have cell content itself.
Jean-Paul Smets's avatar
Jean-Paul Smets committed
82 83 84 85 86 87 88 89 90 91
      """
      return 0

    security.declareProtected(Permissions.AccessContentsInformation, 'isAccountable')
    def isAccountable(self):
      """
        Returns 1 if this needs to be accounted
        Only account movements which are not associated to a delivery
        Whenever delivery is there, delivery has priority
      """
92
      return self.getParentValue().getParentValue().isAccountable()
Jean-Paul Smets's avatar
Jean-Paul Smets committed
93

94
    security.declareProtected(Permissions.AccessContentsInformation, 'getPrice')
95
    def getPrice(self, *args, **kw):
Jean-Paul Smets's avatar
Jean-Paul Smets committed
96
      """
97
      call Movement.getPrice
98
      """
99 100 101
      return Movement.getPrice(self, *args, **kw)

    security.declareProtected(Permissions.AccessContentsInformation, 'getTotalPrice')
102
    def getTotalPrice(self, default=0.0, *args, **kw):
103 104 105
      """
      call Movement.getTotalPrice
      """
106
      return Movement.getTotalPrice(self, default=default, *args, **kw)
107

108 109
    security.declareProtected(Permissions.AccessContentsInformation,
                              'getRootDeliveryValue')
Sebastien Robin's avatar
Sebastien Robin committed
110 111 112 113
    def getRootDeliveryValue(self):
      """
      Returns the root delivery responsible of this cell
      """
114
      return self.getParentValue().getRootDeliveryValue()
Sebastien Robin's avatar
Sebastien Robin committed
115

Jean-Paul Smets's avatar
Jean-Paul Smets committed
116
    # Simulation Consistency Check
117
    def getSimulationQuantity(self):
Jean-Paul Smets's avatar
Jean-Paul Smets committed
118 119 120 121 122 123 124 125 126 127 128
      """
          Computes the quantities in the simulation
      """
      if isinstance(self, OrderLine):
        result = self.OrderLine_zGetRelatedQuantity(uid=self.getUid())
        if len(result) > 0:
          return result[0].quantity
        return None
      else:
        result = self.DeliveryLine_zGetRelatedQuantity(uid=self.getUid())
        if len(result) > 0:
129
          return result[0].quantity
Jean-Paul Smets's avatar
Jean-Paul Smets committed
130
        return None
131

132 133 134 135
    security.declareProtected( Permissions.ModifyPortalContent,
                               'notifyAfterUpdateRelatedContent' )
    def notifyAfterUpdateRelatedContent(self, previous_category_url,
                                              new_category_url):
136
      """
137 138
        Membership Crirerions and Category List are same in DeliveryCell
        Must update it (or change implementation to remove data duplication)
139 140 141
      """
      update_method = self.portal_categories.updateRelatedCategory
      predicate_value = self.getPredicateValueList()
142 143 144 145
      new_predicate_value = map(lambda c: update_method(c,
              previous_category_url, new_category_url), predicate_value)
      self._setPredicateValueList(new_predicate_value)
      # No reindex needed since uid stable
Sebastien Robin's avatar
Sebastien Robin committed
146

Romain Courteaud's avatar
Romain Courteaud committed
147 148 149 150 151 152
    # XXX FIXME: option variation are today not well implemented
    # This little hack is needed to make the matrixbox working
    # in DeliveryLine_viewIndustrialPhase
    # Generic form (DeliveryLine_viewOption) is required
    security.declarePrivate('_edit')
    def _edit(self, REQUEST=None, force_update=0, reindex_object=0, **kw):
Sebastien Robin's avatar
Sebastien Robin committed
153
      """
Romain Courteaud's avatar
Romain Courteaud committed
154 155
        Store variation_category_list, in order to store new value of
        industrial_phase after.
Sebastien Robin's avatar
Sebastien Robin committed
156
      """
Romain Courteaud's avatar
Romain Courteaud committed
157 158 159 160 161
      if kw.has_key('variation_category_list'):
        self._setVariationCategoryList(kw['variation_category_list'])
        kw.pop('variation_category_list')
      MappedValue._edit(self, REQUEST=REQUEST, force_update=force_update,
                        reindex_object=reindex_object, **kw)
162 163
#       if self.isSimulated():
#         self.getRootDeliveryValue().activate().propagateResourceToSimulation()
Sebastien Robin's avatar
Sebastien Robin committed
164 165
      # This one must be the last
      if kw.has_key('item_id_list'):
Romain Courteaud's avatar
Romain Courteaud committed
166
        self._setItemIdList(kw['item_id_list'])
Sebastien Robin's avatar
Sebastien Robin committed
167

168 169
    security.declareProtected(Permissions.ModifyPortalContent,
                              'updateSimulationDeliveryProperties')
170 171
    def updateSimulationDeliveryProperties(self, movement_list = None):
      """
172 173 174
      Set properties delivery_ratio and delivery_error for each
      simulation movement in movement_list (all movements by default),
      according to this delivery calculated quantity
175
      """
176
      parent = self.getParentValue()
177
      if parent is not None:
178
        parent = parent.getParentValue()
179 180
        if parent is not None:
          parent.updateSimulationDeliveryProperties(movement_list, self)
181 182 183 184 185

    security.declareProtected(Permissions.AccessContentsInformation, 'isMovement')
    def isMovement(self):
      return 1