diff --git a/product/ERP5/Document/SupplyLine.py b/product/ERP5/Document/SupplyLine.py index 131a08d4bc2c731d8b9960e7a1c797dd32a5479c..fc74c94db2404286038f8d0b5ae4f9b73aa94c88 100755 --- a/product/ERP5/Document/SupplyLine.py +++ b/product/ERP5/Document/SupplyLine.py @@ -1,7 +1,8 @@ ############################################################################## # -# Copyright (c) 2002 Nexedi SARL and Contributors. All Rights Reserved. +# Copyright (c) 2002, 2005 Nexedi SARL and Contributors. All Rights Reserved. # Jean-Paul Smets-Solanes <jp@nexedi.com> +# Romain Courteaud <romain@nexedi.com> # # WARNING: This program as such is intended to be used by professional # programmers who take the whole responsability of assessing all potential @@ -27,68 +28,16 @@ ############################################################################## import ExtensionClass - from Globals import InitializeClass, PersistentMapping from AccessControl import ClassSecurityInfo - from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface from Products.ERP5Type.XMLMatrix import XMLMatrix - from Products.ERP5.Document.DeliveryLine import DeliveryLine from Products.ERP5.Document.Movement import Movement from Products.ERP5.Document.Path import Path from zLOG import LOG -class SupplyLineMixin(ExtensionClass.Base): - - security = ClassSecurityInfo() - - # Cell Related -# security.declareProtected( Permissions.ModifyPortalContent, 'newCellContent' ) -# def newCellContent(self, id): -# """ -# This method can be overriden -# """ -# self.invokeFactory(type_name="Supply Cell",id=id) -# return self.get(id) - - security.declareProtected( Permissions.ModifyPortalContent, 'hasCellContent' ) - def hasCellContent(self, base_id='path'): - """ - This method can be overriden - """ - return XMLMatrix.hasCellContent(self, base_id=base_id) - # If we need it faster, we can use another approach... - return len(self.contentValues()) > 0 - - security.declareProtected( Permissions.AccessContentsInformation, 'getCellValueList' ) - def getCellValueList(self, base_id='path'): - """ - This method can be overriden - """ - return XMLMatrix.getCellValueList(self, base_id=base_id) - - security.declareProtected( Permissions.View, 'getCell' ) - def getCell(self, *kw , **kwd): - """ - This method can be overriden - """ - if 'base_id' not in kwd: - kwd['base_id'] = 'path' - - return XMLMatrix.getCell(self, *kw, **kwd) - - security.declareProtected( Permissions.ModifyPortalContent, 'newCell' ) - def newCell(self, *kw, **kwd): - """ - This method creates a new cell - """ - if 'base_id' not in kwd: - kwd['base_id'] = 'path' - - return XMLMatrix.newCell(self, *kw, **kwd) - class SupplyLine(DeliveryLine, Path): """ A DeliveryLine object allows to implement lines in @@ -128,8 +77,11 @@ class SupplyLine(DeliveryLine, Path): , PropertySheet.Predicate ) + ############################################# # Pricing methods - security.declareProtected(Permissions.AccessContentsInformation, 'getPrice') + ############################################# + security.declareProtected(Permissions.AccessContentsInformation, + 'getPrice') def getPrice(self): # If price not defined, look up price if getattr(self, 'price', None) is None: @@ -137,7 +89,8 @@ class SupplyLine(DeliveryLine, Path): # Return the price return self.price - security.declareProtected(Permissions.AccessContentsInformation, 'getTotalPrice') + security.declareProtected(Permissions.AccessContentsInformation, + 'getTotalPrice') def getTotalPrice(self): """ Returns the totals price for this line @@ -158,71 +111,99 @@ class SupplyLine(DeliveryLine, Path): def _getDefaultTotalPrice(self, context): return 0.0 - security.declareProtected(Permissions.AccessContentsInformation, 'isAccountable') + security.declareProtected(Permissions.AccessContentsInformation, + 'isAccountable') def isAccountable(self): """ Returns 1 if this needs to be accounted """ return 0 -# security.declareProtected(Permissions.AccessContentsInformation, 'getPrice') -# def getPrice(self, context=None, REQUEST=None, **kw): -# """ -# """ -# return self._getPrice(self.asContext(context=context, REQUEST=REQUEST, **kw)) - - security.declareProtected(Permissions.AccessContentsInformation, 'getDefaultPrice') + security.declareProtected(Permissions.AccessContentsInformation, + 'getDefaultPrice') def getDefaultPrice(self, context=None, REQUEST=None, **kw): """ """ - return self._getDefaultPrice(self.asContext(context=context, REQUEST=REQUEST, **kw)) + return self._getDefaultPrice(self.asContext(context=context, + REQUEST=REQUEST, **kw)) -# security.declareProtected(Permissions.AccessContentsInformation, 'getTotalPrice') -# def getTotalPrice(self, context=None, REQUEST=None, **kw): -# """ -# """ -# return self._getTotalPrice(self.asContext(context=context, REQUEST=REQUEST, **kw)) - - security.declareProtected(Permissions.AccessContentsInformation, 'getDefaultTotalPrice') + security.declareProtected(Permissions.AccessContentsInformation, + 'getDefaultTotalPrice') def getDefaultTotalPrice(self, context=None, REQUEST=None, **kw): """ """ - return self._getDefaultTotalPrice(self.asContext(context=context, REQUEST=REQUEST, **kw)) + return self._getDefaultTotalPrice(self.asContext(context=context, + REQUEST=REQUEST, **kw)) - security.declareProtected( Permissions.ModifyPortalContent, 'hasCellContent' ) + ############################################# + # Predicate method + ############################################# + asPredicate = Path.asPredicate + + ############################################# + # XMLMatrix methods + # XXX to be removed if possible + ############################################# + security.declareProtected(Permissions.ModifyPortalContent, 'hasCellContent') def hasCellContent(self, base_id='path'): """ This method can be overriden """ - return int(XMLMatrix.getCellRange(self, base_id=base_id) != []) + return XMLMatrix.hasCellContent(self, base_id=base_id) - asPredicate = Path.asPredicate + security.declareProtected(Permissions.AccessContentsInformation, + 'getCellValueList' ) + def getCellValueList(self, base_id='path'): + """ + This method can be overriden + """ + return XMLMatrix.getCellValueList(self, base_id=base_id) + + security.declareProtected(Permissions.View, 'getCell') + def getCell(self, *kw , **kwd): + """ + This method can be overriden + """ + if 'base_id' not in kwd: + kwd['base_id'] = 'path' + return XMLMatrix.getCell(self, *kw, **kwd) + + security.declareProtected(Permissions.ModifyPortalContent, 'newCell') + def newCell(self, *kw, **kwd): + """ + This method creates a new cell + """ + if 'base_id' not in kwd: + kwd['base_id'] = 'path' + return XMLMatrix.newCell(self, *kw, **kwd) # For generation of matrix lines - security.declareProtected( Permissions.ModifyPortalContent, '_setQuantityStepList' ) + security.declareProtected(Permissions.ModifyPortalContent, + '_setQuantityStepList' ) def _setQuantityStepList(self, value): self._baseSetQuantityStepList(value) value = self.getQuantityStepList() value.sort() - + # XXX Hardcoded portal type name for pid in self.contentIds(filter={'portal_type': 'Predicate Group'}): self.deleteContent(pid) if len(value) > 0: #value = value value = [None] + value + [None] - - # With this script, we canc change customize the title of the predicate - script = getattr(self,'SupplyLine_getTitle',None) - + # With this script, we can change customize the title of the + # predicate + script = getattr(self, 'SupplyLine_getTitle', None) for i in range(0, len(value) -1 ): min = value[i] max = value[i+1] - p = self.newContent(id = 'quantity_range_%s' % str(i), portal_type = 'Predicate Group') + # XXX Hardcoded portal type name + p = self.newContent(id='quantity_range_%s' % str(i), + portal_type = 'Predicate Group') p.setCriterionPropertyList(('quantity', )) p.setCriterion('quantity', min=min, max=max) if script is not None: - title = script(min=min,max=max) + title = script(min=min, max=max) p.setTitle(title) else: if min is None: @@ -230,9 +211,5 @@ class SupplyLine(DeliveryLine, Path): elif max is None: p.setTitle('%s <= quantity' % repr(min)) else: - p.setTitle('%s <= quantity < %s' % (repr(min),repr(max))) - + p.setTitle('%s <= quantity < %s' % (repr(min), repr(max))) self.updateCellRange(base_id='path') - -from Products.ERP5Type.Utils import monkeyPatch -monkeyPatch(SupplyLineMixin,SupplyLine)