Skip to content

Commit 39e06db

Browse files
committed
chore: update dashboard tiles
chore: cleanup chore: cleanup chore: cleanup chore: cleanup chore: cleanup chore: cleanup chore: cleanup chore: cleanup
1 parent 0674d0b commit 39e06db

13 files changed

Lines changed: 223 additions & 123 deletions

File tree

bc_obps/common/fixtures/dashboard/bciers/external.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,11 @@
177177
],
178178
"links": [
179179
{
180-
"title": "View Annual Reports",
180+
"title": "Current Reporting Year",
181181
"href": "/reporting/reports/current-reports"
182182
},
183183
{
184-
"title": "View Past Reports",
184+
"title": "Previous Reporting Years",
185185
"href": "/reporting/reports/previous-years"
186186
}
187187
]
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from django.db import migrations
2+
3+
4+
def load_dashboard_fixtures(apps, schema_editor):
5+
from django.core.management import call_command
6+
7+
fixture_files = [
8+
'common/fixtures/dashboard/bciers/external.json',
9+
'common/fixtures/dashboard/bciers/internal.json',
10+
'common/fixtures/dashboard/operators/internal.json',
11+
]
12+
13+
# Delete all existing DashboardData objects
14+
DashboardData = apps.get_model('common', 'DashboardData')
15+
DashboardData.objects.all().delete()
16+
17+
# Load the fixtures
18+
for fixture in fixture_files:
19+
call_command('loaddata', fixture)
20+
21+
22+
class Migration(migrations.Migration):
23+
24+
dependencies = [
25+
('common', '0130_V5_15_0'),
26+
]
27+
28+
operations = [
29+
migrations.RunPython(load_dashboard_fixtures, elidable=True),
30+
]

bc_obps/reporting/api/reports.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from reporting.constants import EMISSIONS_REPORT_TAGS
1111
from reporting.schema.generic import Message
1212
from reporting.schema.report import StartReportIn, CreateReportVersionIn, CreateReportForReportingYearIn
13-
from service.report_service import ReportService
13+
from service.report_service import CreateReportForReportingYearData, ReportService
1414
from service.report_version_service import ReportVersionService, ReportVersionData
1515
from service.reporting_year_service import ReportingYearService
1616
from service.error_service.custom_codes_4xx import custom_codes_4xx
@@ -55,9 +55,14 @@ def create_report_for_reporting_year(
5555
request: HttpRequest,
5656
payload: CreateReportForReportingYearIn,
5757
) -> Tuple[Literal[201], int]:
58+
data = CreateReportForReportingYearData(
59+
operation_id=payload.operation_id,
60+
reporting_year=payload.reporting_year,
61+
registration_purpose=payload.registration_purpose,
62+
)
5863
report_version_id = ReportService.create_report_for_reporting_year(
5964
user_guid=get_current_user_guid(request),
60-
data=payload,
65+
data=data,
6166
)
6267

6368
return 201, report_version_id

bc_obps/reporting/tests/service/test_reporting_year_service.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,27 @@ def test_get_reporting_year_by_version_id(self):
3838
report_version = make_recipe('reporting.tests.utils.report_version', report=report)
3939
reporting_year = ReportingYearService.get_reporting_year_by_version_id(report_version.id)
4040
assert reporting_year == self.reporting_year
41+
42+
@patch("service.reporting_year_service.ReportingYearService.get_current_reporting_year")
43+
def test_get_previous_reporting_years(self, mock_get_current_reporting_year):
44+
# Arrange
45+
for year in [2023, 2024, 2025]:
46+
ReportingYear.objects.get_or_create(
47+
reporting_year=year,
48+
defaults={
49+
"reporting_window_start": f"{year + 1}-01-01T00:00:00.000Z",
50+
"reporting_window_end": f"{year + 1}-12-31T23:59:59.999Z",
51+
"report_due_date": f"{year + 1}-05-31T23:59:59.999Z",
52+
"description": f"{year} reporting year",
53+
},
54+
)
55+
56+
mock_get_current_reporting_year.return_value = ReportingYear(
57+
reporting_year=2025,
58+
)
59+
60+
# Act
61+
reporting_years = ReportingYearService.get_previous_reporting_years()
62+
63+
# Assert
64+
assert list(reporting_years.values_list("reporting_year", flat=True)) == [2024]

bc_obps/service/operation_service.py

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
class OperationService:
6565

6666
OPERATION_DEFAULT_START_DATE = datetime(2024, 1, 1, tzinfo=ZoneInfo("America/Vancouver"))
67-
MIN_REPORTING_YEAR = 2024
6867

6968
@classmethod
7069
def get_if_authorized(
@@ -770,6 +769,8 @@ def get_valid_operation_regulated_products(operation: Operation, reporting_year:
770769
return operation.regulated_products.filter(
771770
valid_from__lte=reporting_year_date, valid_to__gte=reporting_year_date
772771
)
772+
773+
@staticmethod
773774
def _is_reportable_operation_year(
774775
operation_year: tuple[UUID, int],
775776
added_operation_years: set[tuple[UUID, int]],
@@ -788,21 +789,6 @@ def _is_designated_to_user_operator(
788789
and designated_operator_timeline.operator.id == user_operator.operator_id
789790
)
790791

791-
@classmethod
792-
def _get_previous_reporting_years(cls) -> QuerySet[ReportingYear]:
793-
"""
794-
Returns reporting years that are eligible for the Start Past Report workflow
795-
796-
Only reporting years from MIN_REPORTING_YEAR up to (but not including) the current
797-
reporting year are returned.
798-
"""
799-
current_reporting_year = ReportingYearService.get_current_reporting_year()
800-
801-
return ReportingYear.objects.filter(
802-
reporting_year__gte=cls.MIN_REPORTING_YEAR,
803-
reporting_year__lt=current_reporting_year.reporting_year,
804-
).order_by("-reporting_year")
805-
806792
@staticmethod
807793
def _get_registration_purposes_for_operation_type(
808794
operation_type: str,
@@ -887,7 +873,7 @@ def list_previous_reportable_operations(
887873

888874
user_operator = UserDataAccessService.get_user_operator_by_user(user_guid)
889875

890-
reporting_years = cls._get_previous_reporting_years()
876+
reporting_years = ReportingYearService.get_previous_reporting_years()
891877
year_values = {reporting_year.reporting_year for reporting_year in reporting_years}
892878

893879
timelines = list(

bc_obps/service/report_service.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818
from service.facility_report_service import FacilityReportService, SaveFacilityReportData
1919
from typing import Any, List, Optional
2020
from service.data_access_service.user_service import UserDataAccessService
21+
from dataclasses import dataclass
22+
23+
24+
@dataclass(frozen=True)
25+
class CreateReportForReportingYearData:
26+
operation_id: UUID
27+
reporting_year: int
28+
registration_purpose: str
2129

2230

2331
class SaveReportOperationData:
@@ -89,7 +97,7 @@ def create_report(cls, operation_id: UUID, reporting_year: int) -> int:
8997
def create_report_for_reporting_year(
9098
cls,
9199
user_guid: UUID,
92-
data: Any,
100+
data: CreateReportForReportingYearData,
93101
) -> int:
94102
operation_id = data.operation_id
95103
reporting_year = data.reporting_year
@@ -115,7 +123,7 @@ def create_report_for_reporting_year(
115123
# the designated operator for the selected reporting year
116124
if designated_operator_timeline.operator.id != user_operator.operator_id:
117125
raise UserError(
118-
f"This operation was owned by another operation in {reporting_year}, "
126+
f"This operation was owned by another operator in {reporting_year}, "
119127
"you do not need to report on this operation. "
120128
"If you believe this is incorrect, please contact ghgregulator@gov.bc.ca."
121129
)

bc_obps/service/reporting_year_service.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77

88
class ReportingYearService:
9+
MIN_REPORTING_YEAR = 2024
10+
911
@classmethod
1012
def get_current_reporting_year(cls) -> ReportingYear:
1113
now = timezone.now()
@@ -43,3 +45,18 @@ def get_report_reporting_year(cls, report_id: int) -> ReportingYear:
4345
def get_reporting_year_by_version_id(cls, version_id: int) -> ReportingYear:
4446
report_version = ReportVersion.objects.get(id=version_id)
4547
return report_version.report.reporting_year
48+
49+
@classmethod
50+
def get_previous_reporting_years(cls) -> QuerySet[ReportingYear]:
51+
"""
52+
Returns reporting years that are eligible for the Start Past Report workflow
53+
54+
Only reporting years from MIN_REPORTING_YEAR up to (but not including) the current
55+
reporting year are returned.
56+
"""
57+
current_reporting_year = cls.get_current_reporting_year()
58+
59+
return ReportingYear.objects.filter(
60+
reporting_year__gte=cls.MIN_REPORTING_YEAR,
61+
reporting_year__lt=current_reporting_year.reporting_year,
62+
).order_by("-reporting_year")

bc_obps/service/tests/operation_service/test_operation_service_reportable.py

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,6 @@ def test_is_reportable_operation_year():
1818
assert OperationService._is_reportable_operation_year(operation_year, {operation_year}, set()) is False
1919
assert OperationService._is_reportable_operation_year(operation_year, set(), {operation_year}) is False
2020

21-
@staticmethod
22-
@patch("service.reporting_year_service.ReportingYearService.get_current_reporting_year")
23-
def test_get_previous_reporting_years(mock_get_current_reporting_year: MagicMock):
24-
baker.make_recipe("reporting.tests.utils.reporting_year", reporting_year=2091)
25-
baker.make_recipe("reporting.tests.utils.reporting_year", reporting_year=2092)
26-
current_year = baker.make_recipe(
27-
"reporting.tests.utils.reporting_year",
28-
reporting_year=2093,
29-
)
30-
31-
mock_get_current_reporting_year.return_value = current_year
32-
33-
results = OperationService._get_previous_reporting_years().filter(
34-
reporting_year__in=[2091, 2092, 2093],
35-
)
36-
37-
assert results.count() == 2
38-
assert results[0].reporting_year == 2092
39-
assert results[1].reporting_year == 2091
40-
4121
@staticmethod
4222
def test_get_registration_purposes_for_operation_type_sfo_lfo():
4323
expected_purposes = [
@@ -90,7 +70,7 @@ def test_build_reportable_operation_row(mock_get_purposes: MagicMock):
9070
"service.operation_designated_operator_timeline_service."
9171
"OperationDesignatedOperatorTimelineService.get_operation_designated_operators_for_reporting_years"
9272
)
93-
@patch.object(OperationService, "_get_previous_reporting_years")
73+
@patch("service.reporting_year_service.ReportingYearService.get_previous_reporting_years")
9474
def test_list_previous_reportable_operations(
9575
mock_get_previous_reporting_years: MagicMock,
9676
mock_get_designations: MagicMock,

bc_obps/service/tests/test_report_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ def test_create_report_for_reporting_year_rejects_wrong_historical_designated_op
743743

744744
self.assertEqual(
745745
str(exception_context.exception),
746-
"This operation was owned by another operation in 2023, "
746+
"This operation was owned by another operator in 2023, "
747747
"you do not need to report on this operation. "
748748
"If you believe this is incorrect, please contact ghgregulator@gov.bc.ca.",
749749
)

bciers/apps/dashboard-e2e/utils/enums.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ export enum ExternalDashboardLinks {
4242
CONTACTS = "Contacts",
4343
USERS_AND_ACCESS_REQUESTS = "Users and Access Requests",
4444
REGISTER_AN_OPERATION = "Register an Operation",
45-
VIEW_ANNUAL_REPORTS = "View Annual Reports",
46-
VIEW_PAST_REPORTS = "View Past Reports",
45+
VIEW_ANNUAL_REPORTS = "Current Reporting Year",
46+
VIEW_PAST_REPORTS = "Previous Reporting Years",
4747
MY_COMPLIANCE = "My Compliance",
4848
BC_CARBON_REGISTRY = "B.C. Carbon Registry",
4949
REPORT_PROBLEM = "Report problems to GHGRegulator@gov.bc.ca",

0 commit comments

Comments
 (0)