Commit 4bcdd441 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Add basic support for price precision.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@32328 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent dbe157a3
......@@ -27,6 +27,7 @@
##############################################################################
import zope.interface
from math import log
from warnings import warn
from AccessControl import ClassSecurityInfo
......@@ -225,6 +226,12 @@ 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):
......@@ -294,6 +301,31 @@ 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,
......
......@@ -608,6 +608,7 @@ class Resource(XMLMatrix, Variated):
'variable_additional_price': [],
'non_discountable_additional_price': [],
'priced_quantity': None,
'base_unit_price': None,
}
if mapped_value is None:
return price_parameter_dict
......
......@@ -47,6 +47,20 @@ class Price:
'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
{ 'id' : 'priced_quantity',
'description' : 'Number of units involved in base prices',
......
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