Skip to content

Commit 0bb47a6

Browse files
committed
Minor tweaks to credit card payment summary displays
As suggested by Jordan, centralize the logic in a ProgramAccountingController function. And use a better variable name for the line item type.
1 parent 9133124 commit 0bb47a6

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

esp/esp/accounting/controllers.py

+7
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,13 @@ def remove_pending_transfers(self, users):
278278
we shouldn't be expecting their money. """
279279
self.all_transfers().filter(user__in=users, executed=False).delete()
280280

281+
def payments_summary(self):
282+
""" Return a tuple with the number and total dollar amount of payments
283+
that have been made so far. """
284+
payment_li_type = self.default_payments_lineitemtype()
285+
payments = Transfer.objects.filter(line_item=payment_li_type)
286+
return (payments.count(), payments.aggregate(total=Sum('amount_dec'))['total'])
287+
281288
class IndividualAccountingController(ProgramAccountingController):
282289
def __init__(self, program, user, *args, **kwargs):
283290
super(IndividualAccountingController, self).__init__(program, *args, **kwargs)

esp/esp/program/modules/handlers/creditcardviewer_cybersource.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,14 @@ def viewpay_cybersource(self, request, tl, one, two, module, extra, prog):
6767
payment_table.append((student, iac.get_transfers(), iac.amount_requested(), iac.amount_due()))
6868

6969
# Also fetch summary information about the payments
70-
lt = pac.default_payments_lineitemtype()
71-
payments = Transfer.objects.filter(line_item=lt)
70+
(num_payments, total_payment) = pac.payments_summary()
7271

7372
context = {
7473
'program': prog,
7574
'payment_table': payment_table,
7675
'num_students': len(student_list),
77-
'num_payments': payments.count(),
78-
'total_payment': payments.aggregate(total=Sum('amount_dec'))['total'],
76+
'num_payments': num_payments,
77+
'total_payment': total_payment,
7978
}
8079

8180
return render_to_response(self.baseDir() + 'viewpay_cybersource.html', request, context)

esp/esp/program/modules/handlers/jsondatamodule.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -764,11 +764,11 @@ def student_max_count(clslist):
764764
dictOut["stats"].append({"id": "splashinfo", "data": splashinfo_data})
765765

766766
# Add accounting stats
767-
lt = ProgramAccountingController(prog).default_payments_lineitemtype()
768-
payments = Transfer.objects.filter(line_item=lt)
767+
pac = ProgramAccountingController(prog)
768+
(num_payments, total_payment) = pac.payments_summary()
769769
accounting_data = {
770-
'num_payments': payments.count(),
771-
'total_payments': payments.aggregate(total=Sum('amount_dec'))['total'],
770+
'num_payments': num_payments,
771+
'total_payments': total_payment,
772772
}
773773
dictOut["stats"].append({"id": "accounting", "data": accounting_data})
774774

0 commit comments

Comments
 (0)