State.py 4.1 KB
Newer Older
1 2 3 4
##############################################################################
#
# Copyright (c) 2006 Nexedi SARL and Contributors. All Rights Reserved.
#                    Romain Courteaud <romain@nexedi.com>
5
#               2015 Wenjie ZHENG <wenjie.zheng@tiolive.com>
6 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.
#
##############################################################################

from AccessControl import ClassSecurityInfo
30 31
from Acquisition import aq_inner, aq_parent
from Persistence import PersistentMapping
32
from Products.ERP5Type import Permissions, PropertySheet
33 34
from Products.ERP5Type.id_as_reference import IdAsReferenceMixin
from Products.ERP5Type.XMLMatrix import XMLMatrix
35 36 37
from Products.ERP5Type.XMLObject import XMLObject
from zLOG import LOG, ERROR, DEBUG, WARNING

38
class StateError(Exception):
39 40 41 42 43
  """
  Must call only an available transition
  """
  pass

44
class State(IdAsReferenceMixin("state_", "prefix"), XMLObject, XMLMatrix):
45 46 47 48 49 50 51 52
  """
  A ERP5 State.
  """
  meta_type = 'ERP5 State'
  portal_type = 'State'
  add_permission = Permissions.AddPortalContent
  isPortalContent = 1
  isRADContent = 1
53 54 55
  erp5_permission_roles = {} # { permission: [role] or (role,) }
  default_reference = ''
  type_list = ()
56 57 58
  # Declarative security
  security = ClassSecurityInfo()
  security.declareObjectProtected(Permissions.AccessContentsInformation)
59
  var_values = None
60 61 62 63 64 65
  # Declarative properties
  property_sheets = (
             PropertySheet.Base,
             PropertySheet.XMLObject,
             PropertySheet.CategoryCore,
             PropertySheet.DublinCore,
66
             PropertySheet.Reference,
67 68
             PropertySheet.State,)

69 70 71 72 73 74 75
  def addPossibleTransition(self, tr_ref):
    possible_transition_list = self.getCategoryList()
    transition = self.getParent()._getOb('transition_'+tr_ref, None)
    if transition is not None:
      tr_path = 'destination/' + '/'.join(transition.getPath().split('/')[2:])
      possible_transition_list.append(tr_path)
      self.setCategoryList(possible_transition_list)
76

77 78 79
  def getTransitions(self):
    # return possible transition id list:
    return self.getDestinationIdList()
80

81 82 83 84 85 86 87 88 89 90
  def setPermission(self, permission, acquired, roles, REQUEST=None):
      """Set a permission for this State."""
      permission_role = self.erp5_permission_roles
      if permission_role is None:
          self.erp5_permission_roles = permission_role = PersistentMapping()
      if acquired:
          roles = list(roles)
      else:
          roles = tuple(roles)
      permission_role[permission] = roles
91

92 93
  def getPermissionRoleList(self):
    return self.erp5_permission_roles
94

95 96 97 98 99 100 101 102
  def getDestinationReferenceList(self):
    ref_list = []
    for tr in self.getDestinationValueList():
      ref_list.append(tr.getReference())
    return ref_list

  def getAvailableTypeList(self):
    """This is a method specific to ERP5. This returns a list of state types, which are used for portal methods.
103
    """
104 105 106 107 108 109 110 111
    return (
            'draft_order',
            'planned_order',
            'future_inventory',
            'reserved_inventory',
            'transit_inventory',
            'current_inventory',
            )