python models: Implement Supporter.supperter_type() with filters.

This commit is contained in:
Brett Smith 2017-02-17 15:24:40 -05:00
parent 8481bbf3b9
commit 2b1bdb073d

View file

@ -112,12 +112,12 @@ class Supporter:
return expose_wrapper
def _supporter_type(self, payments):
for payment in payments.reverse():
if payment.program is not None:
break
else:
try:
program = payments.filter(program__isnull=False).reverse()[0].program
except IndexError:
return None
return payment.program.rsplit(':', 1)[-1]
else:
return program.rsplit(':', 1)[-1]
supporter_type = _expose(_supporter_type)
def _calculate_lapse_date(self, last_payment_date, supporter_type):