Skip to content

Commit

Permalink
19263 continuation in validation and db updates (bcgov#2720)
Browse files Browse the repository at this point in the history
  • Loading branch information
vysakh-menon-aot authored May 29, 2024
1 parent 77636c4 commit acdc05c
Show file tree
Hide file tree
Showing 20 changed files with 1,296 additions and 115 deletions.
97 changes: 97 additions & 0 deletions legal-api/migrations/versions/c4732cd8abfd_jurisdiction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
"""jurisdiction
Revision ID: c4732cd8abfd
Revises: ef8f033d317b
Create Date: 2024-05-24 14:38:45.440604
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = 'c4732cd8abfd'
down_revision = 'ef8f033d317b'
branch_labels = None
depends_on = None


def upgrade():
op.create_table('jurisdictions',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('country', sa.String(length=10), nullable=False),
sa.Column('region', sa.String(length=10), nullable=True),
sa.Column('identifier', sa.String(length=50), nullable=True),
sa.Column('legal_name', sa.String(length=1000), nullable=True),
sa.Column('tax_id', sa.String(length=15), nullable=True),
sa.Column('incorporation_date', sa.DateTime(timezone=True), nullable=True),
sa.Column('expro_identifier', sa.String(length=10), nullable=True),
sa.Column('expro_legal_name', sa.String(length=1000), nullable=True),
sa.Column('business_id', sa.Integer(), nullable=False),
sa.Column('filing_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['business_id'], ['businesses.id'], ),
sa.ForeignKeyConstraint(['filing_id'], ['filings.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_jurisdictions_business_id'), 'jurisdictions', ['business_id'], unique=False)
op.create_index(op.f('ix_jurisdictions_filing_id'), 'jurisdictions', ['filing_id'], unique=False)

op.create_table('jurisdictions_version',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('country', sa.String(length=10), nullable=False),
sa.Column('region', sa.String(length=10), nullable=True),
sa.Column('identifier', sa.String(length=50), nullable=True),
sa.Column('legal_name', sa.String(length=1000), nullable=True),
sa.Column('tax_id', sa.String(length=15), nullable=True),
sa.Column('incorporation_date', sa.DateTime(timezone=True), nullable=True),
sa.Column('expro_identifier', sa.String(length=10), nullable=True),
sa.Column('expro_legal_name', sa.String(length=1000), nullable=True),
sa.Column('business_id', sa.Integer(), nullable=False),
sa.Column('filing_id', sa.Integer(), nullable=False),
sa.Column('transaction_id', sa.BigInteger(), autoincrement=False, nullable=False),
sa.Column('end_transaction_id', sa.BigInteger(), nullable=True),
sa.Column('operation_type', sa.SmallInteger(), nullable=False),
sa.ForeignKeyConstraint(['filing_id'], ['filings.id']),
sa.ForeignKeyConstraint(['business_id'], ['businesses.id']),
sa.PrimaryKeyConstraint('id', 'transaction_id')
)
op.create_index(op.f('ix_jurisdictions_version_end_transaction_id'), 'jurisdictions_version', ['end_transaction_id'], unique=False)
op.create_index(op.f('ix_jurisdictions_version_business_id'), 'jurisdictions_version', ['business_id'], unique=False)
op.create_index(op.f('ix_jurisdictions_version_filing_id'), 'jurisdictions_version', ['filing_id'], unique=False)
op.create_index(op.f('ix_jurisdictions_version_operation_type'), 'jurisdictions_version', ['operation_type'], unique=False)
op.create_index(op.f('ix_jurisdictions_version_transaction_id'), 'jurisdictions_version', ['transaction_id'], unique=False)

op.drop_column('businesses', 'foreign_legal_type')
op.drop_column('businesses', 'foreign_identifier')
op.drop_column('businesses', 'foreign_incorporation_date')

op.drop_column('businesses_version', 'foreign_legal_type')
op.drop_column('businesses_version', 'foreign_identifier')
op.drop_column('businesses_version', 'foreign_incorporation_date')

op.add_column('documents', sa.Column('file_name', sa.String(length=1000), nullable=True))
op.add_column('documents_version', sa.Column('file_name', sa.String(length=1000), nullable=True))


def downgrade():
op.drop_column('documents_version', 'file_name')
op.drop_column('documents', 'file_name')

op.add_column('businesses_version', sa.Column('foreign_incorporation_date', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=True))
op.add_column('businesses_version', sa.Column('foreign_identifier', sa.VARCHAR(length=15), autoincrement=False, nullable=True))
op.add_column('businesses_version', sa.Column('foreign_legal_type', sa.VARCHAR(length=10), autoincrement=False, nullable=True))

op.add_column('businesses', sa.Column('foreign_incorporation_date', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=True))
op.add_column('businesses', sa.Column('foreign_identifier', sa.VARCHAR(length=15), autoincrement=False, nullable=True))
op.add_column('businesses', sa.Column('foreign_legal_type', sa.VARCHAR(length=10), autoincrement=False, nullable=True))

op.drop_index(op.f('ix_jurisdictions_version_end_transaction_id'), table_name='jurisdictions_version')
op.drop_index(op.f('ix_jurisdictions_version_business_id'), table_name='jurisdictions_version')
op.drop_index(op.f('ix_jurisdictions_version_filing_id'), table_name='jurisdictions_version')
op.drop_index(op.f('ix_jurisdictions_version_operation_type'), table_name='jurisdictions_version')
op.drop_index(op.f('ix_jurisdictions_version_transaction_id'), table_name='jurisdictions_version')
op.drop_table('jurisdictions_version')

op.drop_index(op.f('ix_jurisdictions_business_id'), table_name='jurisdictions')
op.drop_index(op.f('ix_jurisdictions_filing_id'), table_name='jurisdictions')
op.drop_table('jurisdictions')
2 changes: 1 addition & 1 deletion legal-api/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ minio==7.0.2
PyPDF2==1.26.0
reportlab==3.6.12
html-sanitizer==2.4.1
git+https://github.com/bcgov/[email protected].25#egg=registry_schemas
git+https://github.com/bcgov/[email protected].27#egg=registry_schemas
2 changes: 1 addition & 1 deletion legal-api/requirements/bcregistry-libraries.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
git+https://github.com/bcgov/[email protected].25#egg=registry_schemas
git+https://github.com/bcgov/[email protected].27#egg=registry_schemas
8 changes: 4 additions & 4 deletions legal-api/src/legal_api/core/meta/filing.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,10 @@ class FilingTitles(str, Enum):
'name': 'continuationIn',
'title': 'Continuation In',
'displayName': {
'C': 'BC Limited Company Continuation In Application',
'CBEN': 'BC Benefit Company Continuation In Application',
'CCC': 'BC Community Contribution Company Continuation In Application',
'CUL': 'BC Unlimited Liability Company Continuation In Application',
'C': 'BC Limited Company Continuation Application',
'CBEN': 'BC Benefit Company Continuation Application',
'CCC': 'BC Community Contribution Company Continuation Application',
'CUL': 'BC Unlimited Liability Company Continuation Application',
},
'codes': {
'C': 'CONTI',
Expand Down
45 changes: 38 additions & 7 deletions legal-api/src/legal_api/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from .dc_revocation_reason import DCRevocationReason
from .document import Document, DocumentType
from .filing import Filing
from .jurisdiction import Jurisdiction
from .naics_element import NaicsElement
from .naics_structure import NaicsStructure
from .office import Office, OfficeType
Expand All @@ -45,10 +46,40 @@
from .user import User, UserRoles


__all__ = ('db',
'Address', 'Alias', 'AmalgamatingBusiness', 'Amalgamation', 'Batch', 'BatchProcessing', 'Business',
'ColinLastUpdate', 'Comment', 'Configuration', 'ConsentContinuationOut', 'CorpType', 'DCConnection',
'DCDefinition', 'DCIssuedCredential', 'DCIssuedBusinessUserCredential', 'DCRevocationReason', 'Document',
'DocumentType', 'Filing', 'Office', 'OfficeType', 'Party', 'RegistrationBootstrap', 'RequestTracker',
'Resolution', 'PartyRole', 'ShareClass', 'ShareSeries', 'User', 'UserRoles', 'NaicsStructure', 'NaicsElement'
)
__all__ = (
'db',
'Address',
'Alias',
'AmalgamatingBusiness',
'Amalgamation',
'Batch',
'BatchProcessing',
'Business',
'ColinLastUpdate',
'Comment',
'Configuration',
'ConsentContinuationOut',
'CorpType',
'DCConnection',
'DCDefinition',
'DCIssuedCredential',
'DCIssuedBusinessUserCredential',
'DCRevocationReason',
'Document',
'DocumentType',
'Filing',
'Jurisdiction',
'NaicsElement',
'NaicsStructure',
'Office',
'OfficeType',
'Party',
'PartyRole',
'RegistrationBootstrap',
'RequestTracker',
'Resolution',
'ShareClass',
'ShareSeries',
'User',
'UserRoles',
)
23 changes: 6 additions & 17 deletions legal-api/src/legal_api/models/business.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,7 @@ class AssociationTypes(Enum):
'start_date',
'jurisdiction',
'foreign_jurisdiction_region',
'foreign_identifier',
'foreign_legal_name',
'foreign_legal_type',
'foreign_incorporation_date',
'send_ar_ind',
'restoration_expiry_date',
'continuation_out_date'
Expand Down Expand Up @@ -265,10 +262,7 @@ class AssociationTypes(Enum):

jurisdiction = db.Column('foreign_jurisdiction', db.String(10))
foreign_jurisdiction_region = db.Column('foreign_jurisdiction_region', db.String(10))
foreign_identifier = db.Column(db.String(15))
foreign_legal_name = db.Column(db.String(1000))
foreign_legal_type = db.Column(db.String(10))
foreign_incorporation_date = db.Column(db.DateTime(timezone=True))

# relationships
filings = db.relationship('Filing', lazy='dynamic')
Expand All @@ -281,6 +275,7 @@ class AssociationTypes(Enum):
consent_continuation_outs = db.relationship('ConsentContinuationOut', lazy='dynamic')
amalgamating_businesses = db.relationship('AmalgamatingBusiness', lazy='dynamic')
amalgamation = db.relationship('Amalgamation', lazy='dynamic')
jurisdictions = db.relationship('Jurisdiction', lazy='dynamic')

@hybrid_property
def identifier(self):
Expand Down Expand Up @@ -308,8 +303,8 @@ def business_legal_name(self):
if self.is_firm and flag_on:
sort_name = func.trim(
func.coalesce(Party.organization_name, '') +
func.coalesce(Party.last_name+' ', '') +
func.coalesce(Party.first_name+' ', '') +
func.coalesce(Party.last_name + ' ', '') +
func.coalesce(Party.first_name + ' ', '') +
func.coalesce(Party.middle_initial, '')
)

Expand Down Expand Up @@ -422,10 +417,8 @@ def in_dissolution(self):
# check a business has a batch_processing entry that matches business_id and status is not COMPLETED
find_in_batch_processing = db.session.query(BatchProcessing, Batch).\
filter(BatchProcessing.business_id == self.id).\
filter(BatchProcessing.status.notin_([
BatchProcessing.BatchProcessingStatus.COMPLETED,
BatchProcessing.BatchProcessingStatus.WITHDRAWN])
). \
filter(BatchProcessing.status.notin_([BatchProcessing.BatchProcessingStatus.COMPLETED,
BatchProcessing.BatchProcessingStatus.WITHDRAWN])). \
filter(Batch.id == BatchProcessing.batch_id).\
filter(Batch.status != Batch.BatchStatus.COMPLETED).\
filter(Batch.batch_type == Batch.BatchType.INVOLUNTARY_DISSOLUTION).\
Expand Down Expand Up @@ -539,11 +532,7 @@ def _extend_json(self, d):
if self.jurisdiction:
d['jurisdiction'] = self.jurisdiction
d['jurisdictionRegion'] = self.foreign_jurisdiction_region
d['foreignIdentifier'] = self.foreign_identifier
d['foreignLegalName'] = self.foreign_legal_name
d['foreignLegalType'] = self.foreign_legal_type
d['foreignIncorporationDate'] = LegislationDatetime.format_as_legislation_date(
self.foreign_incorporation_date) if self.foreign_incorporation_date else None

d['hasCorrections'] = Filing.has_completed_filing(self.id, 'correction')
d['hasCourtOrders'] = Filing.has_completed_filing(self.id, 'courtOrder')
Expand Down Expand Up @@ -669,7 +658,7 @@ def get_alternate_names(self) -> dict:
).one_or_none()
alternate_names.append({
'name': alias.alias,
'startDate': LegislationDatetime.format_as_legislation_date(filing.effective_date),
'startDate': LegislationDatetime.format_as_legislation_date(filing.effective_date),
'type': alias.type
})

Expand Down
25 changes: 17 additions & 8 deletions legal-api/src/legal_api/models/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,20 @@

from enum import Enum

from sqlalchemy import Column, String, desc
from sqlalchemy import desc

from .db import db


class DocumentType(Enum):
"""Document types."""

AFFIDAVIT = 'affidavit'
AUTHORIZATION_FILE = 'authorization_file'
COOP_RULES = 'coop_rules'
COOP_MEMORANDUM = 'coop_memorandum'
AFFIDAVIT = 'affidavit'
COURT_ORDER = 'court_order'
DIRECTOR_AFFIDAVIT = 'director_affidavit'


class Document(db.Model):
Expand All @@ -40,9 +42,10 @@ class Document(db.Model):
__versioned__ = {}
__tablename__ = 'documents'

id = Column(db.Integer, primary_key=True)
type = Column('type', String(30), nullable=False)
file_key = Column('file_key', String(100), nullable=False)
id = db.Column(db.Integer, primary_key=True)
type = db.Column('type', db.String(30), nullable=False)
file_key = db.Column('file_key', db.String(100), nullable=False)
file_name = db.Column('file_name', db.String(1000))

# parent keys
business_id = db.Column('business_id', db.Integer, db.ForeignKey('businesses.id'), index=True)
Expand All @@ -59,8 +62,14 @@ def find_by_id(cls, document_id: int) -> Document:
return cls.query.filter_by(id=document_id).one_or_none()

@classmethod
def find_by_business_id_and_type(cls, business_id: int, document_type: String):
def find_all_by(cls, filing_id: int, document_type: str):
"""Return all the documents matching filing id and document type."""
return cls.query.filter_by(filing_id=filing_id, type=document_type).all()

@classmethod
def find_by_business_id_and_type(cls, business_id: int, document_type: str):
"""Return the document matching the business id and type."""
return cls.query.filter_by(
business_id=business_id, type=document_type
).order_by(desc(Document.id)).limit(1).one_or_none()
business_id=business_id,
type=document_type
).order_by(desc(Document.id)).first()
64 changes: 64 additions & 0 deletions legal-api/src/legal_api/models/jurisdiction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Copyright © 2024 Province of British Columbia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""This module holds the data about jurisdiction."""
from __future__ import annotations

from .db import db
from .filing import Filing


class Jurisdiction(db.Model): # pylint: disable=too-many-instance-attributes
"""This class manages the jurisdiction."""

__versioned__ = {}
__tablename__ = 'jurisdictions'

id = db.Column(db.Integer, primary_key=True)
country = db.Column('country', db.String(10))
region = db.Column('region', db.String(10))
identifier = db.Column('identifier', db.String(50))
legal_name = db.Column('legal_name', db.String(1000))
tax_id = db.Column('tax_id', db.String(15))
incorporation_date = db.Column('incorporation_date', db.DateTime(timezone=True))
expro_identifier = db.Column('expro_identifier', db.String(10))
expro_legal_name = db.Column('expro_legal_name', db.String(1000))

# parent keys
business_id = db.Column('business_id', db.Integer, db.ForeignKey('businesses.id'), nullable=False, index=True)
filing_id = db.Column('filing_id', db.Integer, db.ForeignKey('filings.id'), nullable=False, index=True)

def save(self):
"""Save the object to the database immediately."""
db.session.add(self)
db.session.commit()

@classmethod
def find_by_id(cls, jurisdiction_id) -> Jurisdiction:
"""Return jurisdiction by the id."""
jurisdiction = None
if jurisdiction_id:
jurisdiction = cls.query.filter_by(id=jurisdiction_id).one_or_none()
return jurisdiction

@classmethod
def get_continuation_in_jurisdiction(cls, business_id) -> Jurisdiction:
"""Return continuation in jurisdiction by the business id."""
jurisdiction = None
if business_id:
# pylint: disable=protected-access
jurisdiction = (db.session.query(Jurisdiction).join(Filing).
filter(Jurisdiction.business_id == business_id).
filter(Filing._filing_type == 'continuationIn').
one_or_none())
return jurisdiction
3 changes: 3 additions & 0 deletions legal-api/src/legal_api/reports/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -1387,6 +1387,9 @@ class ReportMeta: # pylint: disable=too-few-public-methods
'affidavit': {
'documentType': 'affidavit'
},
'directorAffidavit': {
'documentType': 'director_affidavit'
},
'uploadedCourtOrder': {
'documentType': 'court_order'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
validate_court_order,
validate_foreign_jurisdiction,
validate_name_request,
validate_parties_names,
validate_share_structure,
)
from legal_api.services.filings.validations.incorporation_application import validate_offices
Expand Down Expand Up @@ -52,6 +53,8 @@ def validate(amalgamation_json: Dict, account_id) -> Optional[Error]:
msg.extend(validate_name_request(amalgamation_json, legal_type, filing_type))

msg.extend(validate_party(amalgamation_json, amalgamation_type, filing_type))
msg.extend(validate_parties_names(amalgamation_json, filing_type))

if amalgamation_type == Amalgamation.AmalgamationTypes.regular.name:
msg.extend(validate_offices(amalgamation_json, filing_type))
err = validate_share_structure(amalgamation_json, filing_type)
Expand Down
Loading

0 comments on commit acdc05c

Please sign in to comment.