diff --git a/product/ERP5/Document/Delivery.py b/product/ERP5/Document/Delivery.py index ed1672576975e554b24555d4be619013de03dfda..fd42fb67c5105d2c03c99dbaf373c4dbbdcf77fc 100755 --- a/product/ERP5/Document/Delivery.py +++ b/product/ERP5/Document/Delivery.py @@ -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): """ diff --git a/product/ERP5/Document/DeliveryCell.py b/product/ERP5/Document/DeliveryCell.py index dc355f460164e779482e93d222d3c7f569d4626c..64d6eaf14c963c02ee154c3ccebda23e953fd334 100755 --- a/product/ERP5/Document/DeliveryCell.py +++ b/product/ERP5/Document/DeliveryCell.py @@ -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: diff --git a/product/ERP5/Document/DeliveryLine.py b/product/ERP5/Document/DeliveryLine.py index 4b28312cb13f3ada617b077327191ffa3e22d840..b170e90f489ae409c1bd1278013f0d6fdddac8e2 100755 --- a/product/ERP5/Document/DeliveryLine.py +++ b/product/ERP5/Document/DeliveryLine.py @@ -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():