[Erp5-report] r32328 yo - in /erp5/trunk/products/ERP5: Document/ PropertySheet/

nobody at svn.erp5.org nobody at svn.erp5.org
Mon Feb 8 18:45:59 CET 2010


Author: yo
Date: Mon Feb  8 18:45:59 2010
New Revision: 32328

URL: http://svn.erp5.org?rev=32328&view=rev
Log:
Add basic support for price precision.

Modified:
    erp5/trunk/products/ERP5/Document/Movement.py
    erp5/trunk/products/ERP5/Document/Resource.py
    erp5/trunk/products/ERP5/PropertySheet/Price.py

Modified: erp5/trunk/products/ERP5/Document/Movement.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/Movement.py?rev=32328&r1=32327&r2=32328&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/Movement.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Document/Movement.py [utf8] Mon Feb  8 18:45:59 2010
@@ -27,6 +27,7 @@
 ##############################################################################
 
 import zope.interface
+from math import log
 from warnings import warn
 from AccessControl import ClassSecurityInfo
 
@@ -224,6 +225,12 @@
       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')
@@ -294,6 +301,31 @@
       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,

Modified: erp5/trunk/products/ERP5/Document/Resource.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/Resource.py?rev=32328&r1=32327&r2=32328&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/Resource.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Document/Resource.py [utf8] Mon Feb  8 18:45:59 2010
@@ -608,6 +608,7 @@
         'variable_additional_price': [],
         'non_discountable_additional_price': [],
         'priced_quantity': None,
+        'base_unit_price': None,
       }
       if mapped_value is None:
         return price_parameter_dict

Modified: erp5/trunk/products/ERP5/PropertySheet/Price.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/PropertySheet/Price.py?rev=32328&r1=32327&r2=32328&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/PropertySheet/Price.py [utf8] (original)
+++ erp5/trunk/products/ERP5/PropertySheet/Price.py [utf8] Mon Feb  8 18:45:59 2010
@@ -45,6 +45,20 @@
             'acquisition_copy_value'        : 0,
             'acquisition_mask_value'        : 1,
             'acquisition_accessor_id'       : 'getPrice',
+            'acquisition_depends'           : None,
+            'mode'        : 'w' },
+        {   'id'          : 'base_unit_price',
+            'description' : 'The smallest unit price used to determine the precision of a price',
+            'type'        : 'float',
+            'acquisition_base_category'     : ('parent', 'order', 'delivery'),
+            'acquisition_portal_type'       : \
+                Expression('python: ' \
+                           'portal.getPortalAcquisitionMovementTypeList() +' \
+                           'portal.getPortalDeliveryTypeList() +' \
+                           'portal.getPortalSupplyPathTypeList()'),
+            'acquisition_copy_value'        : 0,
+            'acquisition_mask_value'        : 1,
+            'acquisition_accessor_id'       : 'getBaseUnitPrice',
             'acquisition_depends'           : None,
             'mode'        : 'w' },
         # priced_quantity should be acquired from cells to lines




More information about the Erp5-report mailing list