diff --git a/queue_services/entity-filer/src/entity_filer/filing_processors/annual_report.py b/queue_services/entity-filer/src/entity_filer/filing_processors/annual_report.py index 407241b006..9c808ebdda 100644 --- a/queue_services/entity-filer/src/entity_filer/filing_processors/annual_report.py +++ b/queue_services/entity-filer/src/entity_filer/filing_processors/annual_report.py @@ -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') @@ -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 + 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(), diff --git a/queue_services/entity-filer/src/entity_filer/worker.py b/queue_services/entity-filer/src/entity_filer/worker.py index f0bada99dc..a5e82749b8 100644 --- a/queue_services/entity-filer/src/entity_filer/worker.py +++ b/queue_services/entity-filer/src/entity_filer/worker.py @@ -78,13 +78,13 @@ qsm = QueueServiceManager() # pylint: disable=invalid-name +flags = Flags() # pylint: disable=invalid-name 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) -flags = Flags() if FLASK_APP.config.get('LD_SDK_KEY', None): flags.init_app(FLASK_APP) @@ -240,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'): flag_on = flags.is_on('enable-involuntary-dissolution') diff --git a/queue_services/entity-filer/tests/unit/__init__.py b/queue_services/entity-filer/tests/unit/__init__.py index 9e206f156f..0c45b7e08a 100644 --- a/queue_services/entity-filer/tests/unit/__init__.py +++ b/queue_services/entity-filer/tests/unit/__init__.py @@ -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: diff --git a/queue_services/entity-filer/tests/unit/filing_processors/test_annual_report.py b/queue_services/entity-filer/tests/unit/filing_processors/test_annual_report.py index 8acd96db49..d81fc415fc 100644 --- a/queue_services/entity-filer/tests/unit/filing_processors/test_annual_report.py +++ b/queue_services/entity-filer/tests/unit/filing_processors/test_annual_report.py @@ -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 @@ -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() @@ -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' + 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):