From 4623a5258f6cb9e194c25b35daddd7c72080d1b7 Mon Sep 17 00:00:00 2001 From: Vysakh Menon Date: Thu, 25 Jan 2024 11:35:03 -0800 Subject: [PATCH] 19433 amalgamation state filing fix (#2415) --- .../business-summary/amalgamations.html | 2 +- .../legal_api/reports/business_document.py | 48 +++++++++---------- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/legal-api/report-templates/template-parts/business-summary/amalgamations.html b/legal-api/report-templates/template-parts/business-summary/amalgamations.html index a7bca1873c..308c4c71e9 100644 --- a/legal-api/report-templates/template-parts/business-summary/amalgamations.html +++ b/legal-api/report-templates/template-parts/business-summary/amalgamations.html @@ -1,4 +1,4 @@ -{% if business.amalgamatedEntity %} +{% if amalgamatedEntities|length > 0 %}
Amalgamating Businesses Information
diff --git a/legal-api/src/legal_api/reports/business_document.py b/legal-api/src/legal_api/reports/business_document.py index b025c1df3e..e746f3bb20 100644 --- a/legal-api/src/legal_api/reports/business_document.py +++ b/legal-api/src/legal_api/reports/business_document.py @@ -313,13 +313,11 @@ def _set_business_state_changes(self, business: dict): 'continuationOut']): state_filings.append(self._format_state_filing(filing)) # If it is amalgamating business - if ((business.get('business').get('state') == 'HISTORICAL') - and (business.get('business').get('amalgamatedInto'))): - amalgamating_business_temp = Business.find_by_identifier(business.get('business').get('identifier')) - amalgamating_business = amalgamating_business_temp.amalgamating_businesses.one_or_none() + if business.get('business').get('amalgamatedInto'): + amalgamating_business = self._business.amalgamating_businesses.one_or_none() amalgamation = Amalgamation.find_by_id(amalgamating_business.amalgamation_id) filing = Filing.find_by_id(amalgamation.filing_id) - state_filings.append(self._format_state_filing(filing)) + state_filings.insert(0, self._format_state_filing(filing)) business['stateFilings'] = state_filings def _set_record_keepers(self, business: dict): @@ -423,52 +421,51 @@ def _format_state_filing(self, filing: Filing) -> dict: continuation_out_date = LegislationDatetime.as_legislation_timezone_from_date_str( filing_meta['continuationOut']['continuationOutDate']) filing_info['continuationOutDate'] = continuation_out_date.strftime(OUTPUT_DATE_FORMAT) - elif filing.filing_type == 'amalgamationApplication': - filing_info['filingName'] = 'Amalgamation' else: filing_info['filingName'] = BusinessDocument.\ _get_summary_display_name(filing.filing_type, None, None) return filing_info def _set_amalgamation_details(self, business: dict): - """Set the list of partial amalgamation filing data.""" + """Set amalgamation filing data.""" amalgamated_businesses = [] - amalgamation_application = Filing.get_filings_by_types(self._business.id, ['amalgamationApplication']) - if amalgamation_application: + filings = Filing.get_filings_by_types(self._business.id, ['amalgamationApplication']) + if filings: + amalgamation_application = filings[0] business['business']['amalgamatedEntity'] = True - amalgamation_json = amalgamation_application[0].filing_json.get('filing', {})\ - .get('amalgamationApplication', {}) - # if it's future effective - if self._epoch_filing_date and amalgamation_application[0].effective_date < self._epoch_filing_date: + if self._epoch_filing_date and amalgamation_application.effective_date < self._epoch_filing_date: + # imported from COLIN amalgamated_businesses_info = { 'legalName': 'Not Available', 'identifier': 'Not Available' } amalgamated_businesses.append(amalgamated_businesses_info) else: - amalgamating_businesses = amalgamation_json.get('amalgamatingBusinesses', {}) - while amalgamating_businesses: - if len(amalgamating_businesses[0].get('foreignJurisdiction', {})) == 0: - identifier = amalgamating_businesses[0].get('identifier', {}) + amalgamation = self._business.amalgamation.one_or_none() + amalgamating_businesses = amalgamation.amalgamating_businesses.all() + for amalgamating_business in amalgamating_businesses: + if ting_business := Business.find_by_internal_id(amalgamating_business.business_id): + identifier = ting_business.identifier + business_legal_name = ting_business.legal_name else: - identifier = amalgamating_businesses[0].get('corpNumber', {}) - amalgamating_business = Business.find_by_identifier(identifier) - business_legal_name = amalgamating_business.legal_name + identifier = amalgamating_business.foreign_corp_num or 'Not Available' + business_legal_name = amalgamating_business.foreign_name or 'Not Available' + amalgamated_businesses_info = { 'legalName': business_legal_name, 'identifier': identifier } amalgamated_businesses.append(amalgamated_businesses_info) - amalgamating_businesses.remove(amalgamating_businesses[0]) business['amalgamatedEntities'] = amalgamated_businesses def _set_amalgamating_details(self, business: dict): amalgamating_info = business.get('business', {}).get('amalgamatedInto') - amalgamated_entity = business.get('business', {}).get('amalgamatedEntity') if amalgamating_info: business['business']['isAmalgamating'] = True - if amalgamated_entity: - business['business']['amalgamatedEntity'] = False + if business.get('amalgamatedEntities'): + # Amalgamating business can contain amalgamatedEntities when it is created through an amalgamation + # (if a business was a TED and it is now a TING). No need to show amalgamating businesses information + business['amalgamatedEntities'] = [] def _set_liquidation_details(self, business: dict): """Set partial liquidation filing data.""" @@ -528,6 +525,7 @@ def _get_legal_type_description(legal_type: str) -> str: return corp_type.full_desc if corp_type else '' FILING_SUMMARY_DISPLAY_NAME = { + 'amalgamationApplication': 'Amalgamation', 'dissolution': { 'voluntary': { 'CP': 'Voluntary Dissolution',