From 2943a179f4fc1d1a30f596fb962e5e9d6d107477 Mon Sep 17 00:00:00 2001 From: ketaki-deodhar Date: Tue, 16 Apr 2024 10:22:52 -0700 Subject: [PATCH 1/6] 20359-busimess summary updates --- .../legal_api/reports/business_document.py | 94 ++++++++++--------- .../services/business_details_version.py | 2 +- 2 files changed, 53 insertions(+), 43 deletions(-) diff --git a/legal-api/src/legal_api/reports/business_document.py b/legal-api/src/legal_api/reports/business_document.py index 58f17fa02e..8c5b6eb85b 100644 --- a/legal-api/src/legal_api/reports/business_document.py +++ b/legal-api/src/legal_api/reports/business_document.py @@ -38,7 +38,7 @@ class BusinessDocument: def __init__(self, business, document_key): """Create the Report instance.""" - self._legal_entity = business + self._business = business self._document_key = document_key self._report_date_time = LegislationDatetime.now() self._epoch_filing_date = None @@ -63,7 +63,7 @@ def get_json(self): def _get_report_filename(self): report_date = str(self._report_date_time)[:19] return "{}_{}_{}.pdf".format( - self._legal_entity.identifier, report_date, ReportMeta.reports[self._document_key]["reportName"] + self._business.identifier, report_date, ReportMeta.reports[self._document_key]["reportName"] ).replace(" ", "_") def _get_template(self): @@ -120,8 +120,11 @@ def _get_template_data(self, get_json=False): try: # get document data business_json["reportType"] = self._document_key - business_json["business"] = self._legal_entity.json() - business_json["business"]["businessName"] = self._legal_entity.business_name + business_json["business"] = self._business.json() + if self._business.alternate_names: + business_json["business"]["businessName"] = self._business.alternate_names[0].name + else: + business_json["business"]["businessName"] = self._business.business_name business_json["registrarInfo"] = {**RegistrarInfo.get_registrar_info(self._report_date_time)} self._set_description(business_json) self._set_epoch_date(business_json) @@ -138,8 +141,8 @@ def _get_template_data(self, get_json=False): self._set_amalgamating_details(business_json) self._set_liquidation_details(business_json) - if self._legal_entity.entity_type in ["SP", "GP"]: - registration_filing = Filing.get_filings_by_types(self._legal_entity, ["registration"]) + if self._business.entity_type in ["SP", "GP"]: + registration_filing = Filing.get_filings_by_types(self._business, ["registration"]) if registration_filing: business_json["business"]["registrationDateTime"] = registration_filing[ 0 @@ -176,14 +179,14 @@ def _get_template_data(self, get_json=False): def _set_epoch_date(self, legal_entity: dict): """Set the epoch filing date (date it was imported from COLIN).""" - epoch_filing = Filing.get_filings_by_status(self._legal_entity, [Filing.Status.EPOCH]) + epoch_filing = Filing.get_filings_by_status(self._business, [Filing.Status.EPOCH]) if epoch_filing: self._epoch_filing_date = epoch_filing[0].effective_date legal_entity["business"]["epochFilingDate"] = self._epoch_filing_date.isoformat() def _set_description(self, legal_entity: dict): """Set business descriptors used by json and pdf template.""" - legal_type = self._legal_entity.entity_type + legal_type = self._business.entity_type corp_type = CorpType.find_by_id(legal_type) legal_entity["entityDescription"] = corp_type.full_desc act = { @@ -194,8 +197,8 @@ def _set_description(self, legal_entity: dict): legal_entity["entityAct"] = act.get(legal_type, "Business Corporations Act") legal_entity["business"]["coopType"] = ( - BusinessDocument.CP_TYPE_DESCRIPTION[self._legal_entity.association_type] - if self._legal_entity.association_type + BusinessDocument.CP_TYPE_DESCRIPTION[self._business.association_type] + if self._business.association_type else NOT_AVAILABLE ) @@ -207,19 +210,19 @@ def _set_description_xtra(self, legal_entity: dict): LegalEntity.EntityTypes.PARTNERSHIP.value: "General Partnership", LegalEntity.EntityTypes.SOLE_PROP.value: "Sole Proprietorship", } - legal_entity["entityShortDescription"] = description.get(self._legal_entity.entity_type, "Corporation") + legal_entity["entityShortDescription"] = description.get(self._business.entity_type, "Corporation") legal_entity["entityInformalDescription"] = legal_entity["entityShortDescription"].lower() def _set_dates(self, legal_entity: dict): # pylint: disable=too-many-branches """Set the business json with formatted dates.""" # business dates - if self._legal_entity.last_ar_date: - last_ar_date = self._legal_entity.last_ar_date.strftime(OUTPUT_DATE_FORMAT) + if self._business.last_ar_date: + last_ar_date = self._business.last_ar_date.strftime(OUTPUT_DATE_FORMAT) else: last_ar_date = NOT_AVAILABLE legal_entity["business"]["last_ar_date"] = last_ar_date - if self._legal_entity.last_agm_date: - last_agm_date = self._legal_entity.last_agm_date.strftime(OUTPUT_DATE_FORMAT) + if self._business.last_agm_date: + last_agm_date = self._business.last_agm_date.strftime(OUTPUT_DATE_FORMAT) else: last_agm_date = NOT_AVAILABLE legal_entity["business"]["last_agm_date"] = last_agm_date @@ -227,9 +230,9 @@ def _set_dates(self, legal_entity: dict): # pylint: disable=too-many-branches legal_entity["business"]["epochFilingDate"] = LegislationDatetime.as_legislation_timezone( datetime.fromisoformat(epoch_date) ).strftime(OUTPUT_DATE_FORMAT) - if self._legal_entity.restoration_expiry_date: + if self._business.restoration_expiry_date: legal_entity["business"]["restorationExpiryDate"] = LegislationDatetime.format_as_report_string( - self._legal_entity.restoration_expiry_date + self._business.restoration_expiry_date ) # state change dates for filing in legal_entity.get("stateFilings", []): @@ -258,27 +261,27 @@ def _set_dates(self, legal_entity: dict): # pylint: disable=too-many-branches datetime.fromisoformat(registration_datetime_str) ) # founding dates - founding_datetime = LegislationDatetime.as_legislation_timezone(self._legal_entity.founding_date) + founding_datetime = LegislationDatetime.as_legislation_timezone(self._business.founding_date) legal_entity["formatted_founding_date_time"] = LegislationDatetime.format_as_report_string(founding_datetime) legal_entity["formatted_founding_date"] = founding_datetime.strftime(OUTPUT_DATE_FORMAT) # dissolution dates - if self._legal_entity.dissolution_date: - dissolution_datetime = LegislationDatetime.as_legislation_timezone(self._legal_entity.dissolution_date) + if self._business.dissolution_date: + dissolution_datetime = LegislationDatetime.as_legislation_timezone(self._business.dissolution_date) legal_entity["formatted_dissolution_date"] = dissolution_datetime.strftime(OUTPUT_DATE_FORMAT) # report dates legal_entity["report_date_time"] = LegislationDatetime.format_as_report_string(self._report_date_time) legal_entity["report_date"] = self._report_date_time.strftime(OUTPUT_DATE_FORMAT) - if self._legal_entity.start_date: - legal_entity["start_date_utc"] = self._legal_entity.start_date.strftime(OUTPUT_DATE_FORMAT) - if self._legal_entity.restoration_expiry_date: + if self._business.start_date: + legal_entity["start_date_utc"] = self._business.start_date.strftime(OUTPUT_DATE_FORMAT) + if self._business.restoration_expiry_date: formatted_restoration_expiry_date = LegislationDatetime.format_as_report_expiry_string( - self._legal_entity.restoration_expiry_date + self._business.restoration_expiry_date ) legal_entity["formatted_restoration_expiry_date"] = formatted_restoration_expiry_date def _set_addresses(self, legal_entity: dict): """Set business addresses.""" - address_json = get_addresses(self._legal_entity.identifier).json + address_json = get_addresses(self._business.identifier).json for office_type in ["registeredOffice", "recordsOffice", "businessOffice"]: if office_type in address_json: for key, value in address_json[office_type].items(): @@ -287,7 +290,7 @@ def _set_addresses(self, legal_entity: dict): def _set_directors(self, legal_entity: dict): """Set directors (these have a different schema than parties).""" - directors_json = get_directors(self._legal_entity.identifier).json["directors"] + directors_json = get_directors(self._business.identifier).json["directors"] for director in directors_json: if director.get("mailingAddress"): director["mailingAddress"] = BusinessDocument._format_address(director["mailingAddress"]) @@ -297,17 +300,19 @@ def _set_directors(self, legal_entity: dict): def _set_parties(self, legal_entity: dict): """Set the parties of the business (all parties).""" - party_json = get_parties(self._legal_entity.identifier).json["parties"] + party_json = get_parties(self._business.identifier).json["parties"] for party in party_json: if party.get("mailingAddress"): party["mailingAddress"] = BusinessDocument._format_address(party["mailingAddress"]) if party.get("deliveryAddress"): party["deliveryAddress"] = BusinessDocument._format_address(party["deliveryAddress"]) + if not party.get("officer", {}).get("partyType") and not party.get("officer", {}).get("lastName"): + party["officer"]["partyType"] = "organization" legal_entity["parties"] = party_json def _set_name_translations(self, legal_entity: dict): """Set the aliases.""" - aliases = AlternateName.find_by_name_type(self._legal_entity.id, "TRANSLATION") + aliases = AlternateName.find_by_name_type(self._business.id, "TRANSLATION") legal_entity["listOfTranslations"] = [alias.json for alias in aliases] def _set_business_state_changes(self, legal_entity: dict): @@ -315,7 +320,7 @@ def _set_business_state_changes(self, legal_entity: dict): state_filings = [] # Any filings like restoration, liquidation etc. that changes the state must be included here for filing in Filing.get_filings_by_types( - self._legal_entity, + self._business, [ "dissolution", "restorationApplication", @@ -331,7 +336,7 @@ def _set_business_state_changes(self, legal_entity: dict): state_filings.append(self._format_state_filing(filing)) # If it is amalgamating business if legal_entity.get("business").get("amalgamatedInto"): - amalgamating_business = self._legal_entity.amalgamating_businesses.one_or_none() + 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.insert(0, self._format_state_filing(filing)) @@ -339,11 +344,11 @@ def _set_business_state_changes(self, legal_entity: dict): def _set_record_keepers(self, legal_entity: dict): """Set the custodians of the business (parties with custodian role).""" - if self._legal_entity.state.name == "HISTORICAL": + if self._business.state.name == "HISTORICAL": custodian_json = [ party_role.json - for party_role in self._legal_entity.entity_roles.all() - if party_role.role.lower() == "custodian" + for party_role in self._business.entity_roles.all() + if party_role.role_type.lower() == "custodian" ] for custodian in custodian_json: custodian["mailingAddress"] = BusinessDocument._format_address(custodian["mailingAddress"]) @@ -356,7 +361,7 @@ def _set_business_changes(self, legal_entity: dict): alterations = [] # Any future filings that includes a company name/type change must be added here for filing in Filing.get_filings_by_types( - self._legal_entity, + self._business, ["alteration", "correction", "changeOfName", "changeOfRegistration", "specialResolution"], ): filing_meta = filing.meta_data @@ -415,10 +420,10 @@ def _format_state_filing(self, filing: Filing) -> dict: filing_meta = filing.meta_data if filing.filing_type == "dissolution": filing_info["filingName"] = BusinessDocument._get_summary_display_name( - filing.filing_type, filing_meta["dissolution"]["dissolutionType"], self._legal_entity.entity_type + filing.filing_type, filing_meta["dissolution"]["dissolutionType"], self._business.entity_type ) if ( - self._legal_entity.entity_type in ["SP", "GP"] + self._business.entity_type in ["SP", "GP"] and filing_meta["dissolution"]["dissolutionType"] == "voluntary" ): filing_info["dissolution_date_str"] = LegislationDatetime.as_legislation_timezone_from_date_str( @@ -426,7 +431,7 @@ def _format_state_filing(self, filing: Filing) -> dict: ).strftime(OUTPUT_DATE_FORMAT) elif filing.filing_type == "restoration": filing_info["filingName"] = BusinessDocument._get_summary_display_name( - filing.filing_type, filing.filing_sub_type, self._legal_entity.entity_type + filing.filing_type, filing.filing_sub_type, self._business.entity_type ) if filing.filing_sub_type in ["limitedRestoration", "limitedRestorationExtension"]: expiry_date = filing_meta["restoration"]["expiry"] @@ -456,7 +461,7 @@ def _format_state_filing(self, filing: Filing) -> dict: def _set_amalgamation_details(self, legal_entity: dict): """Set amalgamation filing data.""" amalgamated_businesses = [] - filings = Filing.get_filings_by_types(self._legal_entity.id, ["amalgamationApplication"]) + filings = Filing.get_filings_by_types(self._business, ["amalgamationApplication"]) if filings: amalgamation_application = filings[0] legal_entity["business"]["amalgamatedEntity"] = True @@ -465,7 +470,7 @@ def _set_amalgamation_details(self, legal_entity: dict): amalgamated_businesses_info = {"legalName": "Not Available", "identifier": "Not Available"} amalgamated_businesses.append(amalgamated_businesses_info) else: - amalgamation = self._legal_entity.amalgamation.one_or_none() + amalgamation = self._business.amalgamation.one_or_none() amalgamating_businesses = amalgamation.amalgamating_businesses.all() for amalgamating_business in amalgamating_businesses: if ting_business := LegalEntity.find_by_internal_id(amalgamating_business.legal_entity_id): @@ -491,7 +496,7 @@ def _set_amalgamating_details(self, legal_entity: dict): def _set_liquidation_details(self, legal_entity: dict): """Set partial liquidation filing data.""" liquidation_info = {} - liquidation = Filing.get_filings_by_types(self._legal_entity, ["voluntaryLiquidation"]) + liquidation = Filing.get_filings_by_types(self._business, ["voluntaryLiquidation"]) if liquidation: liquidation_info["filingDateTime"] = liquidation[0].filing_date.isoformat() legal_entity["business"]["state"] = LegalEntity.State.LIQUIDATION.name @@ -516,9 +521,14 @@ def _format_address(address): return address def _set_meta_info(self, legal_entity: dict): - legal_entity["environment"] = f"{self._get_environment()} BUSINESS #{self._legal_entity.identifier}".lstrip() + legal_entity["environment"] = f"{self._get_environment()} BUSINESS #{self._business.identifier}".lstrip() legal_entity["meta_title"] = "Business Summary on {}".format(legal_entity["report_date_time"]) - legal_entity["meta_subject"] = "{} ({})".format(self._legal_entity.legal_name, self._legal_entity.identifier) + if self._business.alternate_names and self._business.legal_name is None: + legal_entity["meta_subject"] = "{} ({})".format( + self._business.alternate_names[0].name, self._business.identifier + ) + else: + legal_entity["meta_subject"] = "{} ({})".format(self._business.legal_name, self._business.identifier) @staticmethod def _get_environment(): diff --git a/legal-api/src/legal_api/services/business_details_version.py b/legal-api/src/legal_api/services/business_details_version.py index b1b42631ae..c1ce6c9c05 100644 --- a/legal-api/src/legal_api/services/business_details_version.py +++ b/legal-api/src/legal_api/services/business_details_version.py @@ -459,7 +459,7 @@ def get_name_translations_revision(filing, legal_entity_id) -> dict: ) name_translations_version = history_cls(AlternateName) - columns_to_select = [col for col in name_translations_version.__table__.columns if col.name != 'changed'] + columns_to_select = [col for col in name_translations_version.__table__.columns if col.name != "changed"] name_translations_history = ( db.session.query(*columns_to_select) .filter(name_translations_version.change_filing_id == filing.id) From e64e7ee431d8abf9a9d2493ce0a6114d842760d9 Mon Sep 17 00:00:00 2001 From: ketaki-deodhar Date: Tue, 16 Apr 2024 11:28:00 -0700 Subject: [PATCH 2/6] 20359-updates after review --- legal-api/src/legal_api/reports/business_document.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/legal-api/src/legal_api/reports/business_document.py b/legal-api/src/legal_api/reports/business_document.py index 8c5b6eb85b..cb1655598d 100644 --- a/legal-api/src/legal_api/reports/business_document.py +++ b/legal-api/src/legal_api/reports/business_document.py @@ -121,10 +121,7 @@ def _get_template_data(self, get_json=False): # get document data business_json["reportType"] = self._document_key business_json["business"] = self._business.json() - if self._business.alternate_names: - business_json["business"]["businessName"] = self._business.alternate_names[0].name - else: - business_json["business"]["businessName"] = self._business.business_name + business_json["business"]["businessName"] = self._business.business_name business_json["registrarInfo"] = {**RegistrarInfo.get_registrar_info(self._report_date_time)} self._set_description(business_json) self._set_epoch_date(business_json) From 60d5ee292aa5bcc1b168f443082aeca2160c89ff Mon Sep 17 00:00:00 2001 From: ketaki-deodhar Date: Tue, 16 Apr 2024 12:15:18 -0700 Subject: [PATCH 3/6] 20359-update logic for business name --- legal-api/src/legal_api/models/business_common.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/legal-api/src/legal_api/models/business_common.py b/legal-api/src/legal_api/models/business_common.py index fbc7ac17ae..fe01f90ca2 100644 --- a/legal-api/src/legal_api/models/business_common.py +++ b/legal-api/src/legal_api/models/business_common.py @@ -209,9 +209,7 @@ def business_name(self): if not self.is_firm: return self._legal_name - if self.is_alternate_name_entity and ( - alternate_name := AlternateName.find_by_identifier(identifier=self.identifier) - ): + if alternate_name := AlternateName.find_by_identifier(identifier=self.identifier): return alternate_name.name return None From 56f0de2b35bd8ff19605fbcd2679e954c1f3bb4e Mon Sep 17 00:00:00 2001 From: ketaki-deodhar Date: Tue, 16 Apr 2024 13:28:11 -0700 Subject: [PATCH 4/6] 20359-update logic meta_info --- legal-api/src/legal_api/reports/business_document.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/legal-api/src/legal_api/reports/business_document.py b/legal-api/src/legal_api/reports/business_document.py index cb1655598d..233fff3232 100644 --- a/legal-api/src/legal_api/reports/business_document.py +++ b/legal-api/src/legal_api/reports/business_document.py @@ -520,12 +520,7 @@ def _format_address(address): def _set_meta_info(self, legal_entity: dict): legal_entity["environment"] = f"{self._get_environment()} BUSINESS #{self._business.identifier}".lstrip() legal_entity["meta_title"] = "Business Summary on {}".format(legal_entity["report_date_time"]) - if self._business.alternate_names and self._business.legal_name is None: - legal_entity["meta_subject"] = "{} ({})".format( - self._business.alternate_names[0].name, self._business.identifier - ) - else: - legal_entity["meta_subject"] = "{} ({})".format(self._business.legal_name, self._business.identifier) + legal_entity["meta_subject"] = "{} ({})".format(self._business.business_name, self._legal_entity.identifier) @staticmethod def _get_environment(): From 2492703e8d3a57baa13a2b112ee6f15303c7b063 Mon Sep 17 00:00:00 2001 From: ketaki-deodhar Date: Tue, 16 Apr 2024 13:33:34 -0700 Subject: [PATCH 5/6] 20359-update to use business object --- legal-api/src/legal_api/reports/business_document.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/legal-api/src/legal_api/reports/business_document.py b/legal-api/src/legal_api/reports/business_document.py index 233fff3232..e45fdcc8ed 100644 --- a/legal-api/src/legal_api/reports/business_document.py +++ b/legal-api/src/legal_api/reports/business_document.py @@ -520,7 +520,7 @@ def _format_address(address): def _set_meta_info(self, legal_entity: dict): legal_entity["environment"] = f"{self._get_environment()} BUSINESS #{self._business.identifier}".lstrip() legal_entity["meta_title"] = "Business Summary on {}".format(legal_entity["report_date_time"]) - legal_entity["meta_subject"] = "{} ({})".format(self._business.business_name, self._legal_entity.identifier) + legal_entity["meta_subject"] = "{} ({})".format(self._business.business_name, self._business.identifier) @staticmethod def _get_environment(): From 9c3545e5f8e9ff07c42047fbad71e25991f97762 Mon Sep 17 00:00:00 2001 From: ketaki-deodhar Date: Tue, 16 Apr 2024 14:28:41 -0700 Subject: [PATCH 6/6] 20359-update to colin_entity model --- legal-api/src/legal_api/models/colin_entity.py | 1 + legal-api/src/legal_api/reports/business_document.py | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/legal-api/src/legal_api/models/colin_entity.py b/legal-api/src/legal_api/models/colin_entity.py index 4de82c8c4b..32a0c88256 100644 --- a/legal-api/src/legal_api/models/colin_entity.py +++ b/legal-api/src/legal_api/models/colin_entity.py @@ -84,6 +84,7 @@ def json(self) -> dict: "id": self.id, "organizationName": self.organization_name, "identifier": self.identifier, + "partyType": "organization", } } member["officer"]["email"] = self.email diff --git a/legal-api/src/legal_api/reports/business_document.py b/legal-api/src/legal_api/reports/business_document.py index e45fdcc8ed..5e246c5676 100644 --- a/legal-api/src/legal_api/reports/business_document.py +++ b/legal-api/src/legal_api/reports/business_document.py @@ -303,8 +303,6 @@ def _set_parties(self, legal_entity: dict): party["mailingAddress"] = BusinessDocument._format_address(party["mailingAddress"]) if party.get("deliveryAddress"): party["deliveryAddress"] = BusinessDocument._format_address(party["deliveryAddress"]) - if not party.get("officer", {}).get("partyType") and not party.get("officer", {}).get("lastName"): - party["officer"]["partyType"] = "organization" legal_entity["parties"] = party_json def _set_name_translations(self, legal_entity: dict):