Commit 64f03033 authored by Jean-Paul Smets's avatar Jean-Paul Smets

updatePrice method added


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@105 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 64cbf76b
......@@ -410,6 +410,12 @@ une liste de mouvements..."""
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):
"""
......
......@@ -180,6 +180,32 @@ Une ligne tarifaire."""
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:
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' )
def getPrice(self, context=None, REQUEST=None, **kw):
"""
......@@ -188,27 +214,6 @@ Une ligne tarifaire."""
"""
# Call a script on the context
if 'price' in self.getMappedValuePropertyList([]):
# Price is defined in an order
# First 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"):
price = m.getPrice()
quantity = m.getQuantity()
try:
price = float(price)
quantity = float(quantity)
except:
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)
return total_price / total_quantity
# Either this is an order cell or it is a delivery with no relation in the simulation
if getattr(aq_base(self), 'price', None) is not None:
return getattr(self, 'price') # default returns a price defined by the mapped value
else:
......
......@@ -28,6 +28,7 @@
from Globals import InitializeClass, PersistentMapping
from AccessControl import ClassSecurityInfo
from Acquisition import aq_base
from Products.CMFCore.WorkflowCore import WorkflowAction
from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface
......@@ -153,34 +154,38 @@ Une ligne tarifaire."""
return self.aq_parent.isAccountable() and (not self.hasCellContent())
# Pricing
security.declareProtected(Permissions.AccessContentsInformation, 'getPrice')
def getPrice(self, context=None, REQUEST=None, **kw):
security.declareProtected(Permissions.ModifyPortalContent, 'updatePrice')
def updatePrice(self):
"""
Returns the price if defined on the cell
or acquire it
Tries to find out a price for this movement
"""
# Price is defined in an order
# First 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"):
price = m.getPrice()
quantity = m.getQuantity()
try:
price = float(price)
quantity = float(quantity)
except:
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)
return total_price / total_quantity
# Either this is an order cell or it is a delivery with no relation in the simulation
return Movement.getPrice(self, context=context, REQUEST=REQUEST, **kw)
if not self.hasCellContent():
# 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:
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 )
else:
for c in self.objectValues():
if hasattr(aq_base(c), 'updatePrice'):
c.updatePrice()
def _getTotalPrice(self, context):
if not self.hasCellContent():
......
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