This works, partially. More information may be needed, however, I thought I would post to get advice on anything obvious that might be wrong here.
The problem is that if activity.get_cost() returns a False
value, the function seems to exit entirely, returning None
.
What I'd like it to do, of course, is accumulate cost
Decimal values in the costs = []
and return their sum. Simple, I would have thought... but my novice Python skills are apparently missing something.
More information provided on request. Thank you.
def get_jobrecord_cost(self):
costs = []
for activity in self.activity_set.all():
cost = activity.get_cost()
if cost:
costs.append(cost)
if len(costs):
return sum(costs)
else:
return False