diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index c8ed951a0..d84727569 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -194,6 +194,22 @@ def template_usage(service_id): get_monthly_template_stats(month, stats) for month in get_months_for_financial_year(year, time_format="%B") ] + months.reverse() + + # Get the year from stats + # If the year is this year, remove months in the future + if len(stats) > 0: + stat_year = stats[0]["year"] + current_year = datetime.now().year + current_month_num = datetime.now().month + new_months = [] + if stat_year == current_year: + for m in months: + + month_num_full = datetime.strptime(m["name"], "%B").month + if month_num_full <= current_month_num: + new_months.append(m) + months = new_months return render_template( "views/dashboard/all-template-statistics.html", diff --git a/tests/app/main/views/test_dashboard.py b/tests/app/main/views/test_dashboard.py index dbabba8a8..a474c5eaf 100644 --- a/tests/app/main/views/test_dashboard.py +++ b/tests/app/main/views/test_dashboard.py @@ -410,7 +410,7 @@ def test_should_not_show_recent_templates_on_dashboard_if_only_one_template_used assert expected_count == 50, f"Expected count to be 50, but got {expected_count}" -@freeze_time("2017-01-01 12:00") +@freeze_time("2017-12-01 12:00") @pytest.mark.parametrize( "extra_args", [