Commit 0ad99c2d authored by Jérome Perrin's avatar Jérome Perrin

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

parent bd1f1e04
......@@ -66,6 +66,19 @@ if context.getSource():\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
......
......@@ -68,6 +68,18 @@ if context.getSource():\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
......
......@@ -143,6 +143,8 @@ 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
......@@ -157,6 +159,7 @@ if explanation is not None:\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
......@@ -171,6 +174,9 @@ if explanation is not None:\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
......
......@@ -479,6 +479,24 @@ class TestTradeConditionSupplyLine(TradeConditionTestCase):
# not using the supply line inside trade condition
self.assertEqual(1, line.getPrice())
def test_supply_line_in_other_trade_condition_does_not_apply(self):
"""Supply lines from trade condition not related to an order does not apply.
"""
supply_line = self.trade_condition.newContent(
portal_type=self.supply_line_type,
resource_value=self.resource,
base_price=2)
self.assertEqual(None, self.order.getSpecialiseValue())
self.order.setSourceSectionValue(self.vendor)
self.order.setDestinationSectionValue(self.client)
self.tic()
line = self.order.newContent(portal_type=self.order_line_type,
resource_value=self.resource,
quantity=1)
# not using the supply line inside trade condition
self.assertEqual(None, line.getPrice())
# TODO: move to testSupplyLine ! (which does not exist yet)
def test_supply_line_section(self):
......
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