Commit 7193b12d authored by Jérome Perrin's avatar Jérome Perrin

trade: Consider movement dates to select trade condition for price

using movement date rather than order date is more correct
parent 5d929056
...@@ -604,6 +604,44 @@ class TestTradeConditionSupplyLine(TradeConditionTestCase): ...@@ -604,6 +604,44 @@ class TestTradeConditionSupplyLine(TradeConditionTestCase):
resource_value=self.resource, resource_value=self.resource,
quantity=1).getPrice(), 3) quantity=1).getPrice(), 3)
def test_supply_line_from_effective_trade_condition_apply_based_on_movement_date(self):
self.trade_condition.setReference(self.id())
self.trade_condition.setExpirationDate(DateTime(1999, 12, 31))
self.trade_condition.newContent(
portal_type=self.supply_line_type,
resource_value=self.resource,
base_price=2,
)
another_trade_condition = self.trade_condition_module.newContent(
portal_type=self.trade_condition_type,
effective_date=DateTime(2000, 1, 1),
reference=self.id(),
)
another_trade_condition.newContent(
portal_type=self.supply_line_type,
resource_value=self.resource,
base_price=3,
)
another_trade_condition.validate()
self.tic()
self.order.setSpecialiseValue(self.trade_condition)
self.assertEqual(
self.order.newContent(
portal_type=self.order_line_type,
start_date=DateTime(1999, 1, 1),
resource_value=self.resource,
quantity=1).getPrice(), 2)
self.assertEqual(
self.order.newContent(
portal_type=self.order_line_type,
start_date=DateTime(2001, 1, 1),
resource_value=self.resource,
quantity=1).getPrice(), 3)
# TODO: move to testSupplyLine ! (which does not exist yet) # TODO: move to testSupplyLine ! (which does not exist yet)
def test_supply_line_section(self): def test_supply_line_section(self):
# if a supply lines defines a section, it has priority over supply lines # if a supply lines defines a section, it has priority over supply lines
......
...@@ -103,7 +103,10 @@ if explanation is not None: ...@@ -103,7 +103,10 @@ if explanation is not None:
# if there are trade conditions containing supply lines related to that # if there are trade conditions containing supply lines related to that
# order/invoice, we give high priority to those supply lines # order/invoice, we give high priority to those supply lines
try: try:
composed_document = explanation.asComposedDocument() composed_document = explanation.asContext(
start_date=context.getStartDate(),
stop_date=context.getStopDate(),
).asComposedDocument()
except KeyError: except KeyError:
pass pass
else: else:
......
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