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 8 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,13 @@ 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

# 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
10 changes: 8 additions & 2 deletions queue_services/entity-filer/src/entity_filer/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,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
from legal_api.utils.datetime import timezone
from sentry_sdk import capture_message
Expand Down Expand Up @@ -80,13 +81,16 @@


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)

def get_filing_types(legal_filings: dict):
"""Get the filing type fee codes for the filing.
Expand Down Expand Up @@ -161,7 +165,7 @@ def publish_gcp_queue_event(business: Business, filing: Filing):
}
}
)

gcp_queue.publish(subject,to_queue_message(ce))

except Exception as err: # pylint: disable=broad-except; we don't want to fail out the filing, so ignore all.
Expand Down Expand Up @@ -231,7 +235,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
36 changes: 36 additions & 0 deletions queue_services/entity-filer/tests/unit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,3 +586,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.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 @@ -18,13 +18,15 @@
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,
)
Expand Down Expand Up @@ -98,3 +100,34 @@ async def test_process_ar_filing_no_agm(app, session):
assert filing.status == Filing.Status.COMPLETED.value
assert business.last_agm_date == agm_date
assert datetime.datetime.date(business.last_ar_date) == ar_date


def test_process_ar_filing_involuntary_dissolution(app, session):
"""Assert that an AR filling can be applied to the model correctly."""
from entity_filer.filing_processors import annual_report
# vars
payment_id = str(random.SystemRandom().getrandbits(0x58))
identifier = 'CP1234567'

# create a business that is not eligible for dissolution. ('CP' is not eligible types)
business = create_business(identifier, 'CP')
# create the batch and batch_processing that are in processing.
batch = create_batch()
batch_processing = create_batch_processing(business, batch.id)
now = datetime.date(2020, 9, 17)
ar_date = datetime.date(2020, 8, 5)
agm_date = datetime.date(2020, 7, 1)
ar = copy.deepcopy(ANNUAL_REPORT)
ar['filing']['business']['identifier'] = identifier
ar['filing']['annualReport']['annualReportDate'] = ar_date.isoformat()
ar['filing']['annualReport']['annualGeneralMeetingDate'] = agm_date.isoformat()

filing_meta = FilingMeta()

# TEST
with freeze_time(now):
filing = create_filing(payment_id, ar, business.id)
annual_report.process(business, filing.filing_json['filing'], filing_meta=filing_meta)

# check it out
assert batch_processing.status == BatchProcessing.BatchProcessingStatus.WITHDRAWN.value
argush3 marked this conversation as resolved.
Show resolved Hide resolved
Loading