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