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

19191 Updated models in legal-api to use NAICS fields in AlternateName #2396

Merged
merged 4 commits into from
Jan 19, 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
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(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Loading