Commit df73e8f2 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Add a new method getPriceCalculationPriceDict to obtain more detailed...

Add a new method getPriceCalculationPriceDict to obtain more detailed information from price calculation.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@15375 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent fbfafbdd
......@@ -199,8 +199,9 @@ class Movement(XMLObject, Amount):
# _getPrice is defined in the order / delivery
# Pricing mehod
def _getPrice(self, context):
# Call a script on the context
return context.Movement_lookupPrice()
operand_dict = self.getPriceCalculationOperandDict(context=context)
if operand_dict is not None:
return operand_dict['price']
def _getTotalPrice(self, default=None, context=None):
price = self.getPrice(context=context)
......@@ -211,6 +212,34 @@ class Movement(XMLObject, Amount):
else:
return default
security.declareProtected(Permissions.AccessContentsInformation,
'getPriceCalculationOperandDict')
def getPriceCalculationOperandDict(self, default=None, context=None, **kw):
"""Return a dict object which contains operands used for price
calculation. The returned items depend on a site configuration,
because this will invoke a custom script at the end. The only
assumption is that the dict must contain a key 'price'
which represents the final result of the price calculation.
The purpose is to obtain descriptive information to notify the user
of how a price is calculated in details, in particular, for invoices
and quotations. So a script which is eventually called should provide
all values required for generating such reports (e.g. a price,
a price without a discount, and a discount).
"""
# First, try a type-based method, and if not present, use
# the good-old-days way (which only returns a final result).
if context is None:
context = self
method = context._getTypeBasedMethod('getPriceCalculationOperandDict')
if method is not None:
operand_dict = method(**kw)
if operand_dict is None:
return default
assert 'price' in operand_dict
return operand_dict
return {'price': context.Movement_lookupPrice()}
security.declareProtected(Permissions.AccessContentsInformation, 'getPrice')
def getPrice(self, default=None, **kw):
"""
......
......@@ -636,29 +636,29 @@ class Resource(XMLMatrix, Variated):
return float(method())
security.declareProtected(Permissions.AccessContentsInformation,
'getPrice')
def getPrice(self, default=None, context=None, REQUEST=None, **kw):
"""
Return the unit price of a resource in a specific context.
"""
# see Movement.getPrice
if isinstance(default, Base) and context is None:
msg = 'getPrice first argument is supposed to be the default value'\
' accessor, the context should be passed as with the context='\
' keyword argument'
warn(msg, DeprecationWarning)
LOG('ERP5', WARNING, msg)
context = default
default = None
# First, try to use a type-based method for the calculation.
'getPriceCalculationOperandDict')
def getPriceCalculationOperandDict(self, default=None, context=None,
REQUEST=None, **kw):
"""Return a dictionary which contains operands for price calculation.
Consult the doc string in Movement.getPriceCalculationOperandDict
for more details.
"""
# First, try to use a new type-based method for the calculation.
# Note that this is based on self (i.e. a resource) instead of context
# (i.e. a movement).
method = self._getTypeBasedMethod('getPrice')
method = self._getTypeBasedMethod('getPriceCalculationOperandDict')
if method is not None:
return method(default=default, movement=context, REQUEST=REQUEST, **kw)
# This below is used only if the type-based method is not
# Next, try an old type-based method which returns only a final result.
method = self._getTypeBasedMethod('getPrice')
if method is not None:
price = method(default=default, movement=context, REQUEST=REQUEST, **kw)
if price is not None:
return {'price': price}
return default
# This below is used only if any type-based method is not
# available at all. We should provide the default implementation
# in a Business Template as Resource_getPrice, thus this will not
# be used in the future. Kept only for backward compatibility in
......@@ -727,7 +727,31 @@ class Resource(XMLMatrix, Variated):
priced_quantity = self.getPricedQuantity()
unit_base_price = unit_base_price / priced_quantity
# Return result
return unit_base_price
if unit_base_price is not None:
return {'price': unit_base_price}
return default
security.declareProtected(Permissions.AccessContentsInformation,
'getPrice')
def getPrice(self, default=None, context=None, REQUEST=None, **kw):
"""
Return the unit price of a resource in a specific context.
"""
# see Movement.getPrice
if isinstance(default, Base) and context is None:
msg = 'getPrice first argument is supposed to be the default value'\
' accessor, the context should be passed as with the context='\
' keyword argument'
warn(msg, DeprecationWarning)
LOG('ERP5', WARNING, msg)
context = default
default = None
operand_dict = self.getPriceCalculationOperandDict(default=default,
context=context, REQUEST=REQUEST, **kw)
if operand_dict is not None:
return operand_dict['price']
return default
security.declareProtected(Permissions.AccessContentsInformation,
'getQuantityPrecision')
......
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