diff --git a/jobs/involuntary-dissolutions/involuntary_dissolutions.py b/jobs/involuntary-dissolutions/involuntary_dissolutions.py index 02e0dde3e..775ad8ac5 100644 --- a/jobs/involuntary-dissolutions/involuntary_dissolutions.py +++ b/jobs/involuntary-dissolutions/involuntary_dissolutions.py @@ -279,19 +279,22 @@ async def stage_3_process(app: Flask, qsm: QueueService): if eligible: filing = create_invountary_dissolution_filing(batch_processing.business_id) app.logger.debug(f'Created Involuntary Dissolution Filing with ID: {filing.id}') - await put_filing_on_queue(filing.id, app, qsm) - batch_processing.filing_id = filing.id batch_processing.step = BatchProcessing.BatchProcessingStep.DISSOLUTION - batch_processing.status = BatchProcessing.BatchProcessingStatus.COMPLETED + batch_processing.status = BatchProcessing.BatchProcessingStatus.QUEUED + batch_processing.last_modified = datetime.utcnow() + batch_processing.save() + + await put_filing_on_queue(filing.id, app, qsm) + app.logger.debug( - f'Batch Processing with identifier: {batch_processing.business_identifier} has been marked as complete.' + f'Batch Processing with identifier: {batch_processing.business_identifier} has been marked as queued.' ) else: batch_processing.status = BatchProcessing.BatchProcessingStatus.WITHDRAWN batch_processing.notes = 'Moved back into good standing' - batch_processing.last_modified = datetime.utcnow() - batch_processing.save() + batch_processing.last_modified = datetime.utcnow() + batch_processing.save() mark_eligible_batches_completed() app.logger.debug('Marked batches complete when all of their associated batch_processings are completed.') diff --git a/jobs/involuntary-dissolutions/tests/unit/test_involuntary_dissolutions.py b/jobs/involuntary-dissolutions/tests/unit/test_involuntary_dissolutions.py index 72ee6d004..648184b55 100644 --- a/jobs/involuntary-dissolutions/tests/unit/test_involuntary_dissolutions.py +++ b/jobs/involuntary-dissolutions/tests/unit/test_involuntary_dissolutions.py @@ -283,7 +283,7 @@ def test_stage_2_process_update_business(app, session, test_name, status, step): 'test_name, status, step', [ ( 'DISSOLVE_BUSINESS', - BatchProcessing.BatchProcessingStatus.COMPLETED, + BatchProcessing.BatchProcessingStatus.QUEUED, BatchProcessing.BatchProcessingStep.DISSOLUTION ), ( @@ -317,8 +317,9 @@ async def test_stage_3_process(app, session, test_name, status, step): if test_name == 'DISSOLVE_BUSINESS': mock_put_filing_on_queue.assert_called() assert batch_processing.filing_id + assert batch.status == Batch.BatchStatus.PROCESSING + else: + assert batch.status == Batch.BatchStatus.COMPLETED assert batch_processing.status == status assert batch_processing.step == step - - assert batch.status == Batch.BatchStatus.COMPLETED diff --git a/legal-api/migrations/versions/01dc3337e726_add_batch_processing_status.py b/legal-api/migrations/versions/01dc3337e726_add_batch_processing_status.py index c35e37dfe..ff7bbedee 100644 --- a/legal-api/migrations/versions/01dc3337e726_add_batch_processing_status.py +++ b/legal-api/migrations/versions/01dc3337e726_add_batch_processing_status.py @@ -30,7 +30,7 @@ def upgrade(): def downgrade(): # Need to convert any existing QUEUED statuses to PROCESSING - op.execute('UPDATE batch_processing SET status = "PROCESSED" WHERE status = "QUEUED"') + op.execute('UPDATE batch_processing SET status = \'PROCESSING\' WHERE status = \'QUEUED\'') op.execute('ALTER TYPE batch_processing_status RENAME TO tmp_batch_processing_status') old_type.create(op.get_bind()) op.execute('ALTER TABLE batch_processing ALTER COLUMN status TYPE batch_processing_status USING status::text::batch_processing_status') diff --git a/queue_services/entity-filer/src/entity_filer/filing_processors/dissolution.py b/queue_services/entity-filer/src/entity_filer/filing_processors/dissolution.py index 2036220c2..0ff7e58ee 100644 --- a/queue_services/entity-filer/src/entity_filer/filing_processors/dissolution.py +++ b/queue_services/entity-filer/src/entity_filer/filing_processors/dissolution.py @@ -18,11 +18,12 @@ import dpath import sentry_sdk from entity_queue_common.service_utils import QueueException, logger -from legal_api.models import Business, Document, Filing, db +from legal_api.models import BatchProcessing, Business, Document, Filing, db from legal_api.models.document import DocumentType from legal_api.services.filings.validations.dissolution import DissolutionTypes from legal_api.services.minio import MinioService from legal_api.services.pdf_service import RegistrarStampData +from legal_api.utils.datetime import datetime from legal_api.utils.legislation_datetime import LegislationDatetime from entity_filer.filing_meta import FilingMeta @@ -31,7 +32,8 @@ from entity_filer.utils import replace_file_with_certified_copy -def process(business: Business, filing: Dict, filing_rec: Filing, filing_meta: FilingMeta): +# pylint: disable=too-many-locals +def process(business: Business, filing: Dict, filing_rec: Filing, filing_meta: FilingMeta, flag_on: bool = False): """Render the dissolution filing unto the model objects.""" if not (dissolution_filing := filing.get('dissolution')): logger.error('Could not find Dissolution in: %s', filing) @@ -95,6 +97,15 @@ def process(business: Business, filing: Dict, filing_rec: Filing, filing_meta: F 'dissolutionDate': LegislationDatetime.format_as_legislation_date(business.dissolution_date) } + # update batch processing entry, if any is present + if flag_on: + batch_processings = BatchProcessing.find_by(filing_id=filing_rec.id) + for batch_processing in batch_processings: + if batch_processing.status == BatchProcessing.BatchProcessingStatus.QUEUED: + batch_processing.status = BatchProcessing.BatchProcessingStatus.COMPLETED + batch_processing.last_modified = datetime.utcnow() + batch_processing.save() + def _update_cooperative(dissolution_filing: Dict, business: Business, filing: Filing, dissolution_type): """Update COOP data. diff --git a/queue_services/entity-filer/src/entity_filer/worker.py b/queue_services/entity-filer/src/entity_filer/worker.py index a5e82749b..adecf08b1 100644 --- a/queue_services/entity-filer/src/entity_filer/worker.py +++ b/queue_services/entity-filer/src/entity_filer/worker.py @@ -256,7 +256,8 @@ async def process_filing(filing_msg: Dict, flask_app: Flask): # pylint: disable change_of_name.process(business, filing, filing_meta) elif filing.get('dissolution'): - dissolution.process(business, filing, filing_submission, filing_meta) + flag_on = flags.is_on('enable-involuntary-dissolution') + dissolution.process(business, filing, filing_submission, filing_meta, flag_on) elif filing.get('incorporationApplication'): business, filing_submission, filing_meta = incorporation_filing.process(business, diff --git a/queue_services/entity-filer/tests/unit/filing_processors/test_dissolution.py b/queue_services/entity-filer/tests/unit/filing_processors/test_dissolution.py index 9d4fb4afd..2a0111668 100644 --- a/queue_services/entity-filer/tests/unit/filing_processors/test_dissolution.py +++ b/queue_services/entity-filer/tests/unit/filing_processors/test_dissolution.py @@ -13,11 +13,12 @@ # limitations under the License. """The Unit Tests for the Voluntary Dissolution filing.""" import copy +from datedelta import datedelta from datetime import datetime import pytest -from legal_api.models import Business, Office, OfficeType, Party, PartyRole, Filing +from legal_api.models import BatchProcessing, Batch, Business, Office, OfficeType, Party, PartyRole, Filing from legal_api.models.document import DocumentType from legal_api.services.minio import MinioService from legal_api.utils.legislation_datetime import LegislationDatetime @@ -98,8 +99,28 @@ def test_dissolution(app, session, minio_server, legal_type, identifier, dissolu filing_meta = FilingMeta() filing = create_filing('123', filing_json) + if dissolution_type == 'involuntary': + batch = Batch( + batch_type=Batch.BatchType.INVOLUNTARY_DISSOLUTION, + status=Batch.BatchStatus.PROCESSING, + size=1, + ) + batch.save() + batch_processing = BatchProcessing( + batch_id=batch.id, + business_id=business.id, + filing_id=filing.id, + business_identifier=business.identifier, + step=BatchProcessing.BatchProcessingStep.DISSOLUTION, + status=BatchProcessing.BatchProcessingStatus.QUEUED, + created_date=datetime.utcnow()-datedelta(days=42), + trigger_date=datetime.utcnow(), + last_modified=datetime.utcnow() + ) + batch_processing.save() + # test - dissolution.process(business, filing_json['filing'], filing, filing_meta) + dissolution.process(business, filing_json['filing'], filing, filing_meta, True) business.save() # validate @@ -127,6 +148,9 @@ def test_dissolution(app, session, minio_server, legal_type, identifier, dissolu assert_pdf_contains_text('Filed on ', affidavit_obj.read()) assert filing_meta.dissolution['dissolutionType'] == dissolution_type + if dissolution_type == 'involuntary': + assert batch_processing + assert batch_processing.status == BatchProcessing.BatchProcessingStatus.COMPLETED expected_dissolution_date = filing.effective_date if dissolution_type == 'voluntary' and business.legal_type in (Business.LegalTypes.SOLE_PROP.value,