Skip to content

Commit

Permalink
19191 Updated models in legal-api to use NAICS fields in AlternateName (
Browse files Browse the repository at this point in the history
#2396)

* 19191-updates for legal-api

Signed-off-by: Hongjing Chen <[email protected]>

* remove unused constant

Signed-off-by: Hongjing Chen <[email protected]>

* revert

Signed-off-by: Hongjing Chen <[email protected]>

* revert-2

Signed-off-by: Hongjing Chen <[email protected]>

---------

Signed-off-by: Hongjing Chen <[email protected]>
  • Loading branch information
chenhongjing authored Jan 19, 2024
1 parent 734d164 commit 50cf58e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
12 changes: 12 additions & 0 deletions legal-api/src/legal_api/models/alternate_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class NameType(BaseEnum):
"name",
"name_type",
"start_date",
"naics_key",
"naics_code",
"naics_description"
]
}

Expand All @@ -50,6 +53,9 @@ class NameType(BaseEnum):
bn15 = db.Column("bn15", db.String(20), nullable=True)
start_date = db.Column("start_date", db.DateTime(timezone=True), nullable=False)
end_date = db.Column("end_date", db.DateTime(timezone=True), nullable=True)
naics_key = db.Column("naics_key", db.String(50), nullable=True)
naics_code = db.Column("naics_code", db.String(10), nullable=True)
naics_description = db.Column("naics_description", db.String(300), nullable=True)

# parent keys
legal_entity_id = db.Column("legal_entity_id", db.Integer, db.ForeignKey("legal_entities.id"))
Expand All @@ -62,3 +68,9 @@ def save(self):
"""Save the object to the database immediately."""
db.session.add(self)
db.session.commit()

@classmethod
def find_by_identifier(cls, identifier: str) -> AlternateName | None:
"""Return None or the AlternateName found by its registration number."""
alternate_name = cls.query.filter_by(identifier=identifier).one_or_none()
return alternate_name
17 changes: 15 additions & 2 deletions legal-api/src/legal_api/models/legal_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,9 +786,22 @@ def find_by_legal_name(cls, legal_name: str = None):
@classmethod
def find_by_identifier(cls, identifier: str = None):
"""Return a Business by the id assigned by the Registrar."""
if not identifier or not cls.validate_identifier(
entity_type=None, identifier=identifier
):
return None

legal_entity = None
if identifier:
non_entity_types = [LegalEntity.EntityTypes.PERSON.value, LegalEntity.EntityTypes.ORGANIZATION.value]

if identifier.startswith("FM"):
if alt_name := AlternateName.find_by_identifier(identifier):
legal_entity = cls.find_by_id(alt_name.legal_entity_id)
else:
non_entity_types = [
LegalEntity.EntityTypes.PERSON.value,
LegalEntity.EntityTypes.ORGANIZATION.value,
]

legal_entity = (
cls.query.filter(~LegalEntity.entity_type.in_(non_entity_types))
.filter_by(identifier=identifier)
Expand Down

0 comments on commit 50cf58e

Please sign in to comment.