Virgil Dupras avatar Virgil Dupras committed 5ede904

[#322 state:fixed] Make all transaction go beyond today+ahead-months when needed.

Comments (0)

Files changed (3)

     
     #--- Private
     def _adjust_date_range(self, new_date):
-        if self.date_range.can_navigate:
-            new_date_range = self.date_range.around(new_date)
-            if new_date_range == self.date_range:
-                return False
-        elif isinstance(self.date_range, AllTransactionsRange):
-            if new_date >= self.date_range.start:
-                return False
-            new_date_range = AllTransactionsRange(start=new_date, ahead_months=self.ahead_months)
-        else:
+        new_date_range = self.date_range.adjusted(new_date)
+        if new_date_range is None:
             return False
         # We have to manually set the date range and send notifications because ENTRY_CHANGED
         # must happen between DATE_RANGE_WILL_CHANGE and DATE_RANGE_CHANGED
     def select_all_transactions_range(self):
         if not self.transactions:
             return
-        start_date = self.transactions[0].date
-        self.date_range = AllTransactionsRange(start=start_date, ahead_months=self.ahead_months)
+        first_date = self.transactions[0].date
+        last_date = self.transactions[-1].date
+        self.date_range = AllTransactionsRange(first_date=first_date, last_date=last_date,
+            ahead_months=self.ahead_months)
     
     def select_custom_date_range(self, start_date=None, end_date=None):
         if start_date is not None and end_date is not None:

core/model/date.py

     def __hash__(self):
         return hash((self.start, self.end))
     
+    def adjusted(self, new_date):
+        # Some date ranges change when new transactions are beind added or changed. This is where
+        # it happens. Returns a new adjusted date range or None.
+        return None
+    
     def around(self, date):
         return self
 
     
 
 class NavigableDateRange(DateRange):
+    def adjusted(self, new_date):
+        result = self.around(new_date)
+        if result == self:
+            result = None
+        return result
+    
     def around(self, date):
         return type(self)(date)
     
     
 
 class AllTransactionsRange(DateRange):
-    def __init__(self, start, ahead_months):
-        end = compute_ahead_months(ahead_months)
+    def __init__(self, first_date, last_date, ahead_months):
+        start = first_date
+        end = max(last_date, compute_ahead_months(ahead_months))
         DateRange.__init__(self, start, end)
+        self.ahead_months = ahead_months
+    
+    def adjusted(self, new_date):
+        first_date = min(self.start, new_date)
+        last_date = max(self.end, new_date)
+        result = AllTransactionsRange(first_date=first_date, last_date=last_date,
+            ahead_months=self.ahead_months)
+        if result == self:
+            result = None
+        return result
     
     def prev(self): # for income statement's Last column
         start = self.start - ONE_DAY

core/tests/date_range_test.py

     eq_(app.ttable.row_count, 3)
 
 @with_app(app_all_txns_range_with_one_txn_far_in_the_past)
-def test_includes_ahead_months(app):
-    # All Transactions range end_date is computed using the ahead_months pref
-    dpview = app.show_dpview()
-    dpview.ahead_months_list.select(4) # triggers a date range update
-    app.add_txn('30/04/2010')
-    eq_(app.ttable.row_count, 3)
-    # but not further...
-    app.add_txn('01/05/2010')
+def test_includes_all_future_txns(app):
+    # All Transactions range end_date is computed dynamically using the txn furthest away in the
+    # future.
+    app.add_txn('01/10/2042')
     eq_(app.ttable.row_count, 3)
 
 @with_app(app_all_txns_range_with_one_txn_far_in_the_past)
 def test_transactions_are_shown(app):
     # When under All Transactions range, the range is big enough to contain all txns.
     eq_(app.ttable.row_count, 2)
-
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.