Skip to content

Commit e2c3e25

Browse files
authored
Merge pull request #4051 from bcgov/fix/prashanth-sort-order-fse-4024
LCFS - Update the sort order used in the FSE schedule and download
2 parents 7ea2ce3 + d30a4a2 commit e2c3e25

File tree

4 files changed

+49
-13
lines changed

4 files changed

+49
-13
lines changed

backend/lcfs/tests/final_supply_equipment/test_final_supply_equipment_repo.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,30 @@ async def test_get_fse_reporting_list_paginated(repo, fake_db):
517517
assert data[0]["charging_equipment_id"] == 1
518518
assert data[0]["status"] == "Submitted"
519519

520+
executed_query = fake_db.execute.call_args[0][0]
521+
compiled_sql = str(executed_query.compile(compile_kwargs={"literal_binds": True}))
522+
assert "site_name ASC NULLS LAST" in compiled_sql
523+
assert "registration_number DESC NULLS LAST" in compiled_sql
524+
525+
526+
@pytest.mark.anyio
527+
async def test_get_fse_for_bulk_update_template_uses_site_then_registration_sort(
528+
repo, fake_db
529+
):
530+
fake_result = MagicMock()
531+
fake_result.fetchall.return_value = []
532+
fake_db.execute.return_value = fake_result
533+
534+
await repo.get_fse_for_bulk_update_template(
535+
organization_id=1, compliance_report_group_uuid="group-123"
536+
)
537+
538+
executed_query = fake_db.execute.call_args[0][0]
539+
compiled_sql = str(executed_query.compile(compile_kwargs={"literal_binds": True}))
540+
541+
assert "site_name ASC NULLS LAST" in compiled_sql
542+
assert "registration_number DESC NULLS LAST" in compiled_sql
543+
520544

521545
@pytest.mark.anyio
522546
async def test_create_fse_reporting_batch(repo, fake_db):

backend/lcfs/web/api/final_supply_equipment/repo.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,19 @@ class FinalSupplyEquipmentRepository:
6464
def __init__(self, db: AsyncSession = Depends(get_async_db_session)):
6565
self.db = db
6666

67+
def _apply_site_registration_sort(self, stmt, site_field, registration_field, tie_breaker_field):
68+
"""
69+
Apply the shared default FSE ordering:
70+
1. Site name ascending (nulls last)
71+
2. Registration number descending (nulls last)
72+
3. Stable tie-breaker for deterministic pagination
73+
"""
74+
return stmt.order_by(
75+
asc(site_field).nullslast(),
76+
desc(registration_field).nullslast(),
77+
asc(tie_breaker_field),
78+
)
79+
6780
def _combine_reporting_queries(self, union_queries: list[Any]):
6881
"""
6982
Combine reporting queries while removing exact duplicate rows.
@@ -1165,9 +1178,11 @@ async def get_fse_reporting_list_paginated(
11651178
else:
11661179
final_query = final_query.order_by(asc(field))
11671180
else:
1168-
final_query = final_query.order_by(
1169-
asc(vt.c.site_name),
1170-
asc(vt.c.registration_number),
1181+
final_query = self._apply_site_registration_sort(
1182+
final_query,
1183+
vt.c.site_name,
1184+
vt.c.registration_number,
1185+
vt.c.charging_equipment_id,
11711186
)
11721187

11731188
# Count total
@@ -1475,10 +1490,12 @@ async def get_fse_for_bulk_update_template(
14751490
all_rows_subquery.c.compliance_report_group_uuid,
14761491
)
14771492
.where(all_rows_subquery.c.row_num == 1)
1478-
.order_by(
1479-
asc(all_rows_subquery.c.site_name),
1480-
asc(all_rows_subquery.c.registration_number),
1481-
)
1493+
)
1494+
stmt = self._apply_site_registration_sort(
1495+
stmt,
1496+
all_rows_subquery.c.site_name,
1497+
all_rows_subquery.c.registration_number,
1498+
all_rows_subquery.c.charging_equipment_id,
14821499
)
14831500

14841501
result = await self.db.execute(stmt)

backend/lcfs/web/api/user/services.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,6 @@ async def get_all_users(self, pagination: PaginationRequestSchema) -> UsersSchem
177177
async def get_seeded_test_users(
178178
self, seed_env: str | None = None
179179
) -> list[UserBaseSchema]:
180-
if not self._is_nonprod_env():
181-
raise HTTPException(
182-
status_code=status.HTTP_403_FORBIDDEN,
183-
detail="Seeded test users endpoint is only available in local/test environments.",
184-
)
185180
resolved_env = (seed_env or "").lower().strip()
186181
if resolved_env not in {"local", "test"}:
187182
resolved_env = "test" if settings.environment.lower() == "test" else "local"

frontend/src/components/BCDataGrid/BCGridBase.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const BCGridBase = forwardRef(
4040
autoSizeStrategy,
4141
autoHeight,
4242
containerStyle,
43-
enableCellTextSelection=true,
43+
enableCellTextSelection,
4444
getRowId,
4545
overlayNoRowsTemplate,
4646
queryData,

0 commit comments

Comments
 (0)