Skip to content

Commit 31576fa

Browse files
authored
fixed reports order (#10)
1 parent 5e7f62c commit 31576fa

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

docker-compose.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@ services:
77
- 8000:8000
88
volumes:
99
- ./src:/app/src
10-
- ./htmlcov:/app/htmlcov

src/microinvoicer/views.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
from django_registration.backends.one_step.views import RegistrationView
1313
from dateutil.rrule import rrule, MONTHLY
1414
from django.apps import apps
15+
from decimal import Decimal
1516

1617
from . import forms, models, pdf_rendering, micro_timesheet
1718
from .temporary_locale import TemporaryLocale
18-
from decimal import Decimal
1919

2020

2121
class IndexView(TemplateView):
@@ -77,6 +77,23 @@ def get_context_data(self, **kwargs):
7777

7878
# build up the monthly / quartery / yearly total
7979
totals = dict()
80+
if invoices:
81+
# fill in all spots between first and last invoice in reverse order
82+
since = invoices.last().issue_date.replace(day=1)
83+
until = invoices.first().issue_date.replace(day=1)
84+
all_months = list(rrule(freq=MONTHLY, dtstart=since, until=until, bymonthday=1))
85+
for every_month in reversed(all_months):
86+
year = every_month.year
87+
quarter = models.quarter_of(every_month)
88+
month = every_month.month
89+
90+
if year not in totals:
91+
totals[year] = dict(total=0)
92+
if quarter not in totals[year]:
93+
totals[year][quarter] = dict(total=0)
94+
if month not in totals[year][quarter]:
95+
totals[year][quarter][month] = dict(total=0, count=0, date=every_month)
96+
8097
for invoice in invoices:
8198
year = invoice.issue_date.year
8299
quarter = models.quarter_of(invoice.issue_date)
@@ -100,22 +117,6 @@ def get_context_data(self, **kwargs):
100117
total_year[quarter] = total_quarter
101118
totals[year] = total_year
102119

103-
if invoices:
104-
# fill in missing spots between first and last invoice
105-
since = invoices.last().issue_date.replace(day=1)
106-
until = invoices.first().issue_date.replace(day=1)
107-
for every_month in rrule(freq=MONTHLY, dtstart=since, until=until, bymonthday=1):
108-
year = every_month.year
109-
quarter = models.quarter_of(every_month)
110-
month = every_month.month
111-
112-
if year not in totals:
113-
totals[year] = dict(total=0)
114-
if quarter not in totals[year]:
115-
totals[year][quarter] = dict(total=0)
116-
if month not in totals[year][quarter]:
117-
totals[year][quarter][month] = dict(total=0, count=0, date=every_month)
118-
119120
context["totals"] = totals
120121

121122
return context

0 commit comments

Comments
 (0)