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

21208 update AR filing to withdraw businesses in dissolution where appropriate #2739

Merged
merged 18 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 14 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
5 changes: 5 additions & 0 deletions queue_services/entity-filer/flags.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"flagValues": {
"enable-involuntary-dissolution": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
from typing import Dict

from entity_queue_common.service_utils import logger
from legal_api.models import Business
from legal_api.models import BatchProcessing, Business
from legal_api.services.filings import validations
from legal_api.services.involuntary_dissolution import InvoluntaryDissolutionService

from entity_filer.filing_meta import FilingMeta


def process(business: Business, filing: Dict, filing_meta: FilingMeta):
def process(business: Business, filing: Dict, filing_meta: FilingMeta, flag_on):
"""Render the annual_report onto the business model objects."""
legal_filing_name = 'annualReport'
agm_date = filing[legal_filing_name].get('annualGeneralMeetingDate')
Expand All @@ -44,6 +45,15 @@ def process(business: Business, filing: Dict, filing_meta: FilingMeta):

business.last_ar_year = business.last_ar_year + 1 if business.last_ar_year else business.founding_date.year + 1

# remove dissolution flag if business can be withdrawn
if flag_on and business.in_dissolution:
eligibility, _ = InvoluntaryDissolutionService.check_business_eligibility(business.identifier, False)
if not eligibility:
batch_processing, _ = InvoluntaryDissolutionService.get_in_dissolution_batch_processing(business.id)
batch_processing.status = BatchProcessing.BatchProcessingStatus.WITHDRAWN.value
argush3 marked this conversation as resolved.
Show resolved Hide resolved
batch_processing.notes = 'Moved back to good standing'
batch_processing.last_modified = datetime.datetime.utcnow()

# save the annual report date to the filing meta info
filing_meta.application_date = ar_date
filing_meta.annual_report = {'annualReportDate': ar_date.isoformat(),
Expand Down
11 changes: 9 additions & 2 deletions queue_services/entity-filer/src/entity_filer/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from legal_api import db
from legal_api.core import Filing as FilingCore
from legal_api.models import Business, Filing
from legal_api.services.flags import Flags
from legal_api.utils.datetime import datetime, timezone
from sentry_sdk import capture_message
from sqlalchemy.exc import OperationalError
Expand Down Expand Up @@ -77,13 +78,17 @@


qsm = QueueServiceManager() # pylint: disable=invalid-name
flags = Flags() # pylint: disable=invalid-name
chenhongjing marked this conversation as resolved.
Show resolved Hide resolved
gcp_queue = GcpQueue()
APP_CONFIG = config.get_named_config(os.getenv('DEPLOYMENT_ENV', 'production'))
FLASK_APP = Flask(__name__)
FLASK_APP.config.from_object(APP_CONFIG)
db.init_app(FLASK_APP)
gcp_queue.init_app(FLASK_APP)

if FLASK_APP.config.get('LD_SDK_KEY', None):
flags.init_app(FLASK_APP)

chenhongjing marked this conversation as resolved.
Show resolved Hide resolved

def get_filing_types(legal_filings: dict):
"""Get the filing type fee codes for the filing.
Expand Down Expand Up @@ -139,7 +144,7 @@ def publish_gcp_queue_event(business: Business, filing: Filing):
"""Publish the filing message onto the GCP-QUEUE filing subject."""
try:
subject = APP_CONFIG.BUSINESS_EVENTS_TOPIC
data= {
data = {
'filing': {
'header': {'filingId': filing.id,
'effectiveDate': filing.effective_date.isoformat()
Expand Down Expand Up @@ -235,7 +240,9 @@ async def process_filing(filing_msg: Dict, flask_app: Flask): # pylint: disable
alteration.process(business, filing_submission, filing, filing_meta, is_correction)

elif filing.get('annualReport'):
annual_report.process(business, filing, filing_meta)
flag_on = flags.is_on('enable-involuntary-dissolution')
logger.debug('enable-involuntary-dissolution flag on: %s', flag_on)
annual_report.process(business, filing, filing_meta, flag_on)

elif filing.get('changeOfAddress'):
change_of_address.process(business, filing, filing_meta)
Expand Down
41 changes: 39 additions & 2 deletions queue_services/entity-filer/tests/unit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,12 @@
}


def create_filing(token, json_filing=None, business_id=None, filing_date=EPOCH_DATETIME, bootstrap_id: str = None):
def create_filing(token=None, json_filing=None, business_id=None, filing_date=EPOCH_DATETIME, bootstrap_id: str = None):
"""Return a test filing."""
from legal_api.models import Filing
filing = Filing()
filing.payment_token = str(token)
if token:
filing.payment_token = str(token)
filing.filing_date = filing_date

if json_filing:
Expand Down Expand Up @@ -586,3 +587,39 @@ def factory_completed_filing(business, data_dict, filing_date=FROZEN_DATETIME, p
colin_event.save()
filing.save()
return filing


def create_batch(status=None, size=None, start_date=None):
"""Create a batch"""
from legal_api.models import Batch
batch = Batch()
batch.batch_type = Batch.BatchType.INVOLUNTARY_DISSOLUTION.value
batch.status = status if status else Batch.BatchStatus.PROCESSING.value
if size:
batch.size = size
if start_date:
batch.start_date = start_date

batch.save()
return batch


def create_batch_processing(business, batch_id, step=None, status=None, created_date=None, last_modified=None, meta_data=None):
"""Create a batch processing"""
from legal_api.models import BatchProcessing
batch_processing = BatchProcessing()
batch_processing.business_identifier = business.identifier
batch_processing.business_id = business.id
batch_processing.step = step if step else BatchProcessing.BatchProcessingStep.DISSOLUTION.value
batch_processing.status = status if status else BatchProcessing.BatchProcessingStatus.PROCESSING.value
if created_date:
batch_processing.created_date = created_date
if last_modified:
batch_processing.last_modified = last_modified
if meta_data:
batch_processing.meta_data = meta_data

batch_processing.batch_id = batch_id

batch_processing.save()
return batch_processing
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,57 @@
"""The Test Suites to ensure that the worker is operating correctly."""
import copy
import datetime
import pytest
import random
from unittest.mock import patch

from freezegun import freeze_time
from legal_api.models import Business, Filing
from legal_api.models import BatchProcessing, Business, Filing
from registry_schemas.example_data import ANNUAL_REPORT

# from entity_filer.filing_processors.filing_components import create_party, create_role
from entity_filer.filing_meta import FilingMeta
from entity_filer.worker import process_filing
from tests.unit import (
create_batch,
create_batch_processing,
create_business,
create_filing,
)
from tests import EPOCH_DATETIME


def test_process_ar_filing(app, session):
@pytest.mark.parametrize('test_name,flag_on,in_dissolution,eligibility,legal_type,', [
('AR successfully', True, False, False, 'CP'),
('Not withdrawn from the dissolution process', True, True, True, 'BC'),
('Withdrawn from the dissolution process', True, True, False, 'CP'),
('AR successfully when flag is off', False, True, False, 'CP')
argush3 marked this conversation as resolved.
Show resolved Hide resolved
])
argush3 marked this conversation as resolved.
Show resolved Hide resolved
def test_process_ar_filing_involuntary_dissolution(app, session, test_name, flag_on, in_dissolution, eligibility, legal_type):
"""Assert that an AR filling can be applied to the model correctly."""
from entity_filer.worker import APP_CONFIG
from entity_filer.filing_processors import annual_report
# vars
payment_id = str(random.SystemRandom().getrandbits(0x58))
identifier = 'CP1234567'

# setup
business = create_business(identifier, 'CP')
business_id = business.id
now = datetime.date(2020, 9, 17)
ar_date = datetime.date(2020, 8, 5)
agm_date = datetime.date(2020, 7, 1)
business = create_business(identifier, legal_type)
business.founding_date = EPOCH_DATETIME
business.save()
# create the batch and batch_processing.
batch_status = 'PROCESSING'
if not in_dissolution:
batch_status = 'COMPLETED'
batch = create_batch(status=batch_status)
batch_processing = create_batch_processing(business=business, batch_id=batch.id, status=batch_status)
argush3 marked this conversation as resolved.
Show resolved Hide resolved

now = datetime.datetime.utcnow()
if eligibility:
# setup ar_date to """INTERVAL '26 MONTHS'"" to make the businees is eligibility
ar_date = datetime.date(year=now.year-3, month=now.month-1, day=now.day)
agm_date = datetime.date(year=now.year-3, month=now.month-2, day=now.day)
else:
ar_date = datetime.date(year=now.year, month=now.month-1, day=now.day)
agm_date = datetime.date(year=now.year, month=now.month-2, day=now.day)

ar = copy.deepcopy(ANNUAL_REPORT)
ar['filing']['business']['identifier'] = identifier
ar['filing']['annualReport']['annualReportDate'] = ar_date.isoformat()
Expand All @@ -53,15 +74,25 @@ def test_process_ar_filing(app, session):

# TEST
with freeze_time(now):
filing = create_filing(payment_id, ar, business.id)
filing_id = filing.id
filing_msg = {'filing': {'id': filing_id}}
annual_report.process(business, filing.filing_json['filing'], filing_meta=filing_meta)
filing = create_filing(json_filing=ar, business_id=business.id)
annual_report.process(business, filing.filing_json['filing'], filing_meta=filing_meta, flag_on=flag_on)

# check it out
# NOTE: until we save or convert the dates, they are FakeDate objects, so casting to str()
assert str(business.last_agm_date) == str(agm_date)
assert str(business.last_ar_date) == str(agm_date)
if flag_on and in_dissolution and not eligibility:
assert batch_processing.status == BatchProcessing.BatchProcessingStatus.WITHDRAWN.value
assert batch_processing.notes == 'Moved back to good standing'
argush3 marked this conversation as resolved.
Show resolved Hide resolved
else:
if in_dissolution:
assert batch_processing.status == BatchProcessing.BatchProcessingStatus.PROCESSING.value
else:
assert batch_processing.status == BatchProcessing.BatchProcessingStatus.COMPLETED.value
assert batch_processing.notes == ''
if legal_type == 'CP':
# require the agm for [Business.LegalTypes.COOP.value, Business.LegalTypes.XPRO_LIM_PARTNR.value]
assert str(business.last_agm_date) == str(agm_date)
assert str(business.last_ar_date) == str(agm_date)
else:
assert str(business.last_ar_date) == str(ar_date)


async def test_process_ar_filing_no_agm(app, session):
Expand Down
Loading