From 02242f2e12e98ebad7e3c401cfa3b31d7bb651cc Mon Sep 17 00:00:00 2001 From: Edwin Smulders Date: Sun, 9 Feb 2020 13:03:52 +0100 Subject: Initial montly expenses (#526) --- ihatemoney/models.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'ihatemoney/models.py') 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 -- cgit v1.1