#NEWLINE# def form_valid( self , form ) : #NEWLINE# #INDENT# threshold_date = ( form . cleaned_data [ 'date' ] + datetime . timedelta ( days = 1 ) ) #NEWLINE# threshold_datetime = datetime . datetime . combine ( threshold_date , datetime . time ( tzinfo = timezone . utc ) ) #NEWLINE# rows = [ ] #NEWLINE# totals = { #NEWLINE# #INDENT# 'total' : D ( '0.00' ) , #NEWLINE# 'num_accounts' : 0 , #NEWLINE# #UNINDENT# } #NEWLINE# for acc_type_name in names . DEFERRED_INCOME_ACCOUNT_TYPES : #NEWLINE# #INDENT# acc_type = AccountType . objects . get ( name = acc_type_name ) #NEWLINE# data = { #NEWLINE# #INDENT# 'name' : acc_type_name , #NEWLINE# 'total' : D ( '0.00' ) , #NEWLINE# 'num_accounts' : 0 , #NEWLINE# 'num_expiring_within_30' : 0 , #NEWLINE# 'num_expiring_within_60' : 0 , #NEWLINE# 'num_expiring_within_90' : 0 , #NEWLINE# 'num_expiring_outside_90' : 0 , #NEWLINE# 'num_open_ended' : 0 , #NEWLINE# 'total_expiring_within_30' : D ( '0.00' ) , #NEWLINE# 'total_expiring_within_60' : D ( '0.00' ) , #NEWLINE# 'total_expiring_within_90' : D ( '0.00' ) , #NEWLINE# 'total_expiring_outside_90' : D ( '0.00' ) , #NEWLINE# 'total_open_ended' : D ( '0.00' ) , #NEWLINE# #UNINDENT# } #NEWLINE# for account in acc_type . accounts . all ( ) : #NEWLINE# #INDENT# data [ 'num_accounts' ] += 1 #NEWLINE# total = account . transactions . filter ( date_created__lt = threshold_datetime ) . aggregate ( total = Sum ( 'amount' ) ) [ 'total' ] #NEWLINE# if ( total is None ) : #NEWLINE# #INDENT# total = D ( '0.00' ) #NEWLINE# #UNINDENT# data [ 'total' ] += total #NEWLINE# days_remaining = account . days_remaining ( threshold_datetime ) #NEWLINE# if ( days_remaining is None ) : #NEWLINE# #INDENT# data [ 'num_open_ended' ] += 1 #NEWLINE# data [ 'total_open_ended' ] += total #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( days_remaining <= 30 ) : #NEWLINE# #INDENT# data [ 'num_expiring_within_30' ] += 1 #NEWLINE# data [ 'total_expiring_within_30' ] += total #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( days_remaining <= 60 ) : #NEWLINE# #INDENT# data [ 'num_expiring_within_60' ] += 1 #NEWLINE# data [ 'total_expiring_within_60' ] += total #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( days_remaining <= 90 ) : #NEWLINE# #INDENT# data [ 'num_expiring_within_90' ] += 1 #NEWLINE# data [ 'total_expiring_within_90' ] += total #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# data [ 'num_expiring_outside_90' ] += 1 #NEWLINE# data [ 'total_expiring_outside_90' ] += total #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# totals [ 'total' ] += data [ 'total' ] #NEWLINE# totals [ 'num_accounts' ] += data [ 'num_accounts' ] #NEWLINE# rows . append ( data ) #NEWLINE# #UNINDENT# ctx = self . get_context_data ( form = form ) #NEWLINE# ctx [ 'rows' ] = rows #NEWLINE# ctx [ 'totals' ] = form #NEWLINE# ctx [ 'report_date' ] = form . cleaned_data [ 'date' ] #NEWLINE# return self . render_to_response ( ctx )