-
Notifications
You must be signed in to change notification settings - Fork 0
/
financers.py
39 lines (31 loc) · 1.14 KB
/
financers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import citizens
class Financers(citizens.Citizens):
def cumulative_donation(self, amount):
self.total_donated += amount
def donate(self, percentage=None, amount=None):
if amount is None:
# Donate percentage of income
self.cumulative_donation(self.income * percentage)
r = self.income * percentage
self.income -= self.income * percentage
return r
else:
if self.income >= amount:
self.cumulative_donation(amount)
self.income -= amount
return amount
else:
r = self.income
self.income = 0
return r
def get_cumulative_donation(self):
return self.total_donated
def reset_total_donated(self):
self.total_donated = 0
@classmethod
def convert_to_donor(cls, obj):
# if obj.__class__ == Candidates:
# print('Another donor who is a candidate')
obj.__class__ = Financers
def __str__(self):
return 'Doador {} Renda {:.2f} Total doado {:.4f}'.format(self.id, self.income, self.total_donated)