[Erp5-report] r32330 yo - in /erp5/trunk/products/ERP5/Document: Amount.py Movement.py

nobody at svn.erp5.org nobody at svn.erp5.org
Mon Feb 8 18:57:34 CET 2010


Author: yo
Date: Mon Feb  8 18:57:32 2010
New Revision: 32330

URL: http://svn.erp5.org?rev=32330&view=rev
Log:
Move the price precision support code into Amount, because it can be used by Path as well.

Modified:
    erp5/trunk/products/ERP5/Document/Amount.py
    erp5/trunk/products/ERP5/Document/Movement.py

Modified: erp5/trunk/products/ERP5/Document/Amount.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/Amount.py?rev=32330&r1=32329&r2=32330&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/Amount.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Document/Amount.py [utf8] Mon Feb  8 18:57:32 2010
@@ -28,6 +28,7 @@
 ##############################################################################
 
 import zope.interface
+from math import log
 from Products.ERP5Type.Globals import InitializeClass
 from AccessControl import ClassSecurityInfo
 from Products.ERP5.Variated import Variated
@@ -417,6 +418,39 @@
     quantity = self.getNetConvertedQuantity()
     if isinstance(price, (int, float)) and isinstance(quantity, (int, float)):
       return quantity * price
+
+  def _getBaseUnitPrice(self, context):
+    resource = self.getResourceValue()
+    if resource is not None:
+      operand_dict = resource.getPriceParameterDict(context=context)
+      if operand_dict is not None:
+        base_unit_price = operand_dict.get('base_unit_price', None)
+        return base_unit_price
+
+  security.declareProtected(Permissions.AccessContentsInformation, 'getBaseUnitPrice')
+  def getBaseUnitPrice(self, **kw):
+    """
+      Get the base unit price.
+
+      If the property is not stored locally, look up one and store it.
+    """
+    local_base_unit_price = self._baseGetBaseUnitPrice()
+    if local_base_unit_price is None:
+      # We must find a base unit price for this movement
+      local_base_unit_price = self._getBaseUnitPrice(context=self)
+    return local_base_unit_price
+
+  security.declareProtected(Permissions.AccessContentsInformation, 
+                            'getPricePrecision')
+  def getPricePrecision(self):
+    """Return the floating point precision of a price.
+    """
+    # First, try to use a base unit price. If not available, use
+    # the older way of using a price currency.
+    try:
+      return int(round(- log(self.getBaseUnitPrice(), 10), 0))
+    except TypeError:
+      return self.getQuantityPrecisionFromResource(self.getPriceCurrency())
 
   # Conversion to standard unit
   security.declareProtected(Permissions.AccessContentsInformation, 'getConvertedQuantity')

Modified: erp5/trunk/products/ERP5/Document/Movement.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/Movement.py?rev=32330&r1=32329&r2=32330&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/Movement.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Document/Movement.py [utf8] Mon Feb  8 18:57:32 2010
@@ -27,7 +27,6 @@
 ##############################################################################
 
 import zope.interface
-from math import log
 from warnings import warn
 from AccessControl import ClassSecurityInfo
 
@@ -225,12 +224,6 @@
       return quantity * price
     else:
       return default
-
-  def _getBaseUnitPrice(self, context):
-    operand_dict = self.getPriceParameterDict(context=context)
-    if operand_dict is not None:
-      price = operand_dict.get('base_unit_price', None)
-      return price
 
   security.declareProtected(Permissions.AccessContentsInformation, 
           'getPriceCalculationOperandDict')
@@ -301,31 +294,6 @@
       local_price = self._getPrice(context=self)
     return local_price
 
-  security.declareProtected(Permissions.AccessContentsInformation, 'getBaseUnitPrice')
-  def getBaseUnitPrice(self, default=None, **kw):
-    """
-      Get the base unit price.
-
-      If the property is not stored locally, look up one and store it.
-    """
-    local_base_unit_price = self._baseGetBaseUnitPrice()
-    if local_base_unit_price is None:
-      # We must find a base unit price for this movement
-      local_base_unit_price = self._getBaseUnitPrice(context=self)
-    return local_base_unit_price
-
-  security.declareProtected(Permissions.AccessContentsInformation, 
-                            'getPricePrecision')
-  def getPricePrecision(self):
-    """Return the floating point precision of a price.
-    """
-    # First, try to use a base unit price. If not available, use
-    # the older way of using a price currency.
-    try:
-      return int(round(- log(self.getBaseUnitPrice(), 10), 0))
-    except TypeError:
-      return self.getQuantityPrecisionFromResource(self.getPriceCurrency())
-
   security.declareProtected( Permissions.AccessContentsInformation,
                              'getTotalPrice')
   def getTotalPrice(self, default=0.0, context=None, REQUEST=None, fast=None,




More information about the Erp5-report mailing list