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

[MDS-6114] Fix AMS bug #3268

Merged
merged 6 commits into from
Oct 17, 2024
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
7 changes: 5 additions & 2 deletions services/common/src/components/projectSummary/Applicant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ const Applicant = () => {
dispatch(
change(FORM.ADD_EDIT_PROJECT_SUMMARY, "applicant.party_orgbook_entity", orgBookEntity)
);
dispatch(
change(FORM.ADD_EDIT_PROJECT_SUMMARY, "incorporation_number", credential.topic.source_id)
);
}
}, [credential]);

Expand Down Expand Up @@ -330,8 +333,8 @@ const Applicant = () => {

<Col md={12} sm={24}>
<Field
id="applicant.party_orgbook_entity.registration_id"
name="applicant.party_orgbook_entity.registration_id"
id="incorporation_number"
name="incorporation_number"
label="Incorporation Number"
required
validate={[required, maxLength(25)]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ exports[`Applicant Component should render the component with expected fields 1`
>
<label
class="ant-form-item-required"
for="ADD_EDIT_PROJECT_SUMMARY_applicant.party_orgbook_entity.registration_id"
for="ADD_EDIT_PROJECT_SUMMARY_incorporation_number"
title=""
>
<div
Expand All @@ -326,8 +326,8 @@ exports[`Applicant Component should render the component with expected fields 1`
>
<input
class="ant-input"
id="applicant.party_orgbook_entity.registration_id"
name="applicant.party_orgbook_entity.registration_id"
id="incorporation_number"
name="incorporation_number"
type="text"
value=""
/>
Expand All @@ -338,7 +338,7 @@ exports[`Applicant Component should render the component with expected fields 1`
>
<div
class="ant-form-item-explain ant-form-item-explain-connected"
id="ADD_EDIT_PROJECT_SUMMARY_applicant.party_orgbook_entity.registration_id_help"
id="ADD_EDIT_PROJECT_SUMMARY_incorporation_number_help"
role="alert"
>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class ProjectSummary(SoftDeleteMixin, AuditMixin, Base):
nearest_municipality_guid = db.Column(UUID(as_uuid=True), db.ForeignKey('municipality.municipality_guid'))
regional_district_id = db.Column(db.Integer(), db.ForeignKey('regions.regional_district_id'), nullable=True)
company_alias = db.Column(db.String(200), nullable=True)
incorporation_number = db.Column(db.String(25), nullable=True)

is_legal_address_same_as_mailing_address = db.Column(db.Boolean, nullable=True)
is_billing_address_same_as_mailing_address = db.Column(db.Boolean, nullable=True)
Expand Down Expand Up @@ -140,6 +141,10 @@ class ProjectSummary(SoftDeleteMixin, AuditMixin, Base):
'Party', lazy='joined', foreign_keys=payment_contact_party_guid
)

regions = db.relationship(
'Regions', lazy='joined', foreign_keys=regional_district_id
)

@classmethod
def __get_address_type_code(cls, address_data):
if isinstance(address_data, list):
Expand Down Expand Up @@ -1002,6 +1007,7 @@ def update(self,
company_alias=None,
regional_district_id=None,
payment_contact=None,
incorporation_number=None,
is_historic=False,
add_to_session=True
):
Expand Down Expand Up @@ -1033,6 +1039,7 @@ def update(self,
self.is_billing_address_same_as_legal_address = is_billing_address_same_as_legal_address
self.company_alias = company_alias
self.is_historic = is_historic
self.incorporation_number=incorporation_number

# TODO - Turn this on when document removal is activated on the front end.
# Get the GUIDs of the updated documents.
Expand Down Expand Up @@ -1175,7 +1182,8 @@ def update(self,
zoning_reason,
regional_district_name,
project.project_guid,
payment_contact)
payment_contact,
incorporation_number)

amendment_ams_results = AMSApiService.create_amendment_ams_authorization(
ams_authorizations,
Expand Down Expand Up @@ -1204,7 +1212,8 @@ def update(self,
is_legal_land_owner,
is_crown_land_federal_or_provincial,
project.project_guid,
payment_contact
payment_contact,
incorporation_number
)

for authorization in ams_authorizations.get('amendments', []):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ class ProjectSummaryResource(Resource, UserMixin):
)

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

@api.doc(
description='Get a Project Description.',
Expand Down Expand Up @@ -253,6 +254,7 @@ def put(self, project_guid, project_summary_guid):
data.get('company_alias'),
data.get('regional_district_id'),
data.get('payment_contact'),
data.get('incorporation_number'),
is_historic)

project_summary.save()
Expand Down
7 changes: 7 additions & 0 deletions services/core-api/app/api/projects/response_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ def format(self, value):
'municipality_name': fields.String
})

REGION_MODEL = api.model(
'Regions', {
'name': fields.String,
'regional_district_id': fields.Integer
})

PROJECT_SUMMARY_MODEL = api.model(
'ProjectSummary', {
'project_guid': fields.String,
Expand Down Expand Up @@ -226,6 +232,7 @@ def format(self, value):
'regional_district_id': fields.Integer,
'payment_contact': fields.Nested(PARTY),
'is_historic': fields.Boolean,
'regions': fields.Nested(REGION_MODEL)
})

REQUIREMENTS_MODEL = api.model(
Expand Down
36 changes: 22 additions & 14 deletions services/core-api/app/api/services/ams_api_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def __get_mapped_amendment_type(cls, data):
return amendment_type_mapping[data]

@classmethod
def __create_full_address(cls, address_line1, city, sub_division_code, post_code):
return f"{address_line1}, {city}, {sub_division_code}, {post_code}"
def __create_full_address(cls, address_line1, city, sub_division_code, post_code, suite_no):
return f"{suite_no} {address_line1}, {city}, {sub_division_code}, {post_code}"

@classmethod
def __get_authorization_details(cls, ams_authorizations, detail_type):
Expand Down Expand Up @@ -91,38 +91,42 @@ def __set_contact_details(cls, contact):
contact['address'].get('address_line_1', ''),
contact['address'].get('city', ''),
contact['address'].get('sub_division_code', ''),
contact['address'].get('post_code', '')
contact['address'].get('post_code', ''),
contact['address'].get('suite_no', '')
) if contact.get('address') else ''
}
return contact_details

@classmethod
def __set_applicant_details(cls, applicant, company_alias):
def __set_applicant_details(cls, applicant, company_alias, incorporation_number):
applicant_details = {
'applicanttype': cls.__get_mapped_party_type(applicant.get('party_type_code')),
'em_companyname': applicant.get('party_name', ''),
'em_firstname': applicant.get('first_name', ''),
'em_middlename': applicant.get('middle_name', ''),
'em_lastname': applicant.get('party_name', ''),
'em_doingbusinessas': company_alias,
'bccompanyregistrationnumber': applicant.get('party_orgbook_entity', {}).get('registration_id', ''),
'bccompanyregistrationnumber': incorporation_number,
'em_businessphone': cls.__format_phone_number(applicant.get('phone_no', '')),
'em_email': applicant.get('email', ''),
'legaladdress': cls.__create_full_address(
applicant.get('address')[1].get('address_line_1', ''),
applicant.get('address')[1].get('city', ''),
applicant.get('address')[1].get('sub_division_code', ''),
applicant.get('address')[1].get('post_code')),
applicant.get('address')[1].get('post_code'),
applicant.get('address')[1].get('suite_no', '')),
'mailingaddress': cls.__create_full_address(
applicant.get('address')[0].get('address_line_1', ''),
applicant.get('address')[0].get('city', ''),
applicant.get('address')[0].get('sub_division_code', ''),
applicant.get('address')[0].get('post_code')),
applicant.get('address')[0].get('post_code'),
applicant.get('address')[0].get('suite_no', '')),
'billingaddress': cls.__create_full_address(
applicant.get('address')[2].get('address_line_1', ''),
applicant.get('address')[2].get('city', ''),
applicant.get('address')[2].get('sub_division_code', ''),
applicant.get('address')[2].get('post_code')),
applicant.get('address')[2].get('post_code'),
applicant.get('address')[2].get('suite_no', '')),
'billingemailaddress': ''
}
return applicant_details
Expand All @@ -138,7 +142,8 @@ def __set_agent_details(cls, agent):
agent.get('address').get('address_line_1', ''),
agent.get('address').get('city', ''),
agent.get('address').get('sub_division_code', ''),
agent.get('address').get('post_code')) if agent else '',
agent.get('address').get('post_code'),
agent.get('address').get('suit_no', '')) if agent else '',
'em_businessphone': cls.__format_phone_number(agent.get('phone_no')) if agent else '',
'em_title': agent.get('job_title', '') if agent else '',
}
Expand All @@ -159,7 +164,8 @@ def __set_facility_address_details(cls, facility_operator, address_type=None):
facility_operator.get('address').get('address_line_1'),
facility_operator.get('address').get('city'),
facility_operator.get('address').get('sub_division_code'),
facility_operator.get('address').get('post_code'))
facility_operator.get('address').get('post_code'),
facility_operator.get('address').get('suite_no', ''))
}
if address_type is not None:
facility_address['addresstype'] = address_type
Expand Down Expand Up @@ -214,7 +220,8 @@ def create_new_ams_authorization(cls,
zoning_reason,
regional_district_name,
project_guid,
payment_contact
payment_contact,
incorporation_number
):
"""Creates a new AMS authorization application"""

Expand Down Expand Up @@ -249,7 +256,7 @@ def create_new_ams_authorization(cls,
'majorcentre': {
'name': nearest_municipality_name
},
'applicant': cls.__set_applicant_details(applicant, company_alias),
'applicant': cls.__set_applicant_details(applicant, company_alias, incorporation_number),
'agent': cls.__set_agent_details(agent),
'purposeofapplication': authorization.get('authorization_description', ''),
'preappexemptionrequest': cls.__boolean_to_yes_no(authorization.get('exemption_requested')),
Expand Down Expand Up @@ -360,7 +367,8 @@ def create_amendment_ams_authorization(cls,
is_legal_land_owner,
is_crown_land_federal_or_provincial,
project_guid,
payment_contact
payment_contact,
incorporation_number
):
"""Creates an AMS authorization application amendment"""

Expand Down Expand Up @@ -410,7 +418,7 @@ def create_amendment_ams_authorization(cls,
'preappexemptionrequest': cls.__boolean_to_yes_no(authorization.get('exemption_requested')),
'preappexemptionrequestreason': authorization.get('exemption_reason', ''),
'newiscontaminatedsite': cls.__boolean_to_yes_no(authorization.get('is_contaminated')),
'newapplicant': cls.__set_applicant_details(applicant, company_alias),
'newapplicant': cls.__set_applicant_details(applicant, company_alias, incorporation_number),
'newcontact': cls.__set_contact_details(contacts[0]),
'newagent': cls.__set_agent_details(agent),
'newfacilitytype': facility_type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,22 @@ export const ProjectSummaryPage = () => {
const handleFetchData = async () => {
if (projectGuid && projectSummaryGuid) {
setIsEditMode(true);
await dispatch(fetchRegions(undefined));
await dispatch(fetchProjectById(projectGuid));
} else {
await dispatch(fetchMineRecordById(mineGuid));
}
};

useEffect(() => {
if (!isLoaded) {
handleFetchData().then(() => setIsLoaded(true));
}
const fetchData = async () => {
await dispatch(fetchRegions(undefined));
if (!isLoaded) {
await handleFetchData();
setIsLoaded(true);
}
};

fetchData();
return () => {
dispatch(clearProjectSummary());
};
Expand Down
Loading