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...""" ...@@ -410,6 +410,12 @@ une liste de mouvements..."""
return self._getDestinationTotalPrice(self.asContext(context=context, REQUEST=REQUEST, **kw)) return self._getDestinationTotalPrice(self.asContext(context=context, REQUEST=REQUEST, **kw))
# Pricing # 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') security.declareProtected(Permissions.AccessContentsInformation, 'getTotalPrice')
def getTotalPrice(self): def getTotalPrice(self):
""" """
......
...@@ -180,6 +180,32 @@ Une ligne tarifaire.""" ...@@ -180,6 +180,32 @@ Une ligne tarifaire."""
result = None result = None
return result 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' ) security.declareProtected( Permissions.AccessContentsInformation, 'getPrice' )
def getPrice(self, context=None, REQUEST=None, **kw): def getPrice(self, context=None, REQUEST=None, **kw):
""" """
...@@ -188,27 +214,6 @@ Une ligne tarifaire.""" ...@@ -188,27 +214,6 @@ Une ligne tarifaire."""
""" """
# Call a script on the context # Call a script on the context
if 'price' in self.getMappedValuePropertyList([]): 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: if getattr(aq_base(self), 'price', None) is not None:
return getattr(self, 'price') # default returns a price defined by the mapped value return getattr(self, 'price') # default returns a price defined by the mapped value
else: else:
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
from Globals import InitializeClass, PersistentMapping from Globals import InitializeClass, PersistentMapping
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Acquisition import aq_base
from Products.CMFCore.WorkflowCore import WorkflowAction from Products.CMFCore.WorkflowCore import WorkflowAction
from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface
...@@ -153,34 +154,38 @@ Une ligne tarifaire.""" ...@@ -153,34 +154,38 @@ Une ligne tarifaire."""
return self.aq_parent.isAccountable() and (not self.hasCellContent()) return self.aq_parent.isAccountable() and (not self.hasCellContent())
# Pricing # Pricing
security.declareProtected(Permissions.AccessContentsInformation, 'getPrice') security.declareProtected(Permissions.ModifyPortalContent, 'updatePrice')
def getPrice(self, context=None, REQUEST=None, **kw): def updatePrice(self):
""" """
Returns the price if defined on the cell Tries to find out a price for this movement
or acquire it
""" """
# Price is defined in an order if not self.hasCellContent():
# First try to compute an average price by accessing simulation movements # Try to compute an average price by accessing simulation movements
# this should always return 0 in the case of OrderCell # This should always return 0 in the case of OrderCell
total_quantity = 0.0 total_quantity = 0.0
total_price = 0.0 total_price = 0.0
for m in self.getDeliveryRelatedValueList(portal_type="Simulation Movement"): for m in self.getDeliveryRelatedValueList(portal_type="Simulation Movement"):
price = m.getPrice() order = m.getOrderValue()
quantity = m.getQuantity() if order is not None:
try: # Price is defined in an order
price = float(price) price = m.getPrice()
quantity = float(quantity) quantity = m.getQuantity()
except: try:
price = 0.0 price = float(price)
quantity = 0.0 quantity = float(quantity)
total_quantity += quantity except:
total_price += quantity * price price = 0.0
if total_quantity: quantity = 0.0
# Update local price total_quantity += quantity
# self._setPrice(total_price / total_quantity) total_price += quantity * price
return total_price / total_quantity if total_quantity:
# Either this is an order cell or it is a delivery with no relation in the simulation # Update local price
return Movement.getPrice(self, context=context, REQUEST=REQUEST, **kw) # 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): def _getTotalPrice(self, context):
if not self.hasCellContent(): 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