def test_reminder(self): """ contributor 1 should be excluded: monthly payer contributor 2 is overdue so should be excluded from the reminders report contributor 3 should pay in 15 days (based on the expected date from his last payment!) contributor 4 pays sporadic so should be excluded """ reminders_rep = RemindersReport() res = reminders_rep.getReportingValues(max_days_till_next_payment=20, _reference_date=self.reference_date) self.assertEqual(len(res['values']), 1) self.assertEqual(res['values'][0][1], 'harvey jones') res = reminders_rep.getReportingValues(max_days_till_next_payment=14, _reference_date=self.reference_date) self.assertEqual(len(res['values']), 0)
def remindersreport(request): help_text = """The reminders report allows you to get an overview of contributors that are expected to donate in the near future. You can define the upper limit of "near future" yourself by setting the "Maximum number of days" paramter. For example if a contributor that donates every year is expected to pay within two weeks, you can set the "Maximum number of days" parameter to 15 and see the contributor pop up in the report. These contributors should receive a reminder. There are a couple of things you should bear in mind: (1) contributors that contribute on a sporadic basis, or contributors that pay every month are excluded from this report (2) contributors that are overdue will also not be shown here (they will appear in the overdue report) and (3) only "recurrent" payments are considered. "single" payments are not taken into account. (4) you should know that the system looks at the "expected date" of a payment, if this is set. So not the actual payment date.""" values = {'report_name': 'Reminders Report', 'values': []} msg = 'Please fill in a maximum number of days until the next expected payment.' if request.method == 'POST': days_til_next = request.POST.get('maximum_number_of_days', '') if days_til_next != '': msg = '' report = RemindersReport() values = report.getReportingValues(max_days_till_next_payment=days_til_next) if request.POST.get('action') == 'download': response = HttpResponse(content_type='text/csv') response['Content-Disposition'] = 'attachment; filename="reminders_{0}_report.csv"'.format(days_til_next) writer = csv.writer(response) writer.writerow(values['fields']) writer.writerows(values['values']) return response context_data = { "report": values, "app_label": "simplereports", "max_days_form": OverdueReportForm(), "help_text": help_text } if msg: context_data['errors'] = msg context = RequestContext(request, context_data) return render_to_response("overdue_report.html", context)