Skip to content

Commit 594ed87

Browse files
[MDS-6114] Fix AMS bug (#3268)
* wip * fix bug on regions. * fix bugs on missing attributes. * update snapshot test
1 parent 715330b commit 594ed87

File tree

7 files changed

+60
-26
lines changed

7 files changed

+60
-26
lines changed

services/common/src/components/projectSummary/Applicant.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ const Applicant = () => {
123123
dispatch(
124124
change(FORM.ADD_EDIT_PROJECT_SUMMARY, "applicant.party_orgbook_entity", orgBookEntity)
125125
);
126+
dispatch(
127+
change(FORM.ADD_EDIT_PROJECT_SUMMARY, "incorporation_number", credential.topic.source_id)
128+
);
126129
}
127130
}, [credential]);
128131

@@ -330,8 +333,8 @@ const Applicant = () => {
330333

331334
<Col md={12} sm={24}>
332335
<Field
333-
id="applicant.party_orgbook_entity.registration_id"
334-
name="applicant.party_orgbook_entity.registration_id"
336+
id="incorporation_number"
337+
name="incorporation_number"
335338
label="Incorporation Number"
336339
required
337340
validate={[required, maxLength(25)]}

services/common/src/components/projectSummary/__snapshots__/Applicant.spec.tsx.snap

+4-4
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ exports[`Applicant Component should render the component with expected fields 1`
305305
>
306306
<label
307307
class="ant-form-item-required"
308-
for="ADD_EDIT_PROJECT_SUMMARY_applicant.party_orgbook_entity.registration_id"
308+
for="ADD_EDIT_PROJECT_SUMMARY_incorporation_number"
309309
title=""
310310
>
311311
<div
@@ -326,8 +326,8 @@ exports[`Applicant Component should render the component with expected fields 1`
326326
>
327327
<input
328328
class="ant-input"
329-
id="applicant.party_orgbook_entity.registration_id"
330-
name="applicant.party_orgbook_entity.registration_id"
329+
id="incorporation_number"
330+
name="incorporation_number"
331331
type="text"
332332
value=""
333333
/>
@@ -338,7 +338,7 @@ exports[`Applicant Component should render the component with expected fields 1`
338338
>
339339
<div
340340
class="ant-form-item-explain ant-form-item-explain-connected"
341-
id="ADD_EDIT_PROJECT_SUMMARY_applicant.party_orgbook_entity.registration_id_help"
341+
id="ADD_EDIT_PROJECT_SUMMARY_incorporation_number_help"
342342
role="alert"
343343
>
344344
<div

services/core-api/app/api/projects/project_summary/models/project_summary.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class ProjectSummary(SoftDeleteMixin, AuditMixin, Base):
7575
nearest_municipality_guid = db.Column(UUID(as_uuid=True), db.ForeignKey('municipality.municipality_guid'))
7676
regional_district_id = db.Column(db.Integer(), db.ForeignKey('regions.regional_district_id'), nullable=True)
7777
company_alias = db.Column(db.String(200), nullable=True)
78+
incorporation_number = db.Column(db.String(25), nullable=True)
7879

7980
is_legal_address_same_as_mailing_address = db.Column(db.Boolean, nullable=True)
8081
is_billing_address_same_as_mailing_address = db.Column(db.Boolean, nullable=True)
@@ -140,6 +141,10 @@ class ProjectSummary(SoftDeleteMixin, AuditMixin, Base):
140141
'Party', lazy='joined', foreign_keys=payment_contact_party_guid
141142
)
142143

144+
regions = db.relationship(
145+
'Regions', lazy='joined', foreign_keys=regional_district_id
146+
)
147+
143148
@classmethod
144149
def __get_address_type_code(cls, address_data):
145150
if isinstance(address_data, list):
@@ -1002,6 +1007,7 @@ def update(self,
10021007
company_alias=None,
10031008
regional_district_id=None,
10041009
payment_contact=None,
1010+
incorporation_number=None,
10051011
is_historic=False,
10061012
add_to_session=True
10071013
):
@@ -1033,6 +1039,7 @@ def update(self,
10331039
self.is_billing_address_same_as_legal_address = is_billing_address_same_as_legal_address
10341040
self.company_alias = company_alias
10351041
self.is_historic = is_historic
1042+
self.incorporation_number=incorporation_number
10361043

10371044
# TODO - Turn this on when document removal is activated on the front end.
10381045
# Get the GUIDs of the updated documents.
@@ -1175,7 +1182,8 @@ def update(self,
11751182
zoning_reason,
11761183
regional_district_name,
11771184
project.project_guid,
1178-
payment_contact)
1185+
payment_contact,
1186+
incorporation_number)
11791187

11801188
amendment_ams_results = AMSApiService.create_amendment_ams_authorization(
11811189
ams_authorizations,
@@ -1204,7 +1212,8 @@ def update(self,
12041212
is_legal_land_owner,
12051213
is_crown_land_federal_or_provincial,
12061214
project.project_guid,
1207-
payment_contact
1215+
payment_contact,
1216+
incorporation_number
12081217
)
12091218

12101219
for authorization in ams_authorizations.get('amendments', []):

services/core-api/app/api/projects/project_summary/resources/project_summary.py

+2
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ class ProjectSummaryResource(Resource, UserMixin):
176176
)
177177

178178
parser.add_argument('is_historic', type=bool, store_missing=False, required=True)
179+
parser.add_argument('incorporation_number', type=str, store_missing=False, required=False)
179180

180181
@api.doc(
181182
description='Get a Project Description.',
@@ -253,6 +254,7 @@ def put(self, project_guid, project_summary_guid):
253254
data.get('company_alias'),
254255
data.get('regional_district_id'),
255256
data.get('payment_contact'),
257+
data.get('incorporation_number'),
256258
is_historic)
257259

258260
project_summary.save()

services/core-api/app/api/projects/response_models.py

+7
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,12 @@ def format(self, value):
171171
'municipality_name': fields.String
172172
})
173173

174+
REGION_MODEL = api.model(
175+
'Regions', {
176+
'name': fields.String,
177+
'regional_district_id': fields.Integer
178+
})
179+
174180
PROJECT_SUMMARY_MODEL = api.model(
175181
'ProjectSummary', {
176182
'project_guid': fields.String,
@@ -226,6 +232,7 @@ def format(self, value):
226232
'regional_district_id': fields.Integer,
227233
'payment_contact': fields.Nested(PARTY),
228234
'is_historic': fields.Boolean,
235+
'regions': fields.Nested(REGION_MODEL)
229236
})
230237

231238
REQUIREMENTS_MODEL = api.model(

services/core-api/app/api/services/ams_api_service.py

+22-14
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ def __get_mapped_amendment_type(cls, data):
3737
return amendment_type_mapping[data]
3838

3939
@classmethod
40-
def __create_full_address(cls, address_line1, city, sub_division_code, post_code):
41-
return f"{address_line1}, {city}, {sub_division_code}, {post_code}"
40+
def __create_full_address(cls, address_line1, city, sub_division_code, post_code, suite_no):
41+
return f"{suite_no} {address_line1}, {city}, {sub_division_code}, {post_code}"
4242

4343
@classmethod
4444
def __get_authorization_details(cls, ams_authorizations, detail_type):
@@ -91,38 +91,42 @@ def __set_contact_details(cls, contact):
9191
contact['address'].get('address_line_1', ''),
9292
contact['address'].get('city', ''),
9393
contact['address'].get('sub_division_code', ''),
94-
contact['address'].get('post_code', '')
94+
contact['address'].get('post_code', ''),
95+
contact['address'].get('suite_no', '')
9596
) if contact.get('address') else ''
9697
}
9798
return contact_details
9899

99100
@classmethod
100-
def __set_applicant_details(cls, applicant, company_alias):
101+
def __set_applicant_details(cls, applicant, company_alias, incorporation_number):
101102
applicant_details = {
102103
'applicanttype': cls.__get_mapped_party_type(applicant.get('party_type_code')),
103104
'em_companyname': applicant.get('party_name', ''),
104105
'em_firstname': applicant.get('first_name', ''),
105106
'em_middlename': applicant.get('middle_name', ''),
106107
'em_lastname': applicant.get('party_name', ''),
107108
'em_doingbusinessas': company_alias,
108-
'bccompanyregistrationnumber': applicant.get('party_orgbook_entity', {}).get('registration_id', ''),
109+
'bccompanyregistrationnumber': incorporation_number,
109110
'em_businessphone': cls.__format_phone_number(applicant.get('phone_no', '')),
110111
'em_email': applicant.get('email', ''),
111112
'legaladdress': cls.__create_full_address(
112113
applicant.get('address')[1].get('address_line_1', ''),
113114
applicant.get('address')[1].get('city', ''),
114115
applicant.get('address')[1].get('sub_division_code', ''),
115-
applicant.get('address')[1].get('post_code')),
116+
applicant.get('address')[1].get('post_code'),
117+
applicant.get('address')[1].get('suite_no', '')),
116118
'mailingaddress': cls.__create_full_address(
117119
applicant.get('address')[0].get('address_line_1', ''),
118120
applicant.get('address')[0].get('city', ''),
119121
applicant.get('address')[0].get('sub_division_code', ''),
120-
applicant.get('address')[0].get('post_code')),
122+
applicant.get('address')[0].get('post_code'),
123+
applicant.get('address')[0].get('suite_no', '')),
121124
'billingaddress': cls.__create_full_address(
122125
applicant.get('address')[2].get('address_line_1', ''),
123126
applicant.get('address')[2].get('city', ''),
124127
applicant.get('address')[2].get('sub_division_code', ''),
125-
applicant.get('address')[2].get('post_code')),
128+
applicant.get('address')[2].get('post_code'),
129+
applicant.get('address')[2].get('suite_no', '')),
126130
'billingemailaddress': ''
127131
}
128132
return applicant_details
@@ -138,7 +142,8 @@ def __set_agent_details(cls, agent):
138142
agent.get('address').get('address_line_1', ''),
139143
agent.get('address').get('city', ''),
140144
agent.get('address').get('sub_division_code', ''),
141-
agent.get('address').get('post_code')) if agent else '',
145+
agent.get('address').get('post_code'),
146+
agent.get('address').get('suit_no', '')) if agent else '',
142147
'em_businessphone': cls.__format_phone_number(agent.get('phone_no')) if agent else '',
143148
'em_title': agent.get('job_title', '') if agent else '',
144149
}
@@ -159,7 +164,8 @@ def __set_facility_address_details(cls, facility_operator, address_type=None):
159164
facility_operator.get('address').get('address_line_1'),
160165
facility_operator.get('address').get('city'),
161166
facility_operator.get('address').get('sub_division_code'),
162-
facility_operator.get('address').get('post_code'))
167+
facility_operator.get('address').get('post_code'),
168+
facility_operator.get('address').get('suite_no', ''))
163169
}
164170
if address_type is not None:
165171
facility_address['addresstype'] = address_type
@@ -214,7 +220,8 @@ def create_new_ams_authorization(cls,
214220
zoning_reason,
215221
regional_district_name,
216222
project_guid,
217-
payment_contact
223+
payment_contact,
224+
incorporation_number
218225
):
219226
"""Creates a new AMS authorization application"""
220227

@@ -249,7 +256,7 @@ def create_new_ams_authorization(cls,
249256
'majorcentre': {
250257
'name': nearest_municipality_name
251258
},
252-
'applicant': cls.__set_applicant_details(applicant, company_alias),
259+
'applicant': cls.__set_applicant_details(applicant, company_alias, incorporation_number),
253260
'agent': cls.__set_agent_details(agent),
254261
'purposeofapplication': authorization.get('authorization_description', ''),
255262
'preappexemptionrequest': cls.__boolean_to_yes_no(authorization.get('exemption_requested')),
@@ -360,7 +367,8 @@ def create_amendment_ams_authorization(cls,
360367
is_legal_land_owner,
361368
is_crown_land_federal_or_provincial,
362369
project_guid,
363-
payment_contact
370+
payment_contact,
371+
incorporation_number
364372
):
365373
"""Creates an AMS authorization application amendment"""
366374

@@ -410,7 +418,7 @@ def create_amendment_ams_authorization(cls,
410418
'preappexemptionrequest': cls.__boolean_to_yes_no(authorization.get('exemption_requested')),
411419
'preappexemptionrequestreason': authorization.get('exemption_reason', ''),
412420
'newiscontaminatedsite': cls.__boolean_to_yes_no(authorization.get('is_contaminated')),
413-
'newapplicant': cls.__set_applicant_details(applicant, company_alias),
421+
'newapplicant': cls.__set_applicant_details(applicant, company_alias, incorporation_number),
414422
'newcontact': cls.__set_contact_details(contacts[0]),
415423
'newagent': cls.__set_agent_details(agent),
416424
'newfacilitytype': facility_type,

services/minespace-web/src/components/pages/Project/ProjectSummaryPage.tsx

+9-4
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,22 @@ export const ProjectSummaryPage = () => {
7777
const handleFetchData = async () => {
7878
if (projectGuid && projectSummaryGuid) {
7979
setIsEditMode(true);
80-
await dispatch(fetchRegions(undefined));
8180
await dispatch(fetchProjectById(projectGuid));
8281
} else {
8382
await dispatch(fetchMineRecordById(mineGuid));
8483
}
8584
};
8685

8786
useEffect(() => {
88-
if (!isLoaded) {
89-
handleFetchData().then(() => setIsLoaded(true));
90-
}
87+
const fetchData = async () => {
88+
await dispatch(fetchRegions(undefined));
89+
if (!isLoaded) {
90+
await handleFetchData();
91+
setIsLoaded(true);
92+
}
93+
};
94+
95+
fetchData();
9196
return () => {
9297
dispatch(clearProjectSummary());
9398
};

0 commit comments

Comments
 (0)