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,20 +180,17 @@ Une ligne tarifaire.""" ...@@ -180,20 +180,17 @@ Une ligne tarifaire."""
result = None result = None
return result return result
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
or acquire it
"""
# Call a script on the context
if 'price' in self.getMappedValuePropertyList([]): if 'price' in self.getMappedValuePropertyList([]):
# Price is defined in an order # Try to compute an average price by accessing simulation movements
# First 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"):
order = m.getOrderValue()
if order is not None:
# Price is defined in an order
price = m.getPrice() price = m.getPrice()
quantity = m.getQuantity() quantity = m.getQuantity()
try: try:
...@@ -207,8 +204,16 @@ Une ligne tarifaire.""" ...@@ -207,8 +204,16 @@ Une ligne tarifaire."""
if total_quantity: if total_quantity:
# Update local price # Update local price
# self._setPrice(total_price / total_quantity) # self._setPrice(total_price / total_quantity)
return total_price / total_quantity self.setPrice( total_price / total_quantity )
# Either this is an order cell or it is a delivery with no relation in the simulation
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: 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,18 +154,20 @@ Une ligne tarifaire.""" ...@@ -153,18 +154,20 @@ 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"):
order = m.getOrderValue()
if order is not None:
# Price is defined in an order
price = m.getPrice() price = m.getPrice()
quantity = m.getQuantity() quantity = m.getQuantity()
try: try:
...@@ -178,9 +181,11 @@ Une ligne tarifaire.""" ...@@ -178,9 +181,11 @@ Une ligne tarifaire."""
if total_quantity: if total_quantity:
# Update local price # Update local price
# self._setPrice(total_price / total_quantity) # self._setPrice(total_price / total_quantity)
return total_price / total_quantity self.setPrice( total_price / total_quantity )
# Either this is an order cell or it is a delivery with no relation in the simulation else:
return Movement.getPrice(self, context=context, REQUEST=REQUEST, **kw) 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