Commit d0f6f1fe authored by Alexandre Boeglin's avatar Alexandre Boeglin

ERP5/Tool/DomainTool.py:

* added method generateMultivaluedMappedValue that returns a list of mapped
  value properties, instead of one single value

ERP5/Document/Resource.py:
* optimized price calculation with options


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@9275 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 6c3eefbb
......@@ -544,10 +544,13 @@ class Resource(XMLMatrix, CoreResource, Variated):
return p
def _pricingSortMethod(self, a, b):
# Simple method : the one that matches the highest number
# of criterions wins
return cmp(len(b.getAcquiredCategoryList()),
len(a.getAcquiredCategoryList()))
# Simple method : the one that defines a destination wins
parent = a.getParentValue()
if parent.getPortalType().endswith(' Line'):
parent = parent.getParentValue()
if parent.getDestination():
return -1 # a has a destination and wins
return 1 # a has no destination ans loses
security.declareProtected(Permissions.AccessContentsInformation,
'_getPriceParameterDict')
......@@ -567,43 +570,22 @@ class Resource(XMLMatrix, CoreResource, Variated):
resource_category = 'resource/' + self.getRelativeUrl()
if not resource_category in new_category_list:
new_category_list += (resource_category, )
# Generate a mapped value without option, and one for each option
# Separate option from new_category_list
option_base_category_list = self.getPortalOptionBaseCategoryList()
option_category_list = []
no_option_category_list = []
for new_category in new_category_list:
is_option = 0
for option_base_category in option_base_category_list:
if new_category.startswith(option_base_category):
is_option = 1
break
if is_option:
option_category_list.append(new_category)
else:
no_option_category_list.append(new_category)
# Generate the predicate mapped value
# to get some price values.
mapped_value_list = []
domain_tool = getToolByName(self,'portal_domains')
portal_type_list = self.getPortalSupplyPathTypeList()
category_list_list = [no_option_category_list] + \
[no_option_category_list+[x] for x in option_category_list]
for category_list in category_list_list:
# Generate the fake context
tmp_context = self.asContext(context=context,
categories=category_list,
categories=new_category_list,
REQUEST=REQUEST, **kw)
tmp_kw = kw.copy()
if 'sort_method' not in tmp_kw:
tmp_kw['sort_method'] = self._pricingSortMethod
mapped_value = domain_tool.generateMappedValue(
mapped_value = domain_tool.generateMultivaluedMappedValue(
tmp_context,
portal_type=portal_type_list,
has_cell_content=0, **tmp_kw)
if mapped_value is not None:
mapped_value_list.append(mapped_value)
# Get price parameters
price_parameter_dict = {
'base_price': None,
......@@ -614,18 +596,23 @@ class Resource(XMLMatrix, CoreResource, Variated):
'variable_additional_price': [],
'non_discountable_additional_price': [],
}
for mapped_value in mapped_value_list:
if mapped_value is None:
return price_parameter_dict
for price_parameter_name in price_parameter_dict.keys():
price_parameter_value = \
mapped_value.getProperty(price_parameter_name)
if price_parameter_value not in [None, '']:
try:
price_parameter_dict[price_parameter_name].append(
price_parameter_dict[price_parameter_name].extend(
price_parameter_value)
except AttributeError:
if price_parameter_dict[price_parameter_name] is None:
if price_parameter_name == 'exclusive_discount_ratio':
price_parameter_dict[price_parameter_name] = \
max(price_parameter_value)
else:
price_parameter_dict[price_parameter_name] = \
price_parameter_value
price_parameter_value[0]
return price_parameter_dict
security.declareProtected(Permissions.AccessContentsInformation,
......
......@@ -189,12 +189,12 @@ class DomainTool(BaseTool):
def generateMappedValue(self, context, test=1, predicate_list=None, **kw):
"""
We will generate a mapped value with the list of all predicates
founds.
found.
Let's say we have 3 predicates (in the order we want) like this:
Predicate 1 [ base_price1, , , , , , ]
Predicate 2 [ base_price2, quantity2 , , , , , ]
Predicate 3 [ base_price3, quantity3 , , , , , ]
Our MappedValue generated will have the base_price of the
Our generated MappedValue will have the base_price of the
predicate1, and the quantity of the Predicate2, because Predicate
1 is the first one which defines a base_price and the Predicate2
is the first one wich defines a quantity.
......@@ -223,6 +223,55 @@ class DomainTool(BaseTool):
mapped_value = mapped_value.asContext(**mapped_value_property_dict)
return mapped_value
# XXX FIXME method should not be public
# (some users are not able to see resource's price)
security.declarePublic('generateMultivaluedMappedValue')
def generateMultivaluedMappedValue(self, context, test=1, predicate_list=None, **kw):
"""
We will generate a mapped value with the list of all predicates
found.
Let's say we have 3 predicates (in the order we want) like this:
Predicate 1 [ base_price1, , , , , , ]
Predicate 2 [ base_price2, additional_price2 , , , , , ]
Predicate 3 [ base_price3, additional_price3 , , , , , ]
Our generated MappedValue will take all values for each property and put
them in lists, unless predicates define the same list of criterion categories
"""
# First get the list of predicates
if predicate_list is None:
predicate_list = self.searchPredicateList(context, test=test, **kw)
if len(predicate_list)==0:
# No predicate, return None
mapped_value = None
else:
# Generate tempDeliveryCell
from Products.ERP5Type.Document import newTempSupplyCell
mapped_value = newTempSupplyCell(self.getPortalObject(),
'new_mapped_value')
mapped_value_property_dict = {}
processed_dict = {}
# Look for each property the first predicate with unique criterion
# categories which defines the property
for predicate in predicate_list:
predicate_category_list = \
tuple(predicate.getMembershipCriterionCategoryList())
for mapped_value_property in predicate.getMappedValuePropertyList():
prop_list = processed_dict.setdefault(predicate_category_list, [])
if mapped_value_property in prop_list:
# we already have one value for this (categories, property)
continue
prop_list.append(mapped_value_property)
value = predicate.getProperty(mapped_value_property)
if value is not None:
mv_prop_list = \
mapped_value_property_dict.setdefault(
mapped_value_property, [])
mv_prop_list.append(value)
# Update mapped value
mapped_value = mapped_value.asContext(**mapped_value_property_dict)
return mapped_value
def getChildDomainValueList(self, parent, **kw):
......
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