From cb0da24fe66f7e77082148c719983b073210cd17 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=81ukasz=20Nowak?= <luke@nexedi.com>
Date: Thu, 26 Jan 2012 16:36:41 +0100
Subject: [PATCH] Stop generation just bit after current moment.

Generate movement for next period and later rely on re expanding.
---
 product/ERP5/Document/SubscriptionItem.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/product/ERP5/Document/SubscriptionItem.py b/product/ERP5/Document/SubscriptionItem.py
index 5dcdd66d2e..dc42088c24 100644
--- a/product/ERP5/Document/SubscriptionItem.py
+++ b/product/ERP5/Document/SubscriptionItem.py
@@ -39,6 +39,7 @@ from Products.ERP5.mixin.rule import MovementGeneratorMixin
 from Products.ERP5.mixin.periodicity import PeriodicityMixin
 from Products.ERP5Type.UnrestrictedMethod import UnrestrictedMethod
 from Products.ERP5Type.Base import Base
+from DateTime import DateTime
 
 from zLOG import LOG
 
@@ -291,6 +292,7 @@ class SubscriptionItem(Item, CompositionMixin, MovementGeneratorMixin, Periodici
         price_currency = movement.getPriceCurrency()
 
         specialise = movement.getSpecialise()
+        now = DateTime()
         current_date = start_date
         id_index = 0
         while current_date < stop_date:
@@ -313,9 +315,11 @@ class SubscriptionItem(Item, CompositionMixin, MovementGeneratorMixin, Periodici
                                      specialise=specialise,
                                     )
           result.append(generated_movement)
+          if current_date > now:
+            # generate only one movement in advance from today
+            break
           current_date = next_date
           id_index += 1
-          break
 
     return result
 
-- 
2.30.9