Commit 17320c43 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

support sort_key_method in Resource.getPriceParameterDict() and rewrite...

support sort_key_method in Resource.getPriceParameterDict() and rewrite Movement_getPriceCalculationOperandDict using it.
parent fa0b9856
......@@ -631,7 +631,7 @@ class Resource(XMLObject, XMLMatrix, VariatedMixin):
# Default value is None
return None
def _pricingSortMethod(self, a, b):
def _pricingSortKeyMethod(self, a):
# Simple method : the one that defines a destination section wins
if a.getDestinationSection():
return -1 # a defines a destination section and wins
......@@ -666,7 +666,16 @@ class Resource(XMLObject, XMLMatrix, VariatedMixin):
else:
portal_type_list = (supply_path_type,)
sort_method = kw.pop('sort_method', self._pricingSortMethod)
sort_key_method = kw.pop('sort_key_method', None)
if sort_key_method is None:
sort_method = kw.pop('sort_method', None)
if sort_method is None:
# use default sort_key_method if neither sort_key_method nor
# sort_method is specified.
sort_key_method = self._pricingSortKeyMethod
else:
# if sort_key_method is specified, we don't need sort_method.
sort_method = None
# Generate the fake context
tmp_context = self.asContext(context=context,
categories=new_category_list,
......@@ -682,6 +691,7 @@ class Resource(XMLObject, XMLMatrix, VariatedMixin):
tmp_context,
portal_type=portal_type_list,
has_cell_content=0,
sort_key_method=sort_key_method,
sort_method=sort_method, **kw)
# Get price parameters
price_parameter_dict = {
......
......@@ -50,88 +50,58 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>def sourceSectionSortMethod(a, b):\n
if a.getSourceSection():\n
return -1 # a defines a source section and wins\n
return 1 # a defines no source section and loses\n
\n
\n
def destinationSectionSortMethod(a, b):\n
if a.getDestinationSection():\n
return -1 # a defines a destination section and wins\n
return 1 # a defines no destination section and loses\n
\n
\n
def getResourceInternalPriceSortMethod(high_priority_supply_line_list):\n
def resourceInternalPriceSortMethod(a, b):\n
a_number = (a in high_priority_supply_line_list) and high_priority_supply_line_list.index(a)+1 or 0\n
b_number = (b in high_priority_supply_line_list) and high_priority_supply_line_list.index(b)+1 or 0\n
if a_number and b_number:\n
return a_number - b_number\n
elif a_number:\n
return -1\n
elif b_number:\n
return 1\n
\n
if "Internal" in a.getPortalType():\n
if "Internal" in b.getPortalType():\n
return destinationSectionSortMethod(a, b)\n
<value> <string>def getResourceInternalPriceSortKeyMethod(high_priority_supply_line_list):\n
def resourceInternalPriceSortKeyMethod(a):\n
high_priority_supply_line_list_len = len(high_priority_supply_line_list)\n
if a in high_priority_supply_line_list:\n
return high_priority_supply_line_list.index(a)\n
elif "Internal" in a.getPortalType():\n
if a.getDestinationSection():\n
return high_priority_supply_line_list_len\n
else:\n
return -1\n
return high_priority_supply_line_list_len + 1\n
else:\n
if "Internal" in b.getPortalType():\n
return 1\n
if a.getSourceSection():\n
return high_priority_supply_line_list_len + 2\n
else:\n
return sourceSectionSortMethod(a, b)\n
return resourceInternalPriceSortMethod\n
\n
\n
def getResourcePurchasePriceSortMethod(high_priority_supply_line_list):\n
def resourcePurchasePriceSortMethod(a, b):\n
a_number = (a in high_priority_supply_line_list) and high_priority_supply_line_list.index(a)+1 or 0\n
b_number = (b in high_priority_supply_line_list) and high_priority_supply_line_list.index(b)+1 or 0\n
if a_number and b_number:\n
return a_number - b_number\n
elif a_number:\n
return -1\n
elif b_number:\n
return 1\n
\n
if "Purchase" in a.getPortalType():\n
if "Purchase" in b.getPortalType():\n
return sourceSectionSortMethod(a, b)\n
return high_priority_supply_line_list_len + 3\n
return resourceInternalPriceSortKeyMethod\n
\n
\n
def getResourcePurchasePriceSortKeyMethod(high_priority_supply_line_list):\n
def resourcePurchasePriceSortKeyMethod(a):\n
high_priority_supply_line_list_len = len(high_priority_supply_line_list)\n
if a in high_priority_supply_line_list:\n
return high_priority_supply_line_list.index(a)\n
elif "Purchase" in a.getPortalType():\n
if a.getSourceSection():\n
return high_priority_supply_line_list_len\n
else:\n
return -1\n
return high_priority_supply_line_list_len + 1\n
else:\n
if "Purchase" in b.getPortalType():\n
return 1\n
if a.getDestinationSection():\n
return high_priority_supply_line_list_len + 2\n
else:\n
return destinationSectionSortMethod(a, b)\n
return resourcePurchasePriceSortMethod\n
\n
\n
def getResourceSalePriceSortMethod(high_priority_supply_line_list):\n
def resourceSalePriceSortMethod(a, b):\n
a_number = (a in high_priority_supply_line_list) and high_priority_supply_line_list.index(a)+1 or 0\n
b_number = (b in high_priority_supply_line_list) and high_priority_supply_line_list.index(b)+1 or 0\n
if a_number and b_number:\n
return a_number - b_number\n
elif a_number:\n
return -1\n
elif b_number:\n
return 1\n
\n
if "Sale" in a.getPortalType():\n
if "Sale" in b.getPortalType():\n
return destinationSectionSortMethod(a, b)\n
return high_priority_supply_line_list_len + 3\n
return resourcePurchasePriceSortKeyMethod\n
\n
\n
def getResourceSalePriceSortKeyMethod(high_priority_supply_line_list):\n
def resourceSalePriceSortKeyMethod(a):\n
high_priority_supply_line_list_len = len(high_priority_supply_line_list)\n
if a in high_priority_supply_line_list:\n
return high_priority_supply_line_list.index(a)\n
elif "Sale" in a.getPortalType():\n
if a.getDestinationSection():\n
return high_priority_supply_line_list_len\n
else:\n
return -1\n
return high_priority_supply_line_list_len + 1\n
else:\n
if "Sale" in b.getPortalType():\n
return 1\n
if a.getSourceSection():\n
return high_priority_supply_line_list_len + 2\n
else:\n
return sourceSectionSortMethod(a, b)\n
return resourceSalePriceSortMethod\n
return high_priority_supply_line_list_len + 3\n
return resourceSalePriceSortKeyMethod\n
\n
\n
def getOptimisedPriceCalculationOperandDict(default=None, context=None, **kw):\n
......@@ -190,13 +160,13 @@ if explanation is not None:\n
\n
# XXX FIXME: Hardcoded values\n
if "Internal" in explanation_type:\n
kw[\'sort_method\'] = getResourceInternalPriceSortMethod(\n
kw[\'sort_key_method\'] = getResourceInternalPriceSortKeyMethod(\n
high_priority_supply_line_list)\n
elif "Purchase" in explanation_type:\n
kw[\'sort_method\'] = getResourcePurchasePriceSortMethod(\n
kw[\'sort_key_method\'] = getResourcePurchasePriceSortKeyMethod(\n
high_priority_supply_line_list)\n
elif "Sale" in explanation_type:\n
kw[\'sort_method\'] = getResourceSalePriceSortMethod(\n
kw[\'sort_key_method\'] = getResourceSalePriceSortKeyMethod(\n
high_priority_supply_line_list)\n
\n
resource = context.getResourceValue()\n
......
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