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 17 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
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
8 changes: 7 additions & 1 deletion queue_services/entity-filer/src/entity_filer/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@


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__)
Expand All @@ -89,6 +90,9 @@
if FLASK_APP.config.get('LD_SDK_KEY', None):
flags.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 @@ -240,7 +244,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'):
flag_on = flags.is_on('enable-involuntary-dissolution')
Expand Down
5 changes: 3 additions & 2 deletions queue_services/entity-filer/tests/unit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,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
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
"""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
Expand All @@ -27,23 +28,44 @@
from tests.unit import (
create_business,
create_filing,
factory_batch,
factory_batch_processing
)
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'),
('AR successfully', True, False, False, 'BC'),
('Not withdrawn from the dissolution process', True, True, True, 'BC'),
('Withdrawn from the dissolution process', True, True, False, 'BC'),
('AR successfully when flag is off', False, True, False, 'BC'),
('AR successfully when flag is off', False, False, False, 'CP')
])
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 in_dissolution:
batch = factory_batch(status=batch_status)
batch_processing = factory_batch_processing(batch_id=batch.id, identifier=identifier, business_id=business.id, status=batch_status)

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 +75,23 @@ 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
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