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

1962 eio form #2738

merged 5 commits into from
Feb 6, 2025

Conversation

BCerki
Copy link
Contributor

@BCerki BCerki commented Jan 27, 2025

card: https://github.com/orgs/bcgov/projects/123/views/16?pane=issue&itemId=80445774&issue=bcgov%7Ccas-registration%7C1962

This PR:

  • conditionally hides non-EIO fields when the registration purpose is EIO
  • EIO type is only available if purpose is EIO
  • makes an EIO in the mock data
  • makes a facility when creating an EIO
  • ^this facility is not accessible via the operation grid
  • vitests
  • pytests
  • testing instructions in the card

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

Comment on lines +168 to +169
"This type of operation (SFO or EIO) can only have one facility, this page should not be accessible"
)
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.

@BCerki BCerki force-pushed the 1962-eio-form branch 3 times, most recently from ae1f6d1 to c6baea2 Compare January 29, 2025 17:54
@BCerki BCerki marked this pull request as ready for review January 29, 2025 17:55
Copy link
Contributor

@Sepehr-Sobhani Sepehr-Sobhani left a comment

Choose a reason for hiding this comment

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

Looks great!
A couple of nits and comments but not blocker.

Comment on lines +168 to +169
"This type of operation (SFO or EIO) can only have one facility, this page should not be accessible"
)
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.

eio_payload = FacilityIn(
name=payload.name, type=Facility.Types.ELECTRICITY_IMPORT, operation_id=operation.id
)
facility = FacilityDataAccessService.get_current_facilities_by_operation(operation).first()
Copy link
Contributor

Choose a reason for hiding this comment

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

Here as well! We could say operation.facilities.first()

Comment on lines 320 to 337
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 = FacilityDataAccessService.get_current_facilities_by_operation(operation).first()

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we move this whole condition into a separate function?!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm currently doing work on this function in the optimization PR, so I'll handle this there instead to avoid merge conflicts/accidentally un-optimizing

Comment on lines +104 to +98
approved_user_operator = baker.make_recipe('utils.approved_user_operator')
owning_operation: Operation = baker.make_recipe(
'utils.operation', operator=approved_user_operator.operator, type="Linear Facility Operation"
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: suggest using the absolute path for recipes.(registration.tests.utils....)
For some reason Model Bakery can't find our recipes after adding the RLS app; The only workaround is to use the absolute path.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I've hit this a few times now, thanks!

assert operation.registration_purpose == Operation.Purposes.ELECTRICITY_IMPORT_OPERATION
assert operation.status == Operation.Statuses.DRAFT
# check facility
facilities = Facility.objects.filter(designated_operations__operation=operation).all()
Copy link
Contributor

Choose a reason for hiding this comment

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

operation.facilities.all()

assert operation.status == Operation.Statuses.DRAFT
facilities = Facility.objects.filter(designated_operations__operation=operation).all()
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here!

@@ -411,6 +472,8 @@ def test_register_operation_information_existing_operation():
# check purpose
assert operation.registration_purpose == Operation.Purposes.POTENTIAL_REPORTING_OPERATION
assert operation.status == Operation.Statuses.DRAFT
facilities = Facility.objects.filter(designated_operations__operation=operation).all()
Copy link
Contributor

Choose a reason for hiding this comment

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

And here! :)

Comment on lines 121 to 136
...(app === Apps.ADMINISTRATION
? {
bc_obps_regulated_operation: {
type: "string",
title: "BORO ID",
},
}
: {}),
...(app === Apps.ADMINISTRATION
? {
bcghg_id: {
type: "string",
title: "BCGHGID",
},
}
: {}),
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we say?

...(app === Apps.ADMINISTRATION && {
        bc_obps_regulated_operation: {
          type: "string",
          title: "BORO ID",
        },
        bcghg_id: {
          type: "string",
          title: "BCGHGID",
        },
    }),

) {
steps.splice(2, 0, OperationRegistrationSteps.OPT_IN_APPLICATION);
}
if (purpose == RegistrationPurposes.NEW_ENTRANT_OPERATION)
if (purpose === RegistrationPurposes.NEW_ENTRANT_OPERATION)
Copy link
Contributor

Choose a reason for hiding this comment

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

🤩

@BCerki BCerki merged commit ffb6848 into develop Feb 6, 2025
42 checks passed
@BCerki BCerki deleted the 1962-eio-form branch February 6, 2025 23:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants