Skip to content

Commit

Permalink
24741 cease custodian while filing putbackon (#3118)
Browse files Browse the repository at this point in the history
  • Loading branch information
vysakh-menon-aot authored Dec 10, 2024
1 parent ecda4a5 commit ccb986f
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 17 deletions.
15 changes: 10 additions & 5 deletions legal-api/src/legal_api/reports/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,16 @@ def _set_tax_id(self, filing):
filing['taxId'] = self._business.tax_id

def _set_description(self, filing):
legal_type = (self._filing.filing_json
.get('filing')
.get(self._filing.filing_type)
.get('nameRequest', {})
.get('legalType'))
legal_type = None
if self._filing.filing_type == 'alteration':
legal_type = self._filing.filing_json.get('filing').get('alteration').get('business', {}).get('legalType')
else:
legal_type = (self._filing.filing_json
.get('filing')
.get(self._filing.filing_type)
.get('nameRequest', {})
.get('legalType'))

if not legal_type and self._business:
legal_type = self._business.legal_type

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@

import dpath
from entity_queue_common.service_utils import QueueException, logger
from legal_api.models import Business, Filing
from legal_api.models import Business, Filing, Office, OfficeType, db

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


def process(business: Business, filing: Dict, filing_rec: Filing, filing_meta: FilingMeta):
def process(business: Business, filing: Dict, filing_rec: Filing, filing_meta: FilingMeta):
"""Render the put back on filing unto the model objects."""
if not (put_back_on_filing := filing.get('putBackOn')):
logger.error('Could not find putBackOn in: %s', filing)
Expand All @@ -39,6 +40,15 @@ def process(business: Business, filing: Dict, filing_rec: Filing, filing_meta:

filing_rec.order_details = put_back_on_filing.get('details')

restoration.cease_custodian(business)

custodial_office = (db.session.query(Office).
filter(Office.business_id == business.id).
filter(Office.office_type == OfficeType.CUSTODIAL).
one_or_none())
if custodial_office:
business.offices.remove(custodial_office)

business.state = Business.State.ACTIVE
business.dissolution_date = None
business.state_filing_id = filing_rec.id
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@ def process(business: Business, filing: Dict, filing_rec: Filing, filing_meta: F

update_offices(business, restoration_filing['offices'])

parties = restoration_filing['parties']
_update_parties(business, parties, filing_rec)
cease_custodian(business)
update_parties(business,
restoration_filing['parties'],
filing_rec,
False)

filing_rec.approval_type = restoration_filing.get('approvalType')
if filing_rec.approval_type == 'courtOrder':
Expand All @@ -86,13 +89,12 @@ def process(business: Business, filing: Dict, filing_rec: Filing, filing_meta: F
filing_rec.notice_date = LegislationDatetime.as_utc_timezone_from_legislation_date_str(notice_date)


def _update_parties(business: Business, parties: dict, filing_rec: Filing):
"""Create applicant party and cease custodian if exist."""
def cease_custodian(business: Business):
"""Cease custodian if exist."""
end_date_time = datetime.utcnow()
custodian_party_roles = PartyRole.get_party_roles(business.id, end_date_time.date(),
custodian_party_roles = PartyRole.get_party_roles(business.id,
end_date_time.date(),
PartyRole.RoleTypes.CUSTODIAN.value)
for party_role in custodian_party_roles:
party_role.cessation_date = end_date_time
business.party_roles.append(party_role)

update_parties(business, parties, filing_rec, False)
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,61 @@
"""The Unit Tests for the Registrars Notation filing."""
import copy
import random
from datetime import datetime, timezone

from legal_api.models import Business, Filing
from legal_api.models import Business, Filing, Office, OfficeType
from registry_schemas.example_data import PUT_BACK_ON, FILING_HEADER

from entity_filer.filing_meta import FilingMeta
from entity_filer.filing_processors import put_back_on
from entity_filer.worker import process_filing
from tests.unit import create_business, create_filing
from tests.unit import (
create_business,
create_filing,
create_office,
create_office_address,
create_party,
create_party_role,
)


def test_worker_put_back_on(app, session):
"""Assert that the put back on object is correctly populated to model objects."""
identifier = 'BC1234567'
business = create_business(identifier, legal_type='BC')

party1 = create_party({
'officer': {
'firstName': '',
'lastName': '',
'middleName': '',
'organizationName': 'Xyz some super super super super super super long business 12345678 name Inc.',
'partyType': 'organization'
},
'mailingAddress': {
'streetAddress': 'mailing_address - address line one',
'streetAddressAdditional': '',
'addressCity': 'mailing_address city',
'addressCountry': 'CA',
'postalCode': 'H0H0H0',
'addressRegion': 'BC'
},
'deliveryAddress': {
'streetAddress': 'delivery_address - address line one',
'streetAddressAdditional': '',
'addressCity': 'delivery_address city',
'addressCountry': 'CA',
'postalCode': 'H0H0H0',
'addressRegion': 'BC'
}
})

create_party_role(business, party1, ['custodian'], datetime.now(timezone.utc))
business.save()

office = create_office(business, 'custodialOffice')
create_office_address(business, office, 'delivery')
create_office_address(business, office, 'mailing')

filing_json = copy.deepcopy(FILING_HEADER)
filing_json['filing']['business']['identifier'] = identifier
filing_json['filing']['putBackOn'] = copy.deepcopy(PUT_BACK_ON)
Expand All @@ -52,3 +92,16 @@ def test_worker_put_back_on(app, session):
assert business.state_filing_id == final_filing.id
assert business.dissolution_date is None
assert filing_json['filing']['putBackOn']['details'] == final_filing.order_details

custodial_office = session.query(Business, Office). \
filter(Business.id == Office.business_id). \
filter(Business.id == business.id). \
filter(Office.office_type == OfficeType.CUSTODIAL). \
one_or_none()
assert not custodial_office

party_roles = business.party_roles.all()
assert len(party_roles) == 1
custodian = party_roles[0]
assert custodian.role == 'custodian'
assert custodian.cessation_date

0 comments on commit ccb986f

Please sign in to comment.