DummyMovement.py 4.08 KB
Newer Older
1
# -*- coding: utf-8 -*-
2 3
##############################################################################
#
4
# Copyright (c) 2006 Nexedi SA and Contributors. All Rights Reserved.
5
#                    Jerome Perrin <jerome@nexedi.com>
6
#                    Łukasz Nowak <luke@nexedi.com>
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.
#
##############################################################################
from AccessControl import ClassSecurityInfo
31
from Products.ERP5Type import Permissions, PropertySheet, interfaces
32 33 34 35 36

from Products.ERP5.Document.Movement import Movement

class DummyMovement(Movement):
  """Dummy Movement for testing purposes."""
37 38
  meta_type = 'ERP5 Dummy Movement'
  portal_type = 'Dummy Movement'
39 40 41 42 43 44 45 46 47 48 49 50 51 52
  add_permission = Permissions.AddPortalContent

  # Declarative security
  security = ClassSecurityInfo()
  security.declareObjectProtected(Permissions.AccessContentsInformation)

  # Declarative properties
  property_sheets = ( PropertySheet.Base
                    , PropertySheet.SimpleItem
                    , PropertySheet.Amount
                    , PropertySheet.Task
                    , PropertySheet.Arrow
                    , PropertySheet.Movement
                    , PropertySheet.Price
53
                    , PropertySheet.ItemAggregation
54 55
                    )

56 57 58 59
  def isAccountable(self):
    """Our dummy movement are always accountable."""
    return getattr(self, 'is_accountable', 1)

60 61 62 63 64 65
  def _getPropertyDirectlyOrFromDummyDelivery(self, property, default=None):
    """Returns property from delivery, in case if in Dummy Delivery, or movement"""
    if self.getParentValue().getPortalType() == 'Dummy Delivery':
      return self.getParentValue().getSimulationState()
    return getattr(self, property, default)

66
  def getSimulationState(self):
67 68 69
    return self._getPropertyDirectlyOrFromDummyDelivery(
        'simulation_state', 'draft')

70
  def setSimulationState(self, state):
71 72 73 74 75
    """Directly sets a simulation state if not in Dummy Delivery."""
    if self.getParentValue().getPortalType() != 'Dummy Delivery':
      self.simulation_state = state
    else:
      raise ValueError
76

77
  def getCausalityState(self):
78 79 80
    return self._getPropertyDirectlyOrFromDummyDelivery(
        'causality_state', 'draft')

81 82
  def setCausalityState(self, state):
    """Directly sets a causality state."""
83 84 85 86 87
    if self.getParentValue().getPortalType() != 'Dummy Delivery':
      self.simulation_state = state
    else:
      raise ValueError

88
  def getDeliveryValue(self):
89 90 91 92 93 94
    """
    Deprecated, we should use getRootDeliveryValue instead
    """
    return self.getRootDeliveryValue()

  def getRootDeliveryValue(self):
95 96
    """In the tests, dummy movements are not always stored in a delivery, here
    we try to support both cases.
97
    """
98 99 100 101 102 103
    parent = self.getParentValue()
    if hasattr(parent, 'getDeliveryValue'):
      # we are in a delivery, make getDeliveryValue and therefore
      # getExplanation value work like on real movements.
      return parent.getDeliveryValue()
    # return self, to have minimum support of getDeliveryValue
104 105
    return self

106

107 108
  def hasCellContent(self):
    return False