Skip to content

Commit

Permalink
Merge branch 'feature-legal-name' of https://github.com/bcgov/lear in…
Browse files Browse the repository at this point in the history
…to 20362
  • Loading branch information
ketaki-deodhar committed Apr 11, 2024
2 parents 96e15cf + 364e817 commit 72d3ed1
Show file tree
Hide file tree
Showing 35 changed files with 219 additions and 152 deletions.
71 changes: 71 additions & 0 deletions docs/oas/business.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1540,6 +1540,25 @@ components:
- code: INVALID_LEGAL_STRUCTURE_DIRECTORS
message: A minimum of 3 directors is required.
filing: 'https://LEGAL-API-HOST/api/v2/businesses/IDENTIFIER/filings/FILING_ID'
alternateNames:
- name: 'Name Translation 1'
nameStartDate: '2021-11-28'
nameType: 'TRANSLATION'
- name: 'Name Translation 2'
nameStartDate: '2023-01-25'
nameType: 'TRANSLATION'
- entityType: 'SP'
identifier: 'FM1111111'
name: 'Some DBA Name'
nameRegisteredDate: '2021-03-16T21:36:07.009977+00:00'
nameStartDate: '2021-03-10'
nameType: 'DBA'
- entityType: 'SP'
identifier: 'FM2222222'
name: 'Another DBA Name'
nameRegisteredDate: '2022-04-16T21:36:07.009977+00:00'
nameStartDate: '2022-04-10'
nameType: 'DBA'
description: 'Organization or enterprising entity engaged in commercial, industrial, or professional activities.'
properties:
lastLedgerTimestamp:
Expand Down Expand Up @@ -1624,6 +1643,58 @@ components:
type: string
description: Filing link related to the warning.
example: '''https://LEGAL-API-HOST/api/v2/businesses/IDENTIFIER/filings/FILING_ID'''
alternateNames:
type: array
description: The alternate name of the business
items:
type: object
properties:
entityType:
type: string
enum:
- SP
- GP
example: 'SP'
description: 'Type of business eg: Sole Proprietorship(SP), Partnership(GP).'
identifier:
type: string
example: 'FM1234567'
pattern: '^[A-Z]{1,3}[0-9]{7}|T[A-Za-z0-9]{9}$'
description: 'Unique code(letters & numbers) to identify a business, issued by the provincial or federal registry.'
name:
type: string
title: The alternate name of the business.
default: ''
examples:
- alternate_name_of_business
pattern: '^(.*)$'
nameRegisteredDate:
type: string
format: date-time
title: The timestamp of the registered date.
default: ''
examples:
- '1970-01-01T00:00:00+00:00'
nameStartDate:
type: string
format: date
title: The start date of the alternate name
default: ''
examples:
- '1970-01-01'
nameEndDate:
type: string
format: date
title: The end date of the alternate name
default: ''
examples:
- '1970-01-01'
nameType:
type: string
title: The type of the alternate name
enum:
- DBA
- TRANSLATION
required:
- identifier
Change_of_address:
Expand Down
2 changes: 1 addition & 1 deletion jobs/email-reminder/services/gcp_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def publisher(self):
self._publisher = pubsub_v1.PublisherClient(credentials=self.credentials_pub)
else:
self._publisher = pubsub_v1.PublisherClient()
return self.credentials_pub
return self._publisher

@staticmethod
def is_valid_envelope(msg: dict):
Expand Down
2 changes: 1 addition & 1 deletion jobs/future-effective-filings/services/gcp_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def publisher(self):
self._publisher = pubsub_v1.PublisherClient(credentials=self.credentials_pub)
else:
self._publisher = pubsub_v1.PublisherClient()
return self.credentials_pub
return self._publisher

@staticmethod
def is_valid_envelope(msg: dict):
Expand Down
2 changes: 1 addition & 1 deletion jobs/update-legal-filings/services/gcp_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def publisher(self):
self._publisher = pubsub_v1.PublisherClient(credentials=self.credentials_pub)
else:
self._publisher = pubsub_v1.PublisherClient()
return self.credentials_pub
return self._publisher

@staticmethod
def is_valid_envelope(msg: dict):
Expand Down
1 change: 0 additions & 1 deletion legal-api/src/legal_api/models/alternate_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ def _slim_json(self):
else None
),
"nameType": self.name_type.name,
"operatingName": self.name, # will be removed in the future
}
],
}
Expand Down
1 change: 0 additions & 1 deletion legal-api/src/legal_api/models/legal_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@ def alternate_names_json(self):
if alternate_name.business_start_date
else None,
"nameType": alternate_name.name_type.name,
"operatingName": alternate_name.name, # will be removed in the future
}
)
else:
Expand Down
21 changes: 2 additions & 19 deletions legal-api/src/legal_api/services/business_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

"""This provides the service for businesses(legal entities and alternate name entities."""
from legal_api.models import AlternateName, LegalEntity
from legal_api.models.business_common import BusinessCommon


class BusinessService:
Expand All @@ -30,17 +29,8 @@ def fetch_business(identifier: str):
return None
if legal_entity := LegalEntity.find_by_identifier(identifier):
return legal_entity

if identifier.startswith("FM") and (alternate_name := AlternateName.find_by_identifier(identifier)):
if alternate_name.is_owned_by_colin_entity:
return alternate_name

legal_entity = LegalEntity.find_by_id(alternate_name.legal_entity_id)
alternate_name_entity = (
alternate_name if legal_entity.entity_type != BusinessCommon.EntityTypes.PARTNERSHIP.value else None
)
return alternate_name_entity

return alternate_name
return None

@staticmethod
Expand All @@ -57,14 +47,7 @@ def fetch_business_by_filing(filing): # pylint: disable=redefined-builtin
if (alternate_name_id := filing.alternate_name_id) and (
alternate_name := AlternateName.find_by_internal_id(alternate_name_id)
):
if alternate_name.is_owned_by_colin_entity:
return alternate_name

legal_entity = LegalEntity.find_by_id(alternate_name.legal_entity_id)
alternate_name_entity = (
alternate_name if legal_entity.entity_type != BusinessCommon.EntityTypes.PARTNERSHIP.value else None
)
return alternate_name_entity
return alternate_name

return None

Expand Down
20 changes: 7 additions & 13 deletions legal-api/tests/unit/models/test_legal_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,14 +746,14 @@ def test_business_name(session, entity_type, legal_name, expected_business_name)
{
"identifier": ALTERNATE_NAME_1_IDENTIFIER,
"entityType": "SP",
"operatingName": ALTERNATE_NAME_1,
"name": ALTERNATE_NAME_1,
"businessStartDate": ALTERNATE_NAME_1_START_DATE_ISO,
"startDate": ALTERNATE_NAME_1_REGISTERED_DATE,
},
{
"identifier": ALTERNATE_NAME_2_IDENTIFIER,
"entityType": "GP",
"operatingName": ALTERNATE_NAME_2,
"name": ALTERNATE_NAME_2,
"businessStartDate": ALTERNATE_NAME_2_START_DATE_ISO,
"startDate": ALTERNATE_NAME_2_REGISTERED_DATE,
},
Expand All @@ -762,7 +762,6 @@ def test_business_name(session, entity_type, legal_name, expected_business_name)
[
{
"identifier": ALTERNATE_NAME_1_IDENTIFIER,
"operatingName": ALTERNATE_NAME_1,
"entityType": "SP",
"nameRegisteredDate": ALTERNATE_NAME_1_REGISTERED_DATE,
"nameStartDate": ALTERNATE_NAME_1_START_DATE,
Expand All @@ -771,7 +770,6 @@ def test_business_name(session, entity_type, legal_name, expected_business_name)
},
{
"identifier": ALTERNATE_NAME_2_IDENTIFIER,
"operatingName": ALTERNATE_NAME_2,
"entityType": "GP",
"nameRegisteredDate": ALTERNATE_NAME_2_REGISTERED_DATE,
"nameStartDate": ALTERNATE_NAME_2_START_DATE,
Expand All @@ -796,7 +794,7 @@ def test_business_name(session, entity_type, legal_name, expected_business_name)
{
"identifier": ALTERNATE_NAME_1_IDENTIFIER,
"entityType": "SP",
"operatingName": ALTERNATE_NAME_1,
"name": ALTERNATE_NAME_1,
"businessStartDate": ALTERNATE_NAME_1_START_DATE_ISO,
"startDate": ALTERNATE_NAME_1_REGISTERED_DATE,
}
Expand All @@ -805,7 +803,6 @@ def test_business_name(session, entity_type, legal_name, expected_business_name)
[
{
"identifier": ALTERNATE_NAME_1_IDENTIFIER,
"operatingName": ALTERNATE_NAME_1,
"entityType": "SP",
"nameRegisteredDate": ALTERNATE_NAME_1_REGISTERED_DATE,
"nameStartDate": ALTERNATE_NAME_1_START_DATE,
Expand All @@ -830,7 +827,7 @@ def test_business_name(session, entity_type, legal_name, expected_business_name)
{
"identifier": ALTERNATE_NAME_2_IDENTIFIER,
"entityType": "GP",
"operatingName": ALTERNATE_NAME_2,
"name": ALTERNATE_NAME_2,
"businessStartDate": ALTERNATE_NAME_2_START_DATE_ISO,
"startDate": ALTERNATE_NAME_2_REGISTERED_DATE,
}
Expand All @@ -839,7 +836,6 @@ def test_business_name(session, entity_type, legal_name, expected_business_name)
[
{
"identifier": ALTERNATE_NAME_2_IDENTIFIER,
"operatingName": ALTERNATE_NAME_2,
"entityType": "GP",
"nameRegisteredDate": ALTERNATE_NAME_2_REGISTERED_DATE,
"nameStartDate": ALTERNATE_NAME_2_START_DATE,
Expand Down Expand Up @@ -867,14 +863,14 @@ def test_business_name(session, entity_type, legal_name, expected_business_name)
{
"identifier": ALTERNATE_NAME_1_IDENTIFIER,
"entityType": "GP",
"operatingName": ALTERNATE_NAME_1,
"name": ALTERNATE_NAME_1,
"businessStartDate": ALTERNATE_NAME_1_START_DATE_ISO,
"startDate": ALTERNATE_NAME_1_REGISTERED_DATE,
},
{
"identifier": ALTERNATE_NAME_2_IDENTIFIER,
"entityType": "SP",
"operatingName": ALTERNATE_NAME_2,
"name": ALTERNATE_NAME_2,
"businessStartDate": ALTERNATE_NAME_2_START_DATE_ISO,
"startDate": ALTERNATE_NAME_2_REGISTERED_DATE,
},
Expand All @@ -883,7 +879,6 @@ def test_business_name(session, entity_type, legal_name, expected_business_name)
[
{
"identifier": ALTERNATE_NAME_1_IDENTIFIER,
"operatingName": ALTERNATE_NAME_1,
"entityType": "GP",
"nameRegisteredDate": ALTERNATE_NAME_1_REGISTERED_DATE,
"nameStartDate": ALTERNATE_NAME_1_START_DATE,
Expand All @@ -892,7 +887,6 @@ def test_business_name(session, entity_type, legal_name, expected_business_name)
},
{
"identifier": ALTERNATE_NAME_2_IDENTIFIER,
"operatingName": ALTERNATE_NAME_2,
"entityType": "SP",
"nameRegisteredDate": ALTERNATE_NAME_2_REGISTERED_DATE,
"nameStartDate": ALTERNATE_NAME_2_START_DATE,
Expand Down Expand Up @@ -939,7 +933,7 @@ def test_alternate_names(session, test_name, legal_entities_info, alternate_name
alternate_name = AlternateName(
identifier=alternate_name_identifier,
name_type=AlternateName.NameType.DBA,
name=alternate_name_info["operatingName"],
name=alternate_name_info["name"],
bn15="111111100BC1111",
start_date=start_date,
business_start_date=business_start_date,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,7 @@ def _slim_json(self):
if self.business_start_date
else None
),
"nameType": self.name_type.name,
"operatingName": self.name, # will be removed in the future
"nameType": self.name_type.name
}
],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,7 @@ def alternate_names_json(self):
)
if alternate_name.business_start_date
else None,
"nameType": alternate_name.name_type.name,
"operatingName": alternate_name.name, # will be removed in the future
"nameType": alternate_name.name_type.name
}
)
else:
Expand Down
Loading

0 comments on commit 72d3ed1

Please sign in to comment.