Blame view

product/ERP5/Document/ImmobilisationDelivery.py 6.65 KB
Guillaume Michon 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
##############################################################################
#
# Copyright (c) 2002 Nexedi SARL and Contributors. All Rights Reserved.
#                    Guillaume Michon        <guillaume.michon@e-asc.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.
#
##############################################################################

29
from Products.ERP5Type.Globals import InitializeClass, PersistentMapping
Guillaume Michon committed
30 31 32 33 34
from AccessControl import ClassSecurityInfo

from DateTime import DateTime
from string import capitalize

Kazuhiko Shiozaki committed
35
from Products.ERP5Type import Permissions, PropertySheet, Constraint, interfaces
Guillaume Michon committed
36 37 38 39 40 41
from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5Type.DateUtils import addToDate, getClosestDate, getIntervalBetweenDates 
from Products.ERP5Type.DateUtils import getMonthAndDaysBetween, getRoundedMonthBetween
from Products.ERP5Type.DateUtils import getMonthFraction, getYearFraction, getBissextilCompliantYearFraction
from Products.ERP5Type.DateUtils import same_movement_interval, number_of_months_in_year, centis, millis
from Products.ERP5.Document.Amount import Amount
Jean-Paul Smets committed
42
from Products.ERP5Type.Base import WorkflowMethod
Guillaume Michon committed
43 44 45 46
from Products.CMFCore.utils import getToolByName
from Products.ERP5.Document.ImmobilisableItem import ImmobilisationValidityError


Romain Courteaud committed
47
from zLOG import LOG, WARNING
Guillaume Michon committed
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79


NEGLIGEABLE_PRICE = 10e-8

class ImmobilisationDelivery(XMLObject):
    """
      An Immobilisation Delivery is an object whose role is to
      contain delivery movements which can immobilise items.
    """

    meta_type = 'ERP5 Immobilisation Delivery'
    portal_type = 'Immobilisation Delivery'
    add_permission = Permissions.AddPortalContent
    isPortalContent = 1
    isRADContent = 1

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

    # Declarative properties
    property_sheets = ( PropertySheet.Base
                      , PropertySheet.XMLObject
                      , PropertySheet.CategoryCore
                      , PropertySheet.DublinCore
                      , PropertySheet.Task
                      , PropertySheet.Arrow
                      , PropertySheet.Movement
                      , PropertySheet.Delivery
                      , PropertySheet.Reference
                      )

Jérome Perrin committed
80
    security.declareProtected(Permissions.AccessContentsInformation, 'updateImmobilisationState')
Nicolas Delaby committed
81
    def updateImmobilisationState(self, **kw):
Guillaume Michon committed
82 83 84 85 86 87 88 89 90
      """
      This is often called as an activity, it will check if the
      delivery is valid as an immobilisation movement, and if so
      it will put the delivery in a valid state, if not valid in
      an invalid state
      """
      if self.getImmobilisationState() == 'calculating':
        try:
          if self.isValidImmobilisationMovement(**kw):
Nicolas Delaby committed
91
            self.validateImmobilisation()
Guillaume Michon committed
92
          else:
Nicolas Delaby committed
93
            self.invalidateImmobilisation()
Guillaume Michon committed
94
        except ImmobilisationValidityError:
Nicolas Delaby committed
95
          self.calculateImmobilisationValidity()
Guillaume Michon committed
96

Jérome Perrin committed
97
    security.declareProtected(Permissions.AccessContentsInformation, 'getImmobilisationMovementList')
Guillaume Michon committed
98 99 100 101 102 103 104 105
    def getImmobilisationMovementList(self, **kw):
      """
      Return regular movements + immobilisation movements like
      Immobilisation Line and Immobilisation Cell
      """
      return self.getMovementList(self.getPortalMovementTypeList() +
                 ('Immobilisation Line', 'Immobilisation Cell'), **kw)
      
Jérome Perrin committed
106
    security.declareProtected(Permissions.AccessContentsInformation, 'checkImmobilisationConsistency')
Guillaume Michon committed
107 108 109 110 111 112 113 114 115
    def checkImmobilisationConsistency(self, *args, **kw):
      """
      Check the consistency about immobilisation values
      """
      return_list = []
      for movement in self.getImmobilisationMovementList():
        return_list.extend(movement.checkImmobilisationConsistency())
      return return_list

Jérome Perrin committed
116
    security.declareProtected(Permissions.AccessContentsInformation, 'isValidImmobilisationMovement')
Guillaume Michon committed
117 118 119 120 121
    def isValidImmobilisationMovement(self, *args, **kw):
      """
      Return true if all submovements are valid in terms of immobilisation
      """
      error_list = self.checkImmobilisationConsistency(*args, **kw)
Jérome Perrin committed
122
      return len(error_list) == 0
Guillaume Michon committed
123

Jérome Perrin committed
124
    security.declareProtected(Permissions.AccessContentsInformation, 'isInvalidImmobilisationMovement')
Guillaume Michon committed
125 126 127 128 129 130
    def isInvalidImmobilisationMovement(self, *args, **kw):
      """
      Return false if all submovements are valid in terms of immobilisation
      """
      return not self.isValidImmobilisationMovement(*args, **kw)

Jérome Perrin committed
131 132
    security.declareProtected(Permissions.AccessContentsInformation,
                              'getAggregatedItemsNextImmobilisationMovementValueList')
Guillaume Michon committed
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
    def getAggregatedItemsNextImmobilisationMovementValueList(self, **kw):
      """
      Return the list of each next immobilisation movement for each aggregated item
      """
      returned_list = []
      sub_movement_list = self.contentValues()
      for movement in self.getImmobilisationMovementList(**kw):
        for item in movement.getAggregateValueList():
          future_movement_list = item.getFutureImmobilisationMovementValueList(
                                     at_date = self.getStopDate(),
                                     from_movement = self,
                                     filter_valid = 0)
          if future_movement_list is not None:
            for next_movement in future_movement_list:
              if next_movement is not None and \
                 next_movement not in sub_movement_list and \
                 next_movement not in returned_list and \
                 next_movement.getStopDate() != self.getStopDate():
                returned_list.append(next_movement)
      return returned_list