Skip to content

Commit

Permalink
23352 notice_of_withdrawal_filer (bcgov#3198)
Browse files Browse the repository at this point in the history
* 23352 notice_of_withdrawal_filer

* fix lint issue

* fix the skip NoW filing

* fix lint issue

* fix lint issue

* fix typo
  • Loading branch information
kzdev420 authored Feb 6, 2025
1 parent 65f5d0b commit 93be1ec
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright © 2025 Province of British Columbia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""File processing rules and actions for the Notice of Withdrawal filing."""
import datetime
from typing import Dict

from legal_api.models import Filing

from entity_filer.filing_meta import FilingMeta
from entity_filer.filing_processors.filing_components import filings


def process(
filing_submission: Filing,
filing: Dict,
filing_meta: FilingMeta
): # pylint: disable=W0613, R0914
"""Render the notice_of_withdrawal onto the model objects."""
now_filing = filing.get('noticeOfWithdrawal')

if court_order := now_filing.get('courtOrder'):
filings.update_filing_court_order(filing_submission, court_order)
filing_meta.notice_of_withdrawal = {**filing_meta.notice_of_withdrawal,
'withdrawnDate': datetime.datetime.utcnow()}

withdrawn_filing_id = now_filing.get('filingId')
withdrawn_filing = Filing.find_by_id(withdrawn_filing_id)

withdrawn_filing._status = Filing.Status.WITHDRAWN.value # pylint: disable=protected-access
withdrawn_filing.withdrawal_pending = False
withdrawn_filing.save_to_session()
10 changes: 9 additions & 1 deletion queue_services/entity-filer/src/entity_filer/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
court_order,
dissolution,
incorporation_filing,
notice_of_withdrawal,
put_back_off,
put_back_on,
registrars_notation,
Expand Down Expand Up @@ -217,10 +218,14 @@ async def process_filing(filing_msg: Dict, # pylint: disable=too-many-branches,

filing_submission = filing_core_submission.storage

if filing_core_submission.status == Filing.Status.COMPLETED:
if filing_core_submission.status in [Filing.Status.COMPLETED, Filing.Status.WITHDRAWN]:
logger.warning('QueueFiler: Attempting to reprocess business.id=%s, filing.id=%s filing=%s',
filing_submission.business_id, filing_submission.id, filing_msg)
return None, None
if filing_submission.withdrawal_pending:
logger.warning('QueueFiler: NoW pending for this filing business.id=%s, filing.id=%s filing=%s',
filing_submission.business_id, filing_submission.id, filing_msg)
raise QueueException

# convenience flag to set that the envelope is a correction
is_correction = filing_core_submission.filing_type == FilingCore.FilingTypes.CORRECTION
Expand Down Expand Up @@ -322,6 +327,9 @@ async def process_filing(filing_msg: Dict, # pylint: disable=too-many-branches,
elif filing.get('agmExtension'):
agm_extension.process(filing, filing_meta)

elif filing.get('noticeOfWithdrawal'):
notice_of_withdrawal.process(filing_submission, filing, filing_meta)

elif filing.get('amalgamationApplication'):
business, filing_submission, filing_meta = amalgamation_application.process(
business,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Copyright © 2025 Province of British Columbia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""The Unit Tests for the Notice Of Withdrawal filing."""
import copy
import random
import pytest

from legal_api.models import Business, Filing
from registry_schemas.example_data import FILING_HEADER, INCORPORATION, NOTICE_OF_WITHDRAWAL

from entity_filer.filing_meta import FilingMeta
from entity_filer.filing_processors import notice_of_withdrawal
from tests.unit import create_business, create_filing


@pytest.mark.parametrize('test_name, withdrawal_pending,withdrawn_filing_status', [
('Process the Filing', False, False),
('Dont process the Filing', False, True),
('Dont process the Filing', True, False),
('Dont process the Filing', True, True),
])
def test_worker_notice_of_withdrawal(session, test_name, withdrawal_pending, withdrawn_filing_status):
"""Assert that the notice of withdrawal filing processes correctly."""
# Setup
identifier = 'BC1234567'
business = create_business(identifier, legal_type='BC')
payment_id = str(random.SystemRandom().getrandbits(0x58))

# Create IA filing
ia_filing_json = copy.deepcopy(FILING_HEADER)
ia_filing_json['filing']['business']['identifier'] = identifier
ia_filing_json['filing']['incorporationApplication'] = copy.deepcopy(INCORPORATION)
ia_filing = create_filing(payment_id, ia_filing_json, business_id=business.id)
ia_filing.withdrawal_pending = withdrawal_pending
if withdrawn_filing_status:
ia_filing._status = Filing.Status.WITHDRAWN.value
else:
ia_filing._status = 'PENDING'
ia_filing.skip_status_listener = True
ia_filing.save()

now_filing_json = copy.deepcopy(FILING_HEADER)
now_filing_json['filing']['business']['identifier'] = identifier
now_filing_json['filing']['noticeOfWithdrawal'] = copy.deepcopy(NOTICE_OF_WITHDRAWAL)
now_filing_json['filing']['noticeOfWithdrawal']['filingId'] = ia_filing.id
now_filing = create_filing(payment_id, now_filing_json, business_id=business.id)
now_filing.withdrawn_filing_id = ia_filing.id
now_filing.save()

filing_meta = FilingMeta()
filing_meta.notice_of_withdrawal = {}

# Test
notice_of_withdrawal.process(now_filing, now_filing_json['filing'], filing_meta)
business.save()

# Check results
final_ia_filing = Filing.find_by_id(ia_filing.id)
final_now_filing = Filing.find_by_id(now_filing.id)

assert now_filing_json['filing']['noticeOfWithdrawal']['courtOrder']['orderDetails'] == final_now_filing.order_details
if withdrawal_pending or withdrawn_filing_status:
assert final_ia_filing.status == ia_filing.status
assert final_ia_filing.withdrawal_pending == ia_filing.withdrawal_pending
else:
assert final_ia_filing.status == Filing.Status.WITHDRAWN.value
assert final_ia_filing.withdrawal_pending == False

0 comments on commit 93be1ec

Please sign in to comment.