Commit 67b1f228 authored by Jérome Perrin's avatar Jérome Perrin

Do not override builtins min and max, minor style changes.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@8504 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 67348c3a
...@@ -27,25 +27,17 @@ ...@@ -27,25 +27,17 @@
# #
############################################################################## ##############################################################################
import ExtensionClass
from Globals import InitializeClass, PersistentMapping
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface
from Products.ERP5Type.XMLMatrix import XMLMatrix from Products.ERP5Type.XMLMatrix import XMLMatrix
from Products.ERP5.Document.DeliveryLine import DeliveryLine from Products.ERP5.Document.DeliveryLine import DeliveryLine
from Products.ERP5.Document.Movement import Movement
from Products.ERP5.Document.Path import Path from Products.ERP5.Document.Path import Path
from Products.ERP5Type.Utils import convertToUpperCase from Products.ERP5Type.Utils import convertToUpperCase
from zLOG import LOG from zLOG import LOG
class SupplyLine(DeliveryLine, Path): class SupplyLine(DeliveryLine, Path):
""" """A Supply Line is a path to define price
A DeliveryLine object allows to implement lines in
Deliveries (packing list, order, invoice, etc.)
It may include a price (for insurance, for customs, for invoices,
for orders)
""" """
meta_type = 'ERP5 Supply Line' meta_type = 'ERP5 Supply Line'
...@@ -54,14 +46,14 @@ class SupplyLine(DeliveryLine, Path): ...@@ -54,14 +46,14 @@ class SupplyLine(DeliveryLine, Path):
isPortalContent = 1 isPortalContent = 1
isRADContent = 1 isRADContent = 1
isPredicate = 1 isPredicate = 1
isAccountable = 0
# Declarative security # Declarative security
security = ClassSecurityInfo() security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation) security.declareObjectProtected(Permissions.AccessContentsInformation)
# Declarative interfaces # Declarative interfaces
__implements__ = ( Interface.Variated, ) __implements__ = ( Interface.Variated,
Interface.Predicate )
# Declarative properties # Declarative properties
property_sheets = ( PropertySheet.Base property_sheets = ( PropertySheet.Base
...@@ -82,7 +74,7 @@ class SupplyLine(DeliveryLine, Path): ...@@ -82,7 +74,7 @@ class SupplyLine(DeliveryLine, Path):
############################################# #############################################
# Pricing methods # Pricing methods
############################################# #############################################
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getPrice') 'getPrice')
def getPrice(self): def getPrice(self):
# If price not defined, look up price # If price not defined, look up price
...@@ -91,7 +83,7 @@ class SupplyLine(DeliveryLine, Path): ...@@ -91,7 +83,7 @@ class SupplyLine(DeliveryLine, Path):
# Return the price # Return the price
return self.price return self.price
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getTotalPrice') 'getTotalPrice')
def getTotalPrice(self): def getTotalPrice(self):
""" """
...@@ -113,28 +105,27 @@ class SupplyLine(DeliveryLine, Path): ...@@ -113,28 +105,27 @@ class SupplyLine(DeliveryLine, Path):
def _getDefaultTotalPrice(self, context): def _getDefaultTotalPrice(self, context):
return 0.0 return 0.0
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'isAccountable') 'isAccountable')
def isAccountable(self): def isAccountable(self):
""" """Supply Line are not accounted.
Returns 1 if this needs to be accounted
""" """
return 0 return 0
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getDefaultPrice') 'getDefaultPrice')
def getDefaultPrice(self, context=None, REQUEST=None, **kw): def getDefaultPrice(self, context=None, REQUEST=None, **kw):
""" """
""" """
return self._getDefaultPrice(self.asContext(context=context, return self._getDefaultPrice(self.asContext(context=context,
REQUEST=REQUEST, **kw)) REQUEST=REQUEST, **kw))
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getDefaultTotalPrice') 'getDefaultTotalPrice')
def getDefaultTotalPrice(self, context=None, REQUEST=None, **kw): def getDefaultTotalPrice(self, context=None, REQUEST=None, **kw):
""" """
""" """
return self._getDefaultTotalPrice(self.asContext(context=context, return self._getDefaultTotalPrice(self.asContext(context=context,
REQUEST=REQUEST, **kw)) REQUEST=REQUEST, **kw))
############################################# #############################################
...@@ -146,14 +137,15 @@ class SupplyLine(DeliveryLine, Path): ...@@ -146,14 +137,15 @@ class SupplyLine(DeliveryLine, Path):
# XMLMatrix methods # XMLMatrix methods
# XXX to be removed if possible # XXX to be removed if possible
############################################# #############################################
security.declareProtected(Permissions.ModifyPortalContent, 'hasCellContent') security.declareProtected(Permissions.AccessContentsInformation,
'hasCellContent')
def hasCellContent(self, base_id='path'): def hasCellContent(self, base_id='path'):
""" """
This method can be overriden This method can be overriden
""" """
return XMLMatrix.hasCellContent(self, base_id=base_id) return XMLMatrix.hasCellContent(self, base_id=base_id)
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getCellValueList' ) 'getCellValueList' )
def getCellValueList(self, base_id='path'): def getCellValueList(self, base_id='path'):
""" """
...@@ -161,7 +153,7 @@ class SupplyLine(DeliveryLine, Path): ...@@ -161,7 +153,7 @@ class SupplyLine(DeliveryLine, Path):
""" """
return XMLMatrix.getCellValueList(self, base_id=base_id) return XMLMatrix.getCellValueList(self, base_id=base_id)
security.declareProtected(Permissions.View, 'getCell') security.declareProtected(Permissions.AccessContentsInformation, 'getCell')
def getCell(self, *kw , **kwd): def getCell(self, *kw , **kwd):
""" """
This method can be overriden This method can be overriden
...@@ -182,7 +174,7 @@ class SupplyLine(DeliveryLine, Path): ...@@ -182,7 +174,7 @@ class SupplyLine(DeliveryLine, Path):
############################################################ ############################################################
# Quantity predicate API # Quantity predicate API
############################################################ ############################################################
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getQuantityPredicateIdList') 'getQuantityPredicateIdList')
def getQuantityPredicateIdList(self, price_parameter): def getQuantityPredicateIdList(self, price_parameter):
""" """
...@@ -199,7 +191,7 @@ class SupplyLine(DeliveryLine, Path): ...@@ -199,7 +191,7 @@ class SupplyLine(DeliveryLine, Path):
if x.startswith(predicate_id_start_with)] if x.startswith(predicate_id_start_with)]
return result return result
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getQuantityPredicateValueList') 'getQuantityPredicateValueList')
def getQuantityPredicateValueList(self, price_parameter): def getQuantityPredicateValueList(self, price_parameter):
""" """
...@@ -209,7 +201,8 @@ class SupplyLine(DeliveryLine, Path): ...@@ -209,7 +201,8 @@ class SupplyLine(DeliveryLine, Path):
self.getQuantityPredicateIdList(price_parameter)] self.getQuantityPredicateIdList(price_parameter)]
return result return result
security.declareProtected(Permissions.View, 'getQuantityStepList') security.declareProtected(Permissions.AccessContentsInformation,
'getQuantityStepList')
def getQuantityStepList(self, price_parameter="base_price"): def getQuantityStepList(self, price_parameter="base_price"):
""" """
Return predicate step related to a price_parameter Return predicate step related to a price_parameter
...@@ -221,42 +214,44 @@ class SupplyLine(DeliveryLine, Path): ...@@ -221,42 +214,44 @@ class SupplyLine(DeliveryLine, Path):
convertToUpperCase("%s_quantity_step" % price_parameter) convertToUpperCase("%s_quantity_step" % price_parameter)
return getattr(self, method_name)() return getattr(self, method_name)()
security.declareProtected(Permissions.ModifyPortalContent, security.declareProtected(Permissions.ModifyPortalContent,
'updateQuantityPredicate') 'updateQuantityPredicate')
def updateQuantityPredicate(self, price_parameter): def updateQuantityPredicate(self, price_parameter):
""" """
Update the quantity predicate Update the quantity predicate for this price parameter
""" """
value = self.getQuantityStepList(price_parameter) quantity_step_list = self.getQuantityStepList(price_parameter)
value.sort() quantity_step_list.sort()
# XXX Hardcoded portal type name
# remove old predicates
for pid in self.getQuantityPredicateIdList(price_parameter): for pid in self.getQuantityPredicateIdList(price_parameter):
self.deleteContent(pid) self.deleteContent(pid)
if len(value) > 0:
#value = value if quantity_step_list:
value = [None] + value + [None] quantity_step_list = [None] + quantity_step_list + [None]
# With this script, we can change customize the title of the # With this script, we can change the title of the predicate
# predicate
script = getattr(self, 'SupplyLine_getTitle', None) script = getattr(self, 'SupplyLine_getTitle', None)
predicate_id_start_with = "quantity_range" predicate_id_start_with = "quantity_range"
if price_parameter != "base_price": if price_parameter != "base_price":
predicate_id_start_with = "%s_%s" % \ predicate_id_start_with = "%s_%s" % \
(price_parameter, predicate_id_start_with) (price_parameter, predicate_id_start_with)
for i in range(0, len(value)-1): for i in range(0, len(quantity_step_list)-1):
min = value[i] min_quantity = quantity_step_list[i]
max = value[i+1] max_quantity = quantity_step_list[i+1]
# XXX Hardcoded portal type name # XXX Hardcoded portal type name
p = self.newContent(id='%s_%s' % (predicate_id_start_with, str(i)), p = self.newContent(id='%s_%s' % (predicate_id_start_with, str(i)),
portal_type = 'Predicate') portal_type = 'Predicate')
p.setCriterionPropertyList(('quantity', )) p.setCriterionPropertyList(('quantity', ))
p.setCriterion('quantity', min=min, max=max) p.setCriterion('quantity', min=min_quantity, max=max_quantity)
if script is not None: if script is not None:
title = script(min=min, max=max) title = script(min=min_quantity, max=max_quantity)
p.setTitle(title) p.setTitle(title)
else: else:
if min is None: if min_quantity is None:
p.setTitle(' quantity < %s' % repr(max)) p.setTitle('quantity < %s' % max_quantity)
elif max is None: elif max_quantity is None:
p.setTitle('%s <= quantity' % repr(min)) p.setTitle('%s <= quantity' % min_quantity)
else: else:
p.setTitle('%s <= quantity < %s' % (repr(min), repr(max))) p.setTitle('%s <= quantity < %s' % (min_quantity, max_quantity))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment