Commit cbf83e71 authored by Jean-Paul Smets's avatar Jean-Paul Smets Committed by Xiaowu Zhang

Added an API to create a default price calculation context to computer price.

Added comments about mixup of kw params in Price API.
parent c803a430
......@@ -650,6 +650,15 @@ class Resource(XMLObject, XMLMatrix, VariatedMixin):
return -1 # a defines a destination section and wins
return 1 # a defines no destination section and loses
def _getPriceCalculationContext(self):
# Tries to find a default context to feed the price calculation
# process. For example, it will set a context in which the
# destination_section is set to the end user the the currency
# to the preferred currency of the end user
method = self._getTypeBasedMethod('getPriceCalculationDefaultContext')
if method is not None:
return method()
security.declareProtected(Permissions.AccessContentsInformation,
'getPriceParameterDict')
def getPriceParameterDict(self, context=None, REQUEST=None,
......@@ -659,7 +668,7 @@ class Resource(XMLObject, XMLMatrix, VariatedMixin):
"""
# Search all categories context
if context is None:
new_category_list = []
new_category_list = [] # Better create a TempMovement ZAXEE
else:
new_category_list = context.getCategoryList()
#XXX This should be 'category_list' instead of 'categories' to respect
......@@ -683,7 +692,7 @@ class Resource(XMLObject, XMLMatrix, VariatedMixin):
# Generate the fake context
tmp_context = self.asContext(context=context,
categories=new_category_list,
REQUEST=REQUEST, **kw)
REQUEST=REQUEST, **kw) # ZAWEE nonsens to use **kw in both places, two parameters needed probably **kw and predicate_kw
# XXX When called for a generated amount, base_application may point
# to nonexistant base_amount (e.g. "base_amount/produced_quantity" for
# transformations), which would make domain tool return nothing.
......@@ -850,7 +859,11 @@ class Resource(XMLObject, XMLMatrix, VariatedMixin):
def getPrice(self, default=None, context=None, REQUEST=None, **kw):
"""
Return the unit price of a resource in a specific context.
ZAWEE - parameters should be well defined **kw parlty used to select predicate and build context
"""
# HACK for default price
if context is None: context=self.Resource_getPriceCalculationDefaultContext() # ZAWEE
# see Movement.getPrice
if isinstance(default, Base) and context is None:
msg = 'getPrice first argument is supposed to be the default value'\
......
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