Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1962 eio form #2738

Merged
merged 5 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bc_obps/registration/enums/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ class AccessRequestTypes(Enum):
class OperationTypes(Enum):
LFO = "Linear Facility Operation"
SFO = "Single Facility Operation"
EIO = "Electricity Import Operation"
7 changes: 2 additions & 5 deletions bc_obps/registration/fixtures/mock/facility.json
Original file line number Diff line number Diff line change
Expand Up @@ -614,11 +614,8 @@
"operation": "02a3ab84-26c6-4a79-bf89-72f877ceef8e",
"created_by": "00000000-0000-0000-0000-000000000001",
"created_at": "2024-06-05T23:18:07.664Z",
"name": "Facility 43",
"type": "Single Facility",
"swrs_facility_id": 1043,
"latitude_of_largest_emissions": 43.5,
"longitude_of_largest_emissions": -123.5
"name": "Blight EIO - Draft",
"type": "Electricity Import"
}
}
]
34 changes: 3 additions & 31 deletions bc_obps/registration/fixtures/mock/operation.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"swrs_facility_id": 1001,
"status": "Registered",
"bc_obps_regulated_operation": "24-0014",
"created_at": "2024-2-01T15:27:00.000Z",
"activities": [1, 5],
"registration_purpose": "Reporting Operation",
"contacts": [1, 2]
Expand All @@ -31,7 +30,6 @@
"regulated_products": [1],
"status": "Registered",
"bc_obps_regulated_operation": "24-0015",
"created_at": "2024-2-02T15:27:00.000Z",
"activities": [1, 5],
"registration_purpose": "OBPS Regulated Operation",
"contacts": [3, 4]
Expand All @@ -49,7 +47,6 @@
"opt_in": false,
"regulated_products": [1],
"status": "Draft",
"created_at": "2024-2-02T15:27:00.000Z",
"activities": [1, 5],
"registration_purpose": "OBPS Regulated Operation"
}
Expand All @@ -69,7 +66,6 @@
"regulated_products": [2, 6, 7, 8],
"status": "Registered",
"bc_obps_regulated_operation": "23-0001",
"created_at": "2024-1-31T15:27:00.000Z",
"activities": [1, 3],
"registration_purpose": "OBPS Regulated Operation",
"contacts": [3, 4]
Expand All @@ -90,7 +86,6 @@
"regulated_products": [1],
"status": "Registered",
"bc_obps_regulated_operation": "23-0002",
"created_at": "2024-1-30T15:27:00.000Z",
"activities": [1, 5],
"registration_purpose": "OBPS Regulated Operation",
"contacts": [1]
Expand All @@ -112,7 +107,6 @@
"registration_purpose": "OBPS Regulated Operation",
"status": "Registered",
"bc_obps_regulated_operation": "24-0003",
"created_at": "2024-1-29T15:27:00.000Z",
"activities": [1, 5],
"operation_has_multiple_operators": true,
"contacts": [3]
Expand All @@ -133,7 +127,6 @@
"regulated_products": [1],
"status": "Registered",
"bc_obps_regulated_operation": "24-0004",
"created_at": "2024-1-28T15:27:00.000Z",
"activities": [1, 5],
"registration_purpose": "Opted-in Operation",
"contacts": [1]
Expand All @@ -153,7 +146,6 @@
"bcghg_id": "23219990006",
"status": "Registered",
"bc_obps_regulated_operation": "24-0005",
"created_at": "2024-1-27T15:27:00.000Z",
"activities": [1, 5],
"registration_purpose": "Potential Reporting Operation",
"contacts": [2]
Expand All @@ -173,7 +165,6 @@
"bcghg_id": "23219990007",
"status": "Registered",
"bc_obps_regulated_operation": "24-0006",
"created_at": "2024-1-26T15:27:00.000Z",
"activities": [1, 5],
"registration_purpose": "Electricity Import Operation",
"contacts": [1]
Expand All @@ -194,7 +185,6 @@
"regulated_products": [2],
"status": "Registered",
"bc_obps_regulated_operation": "24-0007",
"created_at": "2024-1-25T15:27:00.000Z",
"activities": [1, 5],
"registration_purpose": "New Entrant Operation",
"contacts": [1]
Expand All @@ -213,7 +203,6 @@
"opt_in": false,
"status": "Registered",
"bc_obps_regulated_operation": "24-0008",
"created_at": "2024-1-24T15:27:00.000Z",
"activities": [1, 5],
"registration_purpose": "Reporting Operation",
"contacts": [2]
Expand All @@ -234,7 +223,6 @@
"regulated_products": [3],
"status": "Registered",
"bc_obps_regulated_operation": "24-0009",
"created_at": "2024-1-23T15:27:00.000Z",
"activities": [1, 5],
"registration_purpose": "OBPS Regulated Operation",
"contacts": [1, 2]
Expand All @@ -254,7 +242,6 @@
"bcghg_id": "23219990011",
"status": "Registered",
"bc_obps_regulated_operation": "24-0010",
"created_at": "2024-1-22T15:27:00.000Z",
"activities": [1, 5],
"registration_purpose": "Reporting Operation",
"contacts": [1, 2]
Expand All @@ -274,7 +261,6 @@
"regulated_products": [3, 4],
"status": "Registered",
"bc_obps_regulated_operation": "24-0011",
"created_at": "2024-1-21T15:27:00.000Z",
"activities": [1, 5],
"registration_purpose": "OBPS Regulated Operation",
"contacts": [1]
Expand All @@ -292,7 +278,6 @@
"naics_code": 21,
"opt_in": false,
"bcghg_id": "23219990013",
"created_at": "2024-1-20T15:27:00.000Z",
"status": "Not Started",
"registration_purpose": "Electricity Import Operation"
}
Expand All @@ -311,7 +296,6 @@
"bcghg_id": "23219990014",
"regulated_products": [3],
"status": "Not Started",
"created_at": "2024-1-19T15:27:00.000Z",
"activities": [1, 5],
"registration_purpose": "OBPS Regulated Operation"
}
Expand All @@ -329,7 +313,6 @@
"opt_in": false,
"bcghg_id": "23219990015",
"status": "Draft",
"created_at": "2024-1-18T15:27:00.000Z",
"activities": [1, 5],
"registration_purpose": "Potential Reporting Operation"
}
Expand All @@ -349,7 +332,6 @@
"regulated_products": [5],
"status": "Registered",
"bc_obps_regulated_operation": "24-0012",
"created_at": "2024-1-17T15:27:00.000Z",
"activities": [1, 5],
"registration_purpose": "OBPS Regulated Operation",
"contacts": [3]
Expand All @@ -368,7 +350,6 @@
"opt_in": false,
"bcghg_id": "23219990017",
"status": "Draft",
"created_at": "2024-1-16T15:27:00.000Z",
"activities": [1, 5]
}
},
Expand All @@ -388,7 +369,6 @@
"status": "Registered",
"bc_obps_regulated_operation": "24-0013",
"registration_purpose": "New Entrant Operation",
"created_at": "2024-1-15T15:27:00.000Z",
"activities": [1, 3],
"contacts": [4]
}
Expand All @@ -407,7 +387,6 @@
"bcghg_id": "23219990019",
"status": "Registered",
"bc_obps_regulated_operation": "24-0016",
"created_at": "2024-1-14T15:27:00.000Z",
"registration_purpose": "Reporting Operation",
"activities": [1, 5],
"contacts": [3]
Expand All @@ -426,7 +405,6 @@
"bcghg_id": "23219990020",
"status": "Registered",
"bc_obps_regulated_operation": "24-0017",
"created_at": "2024-1-13T15:27:00.000Z",
"registration_purpose": "Reporting Operation",
"activities": [1, 5],
"contacts": [3]
Expand All @@ -445,7 +423,6 @@
"bcghg_id": "23219990021",
"status": "Registered",
"bc_obps_regulated_operation": "24-0018",
"created_at": "2024-1-12T15:27:00.000Z",
"registration_purpose": "Reporting Operation",
"activities": [1, 5],
"contacts": [4]
Expand All @@ -457,13 +434,9 @@
"fields": {
"point_of_contact": 1,
"operator": "4242ea9d-b917-4129-93c2-db00b7451051",
"name": "Blight SFO - Draft",
"type": "Single Facility Operation",
"naics_code": 21,
"opt_in": false,
"status": "Draft",
"created_at": "2024-1-11T15:27:00.000Z",
"activities": [1, 5]
"name": "Blight EIO - Draft",
"type": "Electricity Import Operation",
"status": "Draft"
}
},
{
Expand All @@ -477,7 +450,6 @@
"naics_code": 21,
"opt_in": false,
"status": "Draft",
"created_at": "2024-1-10T15:27:00.000Z",
"activities": [1, 3]
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Generated by Django 5.0.11 on 2025-02-06 19:28

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('registration', '0075_facility_operation_historicalfacility_operation'),
]

operations = [
migrations.AlterField(
model_name='facility',
name='type',
field=models.CharField(
choices=[
('Single Facility', 'Single Facility'),
('Large Facility', 'Large Facility'),
('Medium Facility', 'Medium Facility'),
('Small Aggregate', 'Small Aggregate'),
('Electricity Import', 'Electricity Import'),
],
db_comment='The type of the facility',
max_length=100,
),
),
migrations.AlterField(
model_name='historicalfacility',
name='type',
field=models.CharField(
choices=[
('Single Facility', 'Single Facility'),
('Large Facility', 'Large Facility'),
('Medium Facility', 'Medium Facility'),
('Small Aggregate', 'Small Aggregate'),
('Electricity Import', 'Electricity Import'),
],
db_comment='The type of the facility',
max_length=100,
),
),
migrations.AlterField(
model_name='operation',
name='naics_code',
field=models.ForeignKey(
blank=True,
db_comment="This column refers to an operation's primary NAICS code.",
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name='operations',
to='registration.naicscode',
),
),
]
1 change: 1 addition & 0 deletions bc_obps/registration/models/facility.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Types(models.TextChoices):
LARGE_FACILITY = "Large Facility"
MEDIUM_FACILITY = "Medium Facility"
SMALL_AGGREGATE = "Small Aggregate"
ELECTRICITY_IMPORT = "Electricity Import"

id = models.UUIDField(
primary_key=True, default=uuid.uuid4, db_comment="Primary key to identify the facility", verbose_name="ID"
Expand Down
1 change: 1 addition & 0 deletions bc_obps/registration/models/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class DateOfFirstShipmentChoices(models.TextChoices):
NaicsCode,
on_delete=models.PROTECT,
null=True,
blank=True,
db_comment="This column refers to an operation's primary NAICS code.",
related_name='operations',
)
Expand Down
3 changes: 2 additions & 1 deletion bc_obps/registration/schema/v2/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ class Meta:


class OperationInformationIn(ModelSchema):
name: str
registration_purpose: Optional[Operation.Purposes] = None
regulated_products: Optional[List[int]] = None
activities: List[int]
activities: Optional[List[int]] = None
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only field that isn't already optional, so perhaps it's not worth making a separate EIO schema

boundary_map: Optional[str] = None
process_flow_diagram: Optional[str] = None
naics_code_id: Optional[int] = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ def test_operation_registration_workflow(self, operation_type, purpose):
#### Operation Information Form ####
self._set_operation_information(purpose, operation_type)
#### Facility From ####
self._set_facilities()
if purpose != Operation.Purposes.ELECTRICITY_IMPORT_OPERATION:
self._set_facilities()

if purpose == Operation.Purposes.NEW_ENTRANT_OPERATION:
#### New Entrant Application Form ####
Expand Down
9 changes: 5 additions & 4 deletions bc_obps/service/facility_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,11 @@ def create_facility_with_designated_operation(cls, user_guid: UUID, payload: Fac
operation = OperationDataAccessService.get_by_id(payload.operation_id)
cls.check_user_access(user_guid, operation)

# Validate that SFO can only make one facility
num_facilities = FacilityDataAccessService.get_current_facilities_by_operation(operation).count()
if num_facilities > 0 and operation.type == OperationTypes.SFO.value:
raise RuntimeError("SFO can only create one facility, this page should not be accessible")
# Validate that SFO and EIO can only have one facility
if operation.facilities.count() > 0 and operation.type != OperationTypes.LFO.value:
raise Exception(
"This type of operation (SFO or EIO) can only have one facility, this page should not be accessible"
)
Comment on lines +168 to +169
Copy link
Contributor Author

@BCerki BCerki Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this error for EIO too because I did manage to create a second facility while testing

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of get_current_facilities_by_operation can we just say: operation.facilities.count()? In a couple of places, we should change our approach and use the direct operation-facility/operator-operation relationships which are easier to understand and more readable.
Also, RuntimeError is typically used for unexpected runtime issues rather than business logic validation. Since this is a domain-specific constraint, using an Exception or ValueError might be more appropriate.


facility_data = cls.prepare_facility_data(payload)
address_data = cls.build_address(payload)
Expand Down
15 changes: 15 additions & 0 deletions bc_obps/service/operation_service_v2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import Optional, Tuple, Callable, Generator, Union
from django.db.models import QuerySet
from registration.models.facility import Facility
from registration.schema.v1.facility import FacilityIn
from registration.schema.v2.operation_timeline import OperationTimelineFilterSchema
from service.contact_service_v2 import ContactServiceV2
from service.data_access_service.operation_designated_operator_timeline_service import (
Expand Down Expand Up @@ -28,6 +30,7 @@
from registration.models.opted_in_operation_detail import OptedInOperationDetail
from service.data_access_service.opted_in_operation_detail_service import OptedInOperationDataAccessService
from service.document_service_v2 import DocumentServiceV2
from service.facility_service import FacilityService
from service.operation_service import OperationService
from registration.schema.v2.operation import (
OperationInformationIn,
Expand Down Expand Up @@ -320,6 +323,18 @@ def register_operation_information(
if operation.registration_purpose == Operation.Purposes.OPTED_IN_OPERATION:
operation = cls.create_opted_in_operation_detail(user_guid, operation.id)

if operation.registration_purpose == Operation.Purposes.ELECTRICITY_IMPORT_OPERATION:
# EIO operations have a facility with the same data as the operation
eio_payload = FacilityIn(
name=payload.name, type=Facility.Types.ELECTRICITY_IMPORT, operation_id=operation.id
)
facility = operation.facilities.first()

if not facility:
FacilityService.create_facilities_with_designated_operations(user_guid, [eio_payload])
else:
FacilityService.update_facility(user_guid, facility.id, eio_payload)

if operation.status == Operation.Statuses.NOT_STARTED:
cls.update_status(user_guid, operation.id, Operation.Statuses.DRAFT)
return operation
Expand Down
Loading