From 86d2ee9a3a0395310c99d8714f53fb7d028ebfc5 Mon Sep 17 00:00:00 2001
From: Yusei Tahara <yusei@nexedi.com>
Date: Fri, 28 May 2010 03:59:26 +0000
Subject: [PATCH] Retrieve start_date and stop_date from movement and stop
 expanding when reaching to the end date.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@35696 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5Legacy/Document/OpenOrderRule.py | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/product/ERP5Legacy/Document/OpenOrderRule.py b/product/ERP5Legacy/Document/OpenOrderRule.py
index e20b6d21b9..6443376eb3 100644
--- a/product/ERP5Legacy/Document/OpenOrderRule.py
+++ b/product/ERP5Legacy/Document/OpenOrderRule.py
@@ -70,14 +70,22 @@ class OpenOrderRule(DeliveryRule):
       order_movement_list = order.getMovementList(
         portal_type=order.getPortalOrderMovementTypeList())
 
+      now = DateTime()
       for order_movement in order_movement_list:
+        end_date = order_movement.getStopDate() - order.getForecastingTermDayCount()
+        if end_date > now:
+          calculation_base_date = now
+        else:
+          calculation_base_date = end_date
         last_simulation_movement = self._getLastSimulationMovementValue(applied_rule, order_movement)
         if last_simulation_movement is not None:
           schedule_start_date = last_simulation_movement.getStartDate()
-          schedule_list = self._getOrderDateScheduleTupleList(order_movement, schedule_start_date, **kw)
+          schedule_list = self._getOrderDateScheduleTupleList(order_movement, schedule_start_date,
+                                                              calculation_base_date=calculation_base_date,
+                                                              **kw)
         else:
           # Because order's start_date might be matched with the periodicity.
-          order_start_date = order.getStartDate()
+          order_start_date = order_movement.getStartDate()
           schedule_start_date = order_start_date-1
           schedule_list = [date_pair
                            for date_pair in self._getOrderDateScheduleTupleList(order_movement, schedule_start_date, **kw)
-- 
2.30.9