diff options
| author | Edwin Smulders <edwin.smulders@gmail.com> | 2020-02-09 13:03:52 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-02-09 13:03:52 +0100 |
| commit | 02242f2e12e98ebad7e3c401cfa3b31d7bb651cc (patch) | |
| tree | 122e8b1a43f092adcf9c734238089c8fe1f001dc /ihatemoney/models.py | |
| parent | bf691660ee52073cfca5b32ed833553e9fe3a171 (diff) | |
| download | ihatemoney-mirror-02242f2e12e98ebad7e3c401cfa3b31d7bb651cc.zip ihatemoney-mirror-02242f2e12e98ebad7e3c401cfa3b31d7bb651cc.tar.gz ihatemoney-mirror-02242f2e12e98ebad7e3c401cfa3b31d7bb651cc.tar.bz2 | |
Initial montly expenses (#526)
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 |
