Example #1
0
def overduereport(request):
    help_text = """The overdue report allows you to get an overview of contributors that are overdue. That means, we
    expected a donation from them, but haven't received one yet. For example if a contributor that donates every year
    was expected to pay two weeks ago, you can set the 'Maximum number of days' parameter to 13 and see the contributor pop up
    in the report. It's up to you to choose how many days you allow contributors to be overdue before contacting them.
    There are a couple of things you should bear in mind: (1) contributors that contribute on a sporadic
    basis are excluded from this report (2) only "recurrent" payments are considered. "single" payments are not taken
    into account and (3) 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': 'Overdue Report', 'values': []}
    msg = 'Please fill in a maximum number of days overdue.'
    if request.method == 'POST':
        max_days_till_next_payment= request.POST.get('maximum_number_of_days', '')
        if max_days_till_next_payment!= '':
            msg = ''
            report = OverdueReport()
            values = report.getReportingValues(allowed_overdue_days=max_days_till_next_payment, include_address=False)
            if request.POST.get('action') == 'download':
                response = HttpResponse(content_type='text/csv')
                response['Content-Disposition'] = 'attachment; filename="overdue_{0}_report.csv"'.format(max_days_till_next_payment)
                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)
Example #2
0
 def test_overdue(self):
     """
     contributor 2 is overdue and should show up in the results
     """
     overdue_rep = OverdueReport()
     res = overdue_rep.getReportingValues(allowed_overdue_days=5, _reference_date=self.reference_date)
     self.assertEqual(len(res['values']), 1)
     self.assertEqual(res['values'][0][1], 'marie evers')
     self.assertEqual(res['values'][0][7], -6) # this is the days until next expected payment. Based on previous expected date and payment frequency.
     res = overdue_rep.getReportingValues(allowed_overdue_days=7, _reference_date=self.reference_date)
     self.assertAlmostEqual(len(res['values']), 0) # contributor 2 is now excluded
     new_payment = Payment(amount=45, contributor=self.contributor2, date=self.reference_date - relativedelta(days=4), entitled='entitled', ptype='single')
     new_payment.save()
     res = overdue_rep.getReportingValues(allowed_overdue_days=5, _reference_date=self.reference_date)
     self.assertEqual(len(res['values']), 1) # new payment for contributor 2 is ignored because ptype="single". Contributor 2 is still overdue
     self.assertEqual(res['values'][0][1], 'marie evers')