diff options
Diffstat (limited to 'ihatemoney/models.py')
| -rw-r--r-- | ihatemoney/models.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/ihatemoney/models.py b/ihatemoney/models.py index 250f009..8a7e273 100644 --- a/ihatemoney/models.py +++ b/ihatemoney/models.py @@ -95,6 +95,18 @@ class Project(db.Model): ] @property + def monthly_stats(self): + """Compute expenses by month + + :return: a dict of years mapping to a dict of months mapping to the amount + :rtype dict: + """ + monthly = defaultdict(lambda: defaultdict(float)) + for bill in self.get_bills().all(): + monthly[bill.date.year][bill.date.month] += bill.amount + return monthly + + @property def uses_weights(self): return len([i for i in self.members if i.weight != 1]) > 0 |
