Commit 66838656 authored by Yoshinori Okuji's avatar Yoshinori Okuji

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
parent c4e684f4
......@@ -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):
......
......@@ -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,
......
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