Commit 91023745 authored by Alexandre Boeglin's avatar Alexandre Boeglin

Remove old or useless methods, allow price calculation to work on cells.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@20548 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 636d956e
......@@ -107,13 +107,6 @@ class Delivery(XMLObject, ImmobilisationDelivery):
"""
return self._getDestinationTotalPrice(self.asContext(context=context, REQUEST=REQUEST, **kw))
# Pricing
security.declareProtected( Permissions.ModifyPortalContent, 'updatePrice' )
def updatePrice(self):
for c in self.objectValues():
if hasattr(aq_base(c), 'updatePrice'):
c.updatePrice()
security.declareProtected( Permissions.AccessContentsInformation,
'getTotalPrice')
def getTotalPrice(self, fast=0, src__=0, **kw):
......
......@@ -72,14 +72,6 @@ class DeliveryCell(MappedValue, Movement, ImmobilisationMovement):
, PropertySheet.ItemAggregation
)
# Explicit acquisition of aq_dynamic generated method
security.declareProtected(Permissions.AccessContentsInformation, 'getSimulationState')
def getSimulationState(self):
"""
Explicitly acquire simulation_state from parent
"""
return self.getParentValue().getSimulationState()
# MatrixBox methods
security.declareProtected( Permissions.AccessContentsInformation,
......@@ -98,113 +90,12 @@ class DeliveryCell(MappedValue, Movement, ImmobilisationMovement):
"""
return self.getParentValue().getParentValue().isAccountable()
security.declareProtected( Permissions.AccessContentsInformation, 'getProperty' )
def getProperty(self, key, d=None):
"""
Generic accessor. First we check if the value
exists. Else we call the real accessor
"""
#try:
if 1:
# If mapped_value_property_list is not set
# then it creates an exception
if key in self.getMappedValuePropertyList([]):
if getattr(self, key, None) is not None:
return getattr(self, key)
else:
LOG("Not Found Property %s"%key, -100,"")
return self.getParentValue().getProperty(key)
#except:
# LOG("WARNING: ERP5", 0, 'Could not access mapped value property %s' % key)
# return None
# Standard accessor
try:
result = Movement.getProperty(self, key, d=d)
except AttributeError:
result = None
return result
security.declareProtected( Permissions.ModifyPortalContent, 'updatePrice' )
def updatePrice(self):
if 'price' in self.getMappedValuePropertyList([]):
# Try to compute an average price by accessing simulation movements
# This should always return 0 in the case of OrderCell
total_quantity = 0.0
total_price = 0.0
for m in self.getDeliveryRelatedValueList(portal_type="Simulation Movement"):
order = m.getOrderValue()
if order is not None:
# Price is defined in an order
price = m.getPrice()
quantity = m.getQuantity()
try:
price = float(price)
quantity = float(quantity)
except TypeError:
price = 0.0
quantity = 0.0
total_quantity += quantity
total_price += quantity * price
if total_quantity:
# Update local price
# self._setPrice(total_price / total_quantity)
self.setPrice( total_price / total_quantity )
security.declareProtected( Permissions.AccessContentsInformation, 'getPrice' )
security.declareProtected(Permissions.AccessContentsInformation, 'getPrice')
def getPrice(self, context=None, REQUEST=None, **kw):
"""
Returns the price if defined on the cell
or acquire it
"""
# Call a script on the context
if 'price' in self.getMappedValuePropertyList([]):
if getattr(aq_base(self), 'price', None) is not None:
# default returns a price defined by the mapped value
return getattr(self, 'price')
else:
return self.getParentValue().getProperty('price') # Price is acquired
else:
return None
security.declareProtected( Permissions.AccessContentsInformation,
'getQuantity' )
def getQuantity(self):
"""
Returns the quantity if defined on the cell
or acquire it
"""
# Call a script on the context
if 'quantity' in self.getMappedValuePropertyList([]):
if getattr(aq_base(self), 'quantity', None) is not None:
return getattr(self, 'quantity')
else:
return self.getParentValue().getProperty('quantity')
else:
# We have acquisition here which me should mimic
return self.getParentValue().getQuantity()
# Required for indexing
security.declareProtected(Permissions.AccessContentsInformation,
'getInventoriatedQuantity')
def getInventoriatedQuantity(self):
"""
"""
return Movement.getInventoriatedQuantity(self)
security.declareProtected(Permissions.AccessContentsInformation,
'getStartDate')
def getStartDate(self):
"""
"""
return self._baseGetStartDate()
security.declareProtected(Permissions.AccessContentsInformation,
'getStopDate')
def getStopDate(self):
"""
call Movement.getPrice
"""
return self._baseGetStopDate()
return Movement.getPrice(self, context=context, REQUEST=REQUEST, **kw)
security.declareProtected(Permissions.AccessContentsInformation,
'getRootDeliveryValue')
......
......@@ -75,17 +75,6 @@ class DeliveryLine(Movement, XMLObject, XMLMatrix, Variated,
# Multiple inheritance definition
updateRelatedContent = XMLMatrix.updateRelatedContent
# Explicit acquisition of aq_dynamic generated method
security.declareProtected(Permissions.AccessContentsInformation,
'getSimulationState')
def getSimulationState(self):
"""
Explicitly acquire simulation_state from parent
"""
method = getattr(self.getParentValue(),'getSimulationState', None)
if method is not None:
return method()
# Force in _edit to modify variation_base_category_list first
security.declarePrivate( '_edit' )
def _edit(self, REQUEST=None, force_update = 0, **kw):
......
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