document.erp5.DummyMovement.py 3.67 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
#
# 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.
#
##############################################################################
30

31
from AccessControl import ClassSecurityInfo
32
from Products.ERP5Type import Permissions, PropertySheet, interfaces
33
from erp5.component.document.Movement import Movement
34

35

36 37
class DummyMovement(Movement):
  """Dummy Movement for testing purposes."""
38 39
  meta_type = 'ERP5 Dummy Movement'
  portal_type = 'Dummy Movement'
40 41 42 43 44 45 46 47 48 49 50 51 52 53
  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
54
                    , PropertySheet.ItemAggregation
55 56
                    )

57
  def isAccountable(self):
58 59
    """Our dummy movements are always accountable, unless is_accountable
    attribute is set."""
60 61
    return getattr(self, 'is_accountable', 1)

62 63 64 65 66
  def isMovingItem(self, item):
    """Our dummy movements are always moving items, unless is_moving_item
    attribute is set."""
    return getattr(self, 'is_moving_item', 1)

67 68
  # In order to make tests work with dummy movements that are not contained in
  # dummy deliveries, we must borrow a few methods from DummyDelivery.
69

70
  def getSimulationState(self):
71
    from erp5.component.document.DummyDelivery import DummyDelivery
72 73 74
    parent = self.getParentValue()
    if isinstance(parent, DummyDelivery):
      self = parent
75
    return DummyDelivery.getSimulationState(self)
76

77
  def getDeliveryValue(self):
78 79 80 81 82 83
    """
    Deprecated, we should use getRootDeliveryValue instead
    """
    return self.getRootDeliveryValue()

  def getRootDeliveryValue(self):
84 85
    """In the tests, dummy movements are not always stored in a delivery, here
    we try to support both cases.
86
    """
87 88 89 90 91 92
    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
93 94
    return self

95 96
  def hasCellContent(self):
    return False