Skip to content

Commit

Permalink
chore: added other requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ayeshmcg committed Jan 16, 2025
1 parent 507c316 commit 247a457
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion bc_obps/reporting/api/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def get_report_operation_by_version_id(request: HttpRequest, version_id: int) ->
report_operation = ReportService.get_report_operation_by_version_id(version_id)
return 200, {
"report_operation": report_operation,
"report_operation_representative": report_operation_representative,
"report_operation_representatives": report_operation_representative,
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ class Meta:
db_table_comment = (
"Stores information about operation representatives linked to report versions, "
"including their selection status for reports."
)
)
4 changes: 2 additions & 2 deletions bc_obps/reporting/schema/report_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ReportOperationSchemaOut(Schema):
"""

report_operation: ReportOperationOut
report_operation_representative: List[ReportOperationRepresentativeSchema]
report_operation_representatives: List[ReportOperationRepresentativeSchema]


class ReportOperationIn(Schema):
Expand Down Expand Up @@ -80,4 +80,4 @@ class Meta:
'regulated_products',
'operation_representative_name',
'operation_report_type',
]
]
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from common.tests.utils.helpers import BaseTestCase
from reporting.tests.utils.report_data_bakers import report_operation_representative_baker
from registration.tests.constants import TIMESTAMP_COMMON_FIELDS
from model_bakery.baker import make_recipe


class ReportOperationRepresentativeModelTest(BaseTestCase):
@classmethod
def setUpTestData(cls):
cls.test_object = report_operation_representative_baker()
cls.test_object = make_recipe('reporting.tests.utils.report_operation_representative')
cls.field_data = [
*TIMESTAMP_COMMON_FIELDS,
("id", "ID", None, None),
("report_version", "report version", None, None),
("representative_name", "representative name", None, None),
("selected_for_report", "selected for report", None, None),
]
]
15 changes: 13 additions & 2 deletions bc_obps/reporting/tests/utils/baker_recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@

from registration.models import NaicsCode
from registration.models.activity import Activity
from reporting.models import ReportNewEntrant, ReportNewEntrantEmission, ReportNewEntrantProduction
from reporting.models import (
ReportNewEntrant,
ReportNewEntrantEmission,
ReportNewEntrantProduction,
ReportOperationRepresentative,
)
from reporting.models import ReportAdditionalData
from reporting.models.activity_json_schema import ActivityJsonSchema
from reporting.models.activity_source_type_json_schema import ActivitySourceTypeJsonSchema
Expand Down Expand Up @@ -149,7 +154,6 @@ def json_seq(json_key="generated_json", json_value="test json value", seq_value:
gas_type=[foreign_key(gas_type)],
)


report_verification = Recipe(
ReportVerification,
report_version=foreign_key(report_version),
Expand Down Expand Up @@ -199,3 +203,10 @@ def json_seq(json_key="generated_json", json_value="test json value", seq_value:
NaicsCode,
naics_code='12345',
)

report_operation_representative = Recipe(
ReportOperationRepresentative,
report_version=foreign_key(report_version),
representative_name="Test Report",
selected_for_report=True,
)
11 changes: 1 addition & 10 deletions bc_obps/reporting/tests/utils/report_data_bakers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from registration.models import RegulatedProduct
from registration.tests.utils.bakers import facility_baker
from reporting.models import ReportNewEntrant, ReportNewEntrantProduction, ReportOperationRepresentative
from reporting.models import ReportNewEntrant, ReportNewEntrantProduction
from reporting.models.activity_json_schema import ActivityJsonSchema
from reporting.models.activity_source_type_json_schema import ActivitySourceTypeJsonSchema
from reporting.models.facility_report import FacilityReport
Expand Down Expand Up @@ -138,12 +138,3 @@ def report_new_entrant_production_baker(**props):
"production_amount": 500,
}
return baker.make(ReportNewEntrantProduction, **(default_props | props))


def report_operation_representative_baker(**props) -> ReportOperationRepresentative:
if "report_version" not in props:
props["report_version"] = report_version_baker()

report_representative = baker.make(ReportOperationRepresentative, **props)

return report_representative
9 changes: 3 additions & 6 deletions bc_obps/service/report_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,12 @@ def get_report_operation_by_version_id(cls, report_version_id: int) -> ReportOpe
def save_report_operation(cls, report_version_id: int, data: ReportOperationIn) -> ReportOperation:
# Fetch the existing report operation
report_operation = ReportOperation.objects.get(report_version__id=report_version_id)
report_operation_representatives = ReportOperationRepresentative.objects.filter(
report_version=report_version_id
)

# Update the selected_for_report field based on the provided data
representative_ids_in_data = data.operation_representative_name # List of IDs from input
for representative in report_operation_representatives:
representative.selected_for_report = representative.id in representative_ids_in_data
representative.save()
ReportOperationRepresentative.objects.filter(
report_version_id=report_version_id, id__in=representative_ids_in_data
).update(selected_for_report=True)
# Update fields from data
report_operation.operator_legal_name = data.operator_legal_name
report_operation.operator_trade_name = data.operator_trade_name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { getReportType } from "@reporting/src/app/utils/getReportType";
import { getRegulatedProducts } from "@bciers/actions/api";
import { getRegistrationPurpose } from "@reporting/src/app/utils/getRegistrationPurpose";
import { getFacilityReport } from "@reporting/src/app/utils/getFacilityReport";
import OperationReview from "./OperationReviewForm";
import { HasReportVersion } from "@reporting/src/app/utils/defaultPageFactoryTypes";
import OperationReviewForm from "./OperationReviewForm";

Expand All @@ -24,9 +23,9 @@ export default async function OperationReviewPage({
const transformedOperation = {
...reportOperation.report_operation,
operation_representative_name:
reportOperation.report_operation_representative,
reportOperation.report_operation_representatives,
};
const allRepresentatives = reportOperation.report_operation_representative;
const allRepresentatives = reportOperation.report_operation_representatives;

return (
<OperationReviewForm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ const mockReportOperation = {
operation_representative_name: [4],
operation_type: "Test Operation",
},
report_operation_representative: [{ id: 4, representative_name: "Shon Doe" }],
report_operation_representatives: [
{ id: 4, representative_name: "Shon Doe" },
],
};

const props: HasReportVersion = {
Expand Down

0 comments on commit 247a457

Please sign in to comment.