Commit 30b5aec5 authored by Jérome Perrin's avatar Jérome Perrin Committed by Xiaowu Zhang

pdm/trade: make price from trade conditions only apply if the trade condition is used in this order

(cherry picked from commit 0ad99c2d)
Conflicts:
	product/ERP5/tests/testTradeCondition.py
parent 85da1275
......@@ -48,6 +48,56 @@
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>if context.getParentValue().getParentValue().getPortalType() not in context.getPortalResourceTypeList() \\\n
and getattr(context, \'getValidationState\', lambda: "")() in (\'invalidated\', \'deleted\', \'draft\'):\n
# If this supply cell is contained in a supply or trade condition that is not validated, it does not apply.\n
return None\n
\n
base_category_tuple = (\'resource\', \'price_currency\')\n
\n
if context.getSourceSection():\n
base_category_tuple += (\'source_section\',)\n
if context.getDestinationSection():\n
base_category_tuple += (\'destination_section\',)\n
if context.getSource():\n
base_category_tuple += (\'source\',)\n
if context.getDestination():\n
base_category_tuple += (\'destination\',)\n
\n
if context.getParentValue().getParentValue().getPortalType() in (\n
## XXX There is no portal type group for trade conditions.\n
\'Sale Trade Condition\',\n
\'Purchase Trade Condition\',\n
\'Internal Trade Condition\'):\n
# Supply Lines from trade conditions are set as specialise to this trade condition,\n
# so that we can apply a predicate on movements later. Supply Lines from trade condition\n
# only apply on movements using these trade conditions.\n
category_list = context.getCategoryList() + [\'specialise/%s\' % context.getParentValue().getParentValue().getRelativeUrl()]\n
context = context.asContext(categories=category_list)\n
base_category_tuple += (\'specialise\', )\n
\n
\n
#backwards compatibility\n
mapped_value_property_list = context.getMappedValuePropertyList()\n
if not \'priced_quantity\' in mapped_value_property_list:\n
mapped_value_property_list.append(\'priced_quantity\')\n
context.setMappedValuePropertyList(mapped_value_property_list)\n
\n
# XXX: An hack that the context cell may not have the start_date_range_min/max properties.\n
# But they don\'t acquire it parent the properties.\n
# Correctly, the cell must acquire the properties.\n
if (context.getStartDateRangeMin() == None and\n
context.getStartDateRangeMax() == None):\n
supply_line = context.getParentValue()\n
context = context.asContext(start_date_range_min=supply_line.getStartDateRangeMin(),\n
start_date_range_max=supply_line.getStartDateRangeMax())\n
\n
return context.generatePredicate(membership_criterion_base_category_list = base_category_tuple,\n
criterion_property_list = (\'start_date\',))\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>*args,**kw</string> </value>
......
......@@ -48,6 +48,48 @@
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>if context.getParentValue().getPortalType() not in context.getPortalResourceTypeList() \\\n
and getattr(context, \'getValidationState\', lambda: "")() in (\'invalidated\', \'deleted\', \'draft\'):\n
# If this supply line is contained in a supply or trade condition that is not validated, it does not apply.\n
return None\n
\n
\n
base_category_tuple = (\'resource\', \'price_currency\')\n
\n
if context.getSourceSection():\n
base_category_tuple += (\'source_section\',)\n
if context.getDestinationSection():\n
base_category_tuple += (\'destination_section\',)\n
\n
if context.getSource():\n
base_category_tuple += (\'source\',)\n
if context.getDestination():\n
base_category_tuple += (\'destination\',)\n
\n
if context.getParentValue().getPortalType() in (\n
## XXX There is no portal type group for trade conditions.\n
\'Sale Trade Condition\',\n
\'Purchase Trade Condition\',\n
\'Internal Trade Condition\'):\n
# Supply Lines from trade conditions are set as specialise to this trade condition,\n
# so that we can apply a predicate on movements later. Supply Lines from trade condition\n
# only apply on movements using these trade conditions.\n
category_list = context.getCategoryList() + [\'specialise/%s\' % context.getParentValue().getRelativeUrl()]\n
context = context.asContext(categories=category_list)\n
base_category_tuple += (\'specialise\', )\n
\n
#backwards compatibility\n
mapped_value_property_list = context.getMappedValuePropertyList()\n
if not \'priced_quantity\' in mapped_value_property_list:\n
mapped_value_property_list.append(\'priced_quantity\')\n
context.setMappedValuePropertyList(mapped_value_property_list)\n
\n
return context.generatePredicate(membership_criterion_base_category_list = base_category_tuple,\n
criterion_property_list = (\'start_date\',))\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>*args,**kw</string> </value>
......
......@@ -48,6 +48,146 @@
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<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 high_priority_supply_line_list_len + 1\n
else:\n
if a.getSourceSection():\n
return high_priority_supply_line_list_len + 2\n
else:\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 high_priority_supply_line_list_len + 1\n
else:\n
if a.getDestinationSection():\n
return high_priority_supply_line_list_len + 2\n
else:\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 high_priority_supply_line_list_len + 1\n
else:\n
if a.getSourceSection():\n
return high_priority_supply_line_list_len + 2\n
else:\n
return high_priority_supply_line_list_len + 3\n
return resourceSalePriceSortKeyMethod\n
\n
\n
def getOptimisedPriceCalculationOperandDict(default=None, context=None, **kw):\n
"""\n
Price Method optimised by the preference \n
"""\n
movement_portal_type = context.portal_type\n
preferences = context.portal_preferences\n
supply_portal_type_list = []\n
if movement_portal_type in context.getPortalSaleTypeList():\n
supply_portal_type_list = preferences.getPreferredSaleMovementSupplyPathTypeList()\n
elif movement_portal_type in context.getPortalPurchaseTypeList():\n
supply_portal_type_list = preferences.getPreferredPurchaseMovementSupplyPathTypeList()\n
elif movement_portal_type in context.getPortalInternalTypeList():\n
supply_portal_type_list = preferences.getPreferredInternalMovementSupplyPathTypeList()\n
if supply_portal_type_list:\n
supply_kw = dict(portal_type=supply_portal_type_list)\n
for key in preferences.getPreferredPricingSupplyPathKeyCategoryList():\n
key_uid = \'%s_uid\' % key\n
supply_kw[\'default_%s\' % key_uid] = context.getProperty(key_uid)\n
supply_uid_list = [str(brain.uid) for brain in context.portal_catalog(**supply_kw)]\n
if len(supply_uid_list):\n
kw[\'query\'] = \' catalog.uid IN (%s)\' % \',\'.join(supply_uid_list)\n
else:\n
return default\n
return resource.getPriceCalculationOperandDict(default=default, context=context, **kw)\n
\n
def isPricingOptimise():\n
"""Check whether pricing optimisation is enabled or not """\n
try:\n
return context.portal_preferences.getPreferredPricingOptimise()\n
except AttributeError:\n
# When the preference is not support the property, for instance, old sites\n
return False\n
\n
try:\n
explanation = context.getExplanationValue()\n
except AttributeError:\n
# Sometime, movements doesn\'t have an explanation.\n
explanation = None\n
\n
specialise_set = set()\n
\n
if explanation is not None:\n
explanation_type = explanation.getPortalType()\n
high_priority_supply_line_list = []\n
if explanation_type in context.getPortalInvoiceTypeList() +\\\n
context.getPortalOrderTypeList() + context.getPortalDeliveryTypeList():\n
# if there are trade conditions containing supply lines related to that\n
# order/invoice, we give high priority to those supply lines\n
for supply_line in explanation.asComposedDocument().objectValues(portal_type=context.getPortalSupplyPathTypeList()):\n
supply_cell_list = supply_line.objectValues(\n
portal_type=context.getPortalSupplyPathTypeList())\n
if supply_cell_list:\n
high_priority_supply_line_list.extend(list(supply_cell_list))\n
else:\n
high_priority_supply_line_list.append(supply_line)\n
specialise_set.add(supply_line.getParentValue().getRelativeUrl())\n
\n
# XXX FIXME: Hardcoded values\n
if "Internal" in explanation_type:\n
kw[\'sort_key_method\'] = getResourceInternalPriceSortKeyMethod(\n
high_priority_supply_line_list)\n
elif "Purchase" in explanation_type:\n
kw[\'sort_key_method\'] = getResourcePurchasePriceSortKeyMethod(\n
high_priority_supply_line_list)\n
elif "Sale" in explanation_type:\n
kw[\'sort_key_method\'] = getResourceSalePriceSortKeyMethod(\n
high_priority_supply_line_list)\n
\n
resource = context.getResourceValue()\n
\n
if specialise_set:\n
kw[\'categories\'] = kw.get(\'categories\', []) + [\'specialise/%s\' % x for x in specialise_set]\n
\n
if resource is not None:\n
if isPricingOptimise():\n
return getOptimisedPriceCalculationOperandDict(default=default, context=context, **kw)\n
else:\n
r = resource.getPriceCalculationOperandDict(\n
default=default, context=context, **kw)\n
return r\n
\n
return default\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>default=None, **kw</string> </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