From 668386567f359895388b3a4cf47887a195359aff Mon Sep 17 00:00:00 2001
From: Yoshinori Okuji <yo@nexedi.com>
Date: Mon, 8 Feb 2010 17:57:32 +0000
Subject: [PATCH] Move the price precision support code into Amount, because it
 can be used by Path as well.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@32330 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/Document/Amount.py   | 34 +++++++++++++++++++++++++++++++
 product/ERP5/Document/Movement.py | 32 -----------------------------
 2 files changed, 34 insertions(+), 32 deletions(-)

diff --git a/product/ERP5/Document/Amount.py b/product/ERP5/Document/Amount.py
index 99473df4c0..8f89a4ff56 100644
--- a/product/ERP5/Document/Amount.py
+++ b/product/ERP5/Document/Amount.py
@@ -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
@@ -418,6 +419,39 @@ class Amount(Base, Variated):
     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')
   def getConvertedQuantity(self):
diff --git a/product/ERP5/Document/Movement.py b/product/ERP5/Document/Movement.py
index 7f84d980e8..38365762cc 100644
--- a/product/ERP5/Document/Movement.py
+++ b/product/ERP5/Document/Movement.py
@@ -27,7 +27,6 @@
 ##############################################################################
 
 import zope.interface
-from math import log
 from warnings import warn
 from AccessControl import ClassSecurityInfo
 
@@ -226,12 +225,6 @@ class Movement(XMLObject, Amount):
     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')
   def getPriceCalculationOperandDict(self, default=None, context=None, **kw):
@@ -301,31 +294,6 @@ class Movement(XMLObject, Amount):
       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,
-- 
2.30.9