Skip to content

Commit

Permalink
22205 Legal API - Add additional columns to furnishings table (bcgov#…
Browse files Browse the repository at this point in the history
…2824)

* 22205

Signed-off-by: Hongjing Chen <[email protected]>

* rebase to  resolve conflicts & add missing parameters

Signed-off-by: Hongjing Chen <[email protected]>

---------

Signed-off-by: Hongjing Chen <[email protected]>
  • Loading branch information
chenhongjing authored Jul 15, 2024
1 parent ed4136a commit aef9edd
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 11 deletions.
23 changes: 16 additions & 7 deletions jobs/furnishings/src/furnishings/stage_processors/stage_one.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ async def process(self, batch_processing: BatchProcessing):
business_id=batch_processing.business_id
)
if not furnishings:
# send first notification if no furnishing entry exists
await self._send_first_round_notification(batch_processing)
await self._send_first_round_notification(batch_processing, batch_processing.business)
else:
# send paper letter if business is still not in good standing after 5 days of email letter sent out
valid_furnishing_names = [
Expand All @@ -72,7 +71,7 @@ async def process(self, batch_processing: BatchProcessing):
if has_elapsed_email_entry and not has_mail_entry:
await self._send_second_round_notification(batch_processing)

async def _send_first_round_notification(self, batch_processing: BatchProcessing):
async def _send_first_round_notification(self, batch_processing: BatchProcessing, business: Business):
"""Process first round of notification(email/letter)."""
_, eligible_details = InvoluntaryDissolutionService.check_business_eligibility(
batch_processing.business_identifier,
Expand All @@ -91,16 +90,20 @@ async def _send_first_round_notification(self, batch_processing: BatchProcessing
batch_processing,
eligible_details,
Furnishing.FurnishingType.EMAIL,
business.last_ar_date if business.last_ar_date else business.founding_date,
business.legal_name,
email
)
)
# notify emailer
await self._send_email(new_furnishing)
else:
# send paper letter if business doesn't have email address
new_furnishing = self._create_new_furnishing(
batch_processing,
eligible_details,
Furnishing.FurnishingType.MAIL
Furnishing.FurnishingType.MAIL,
business.last_ar_date if business.last_ar_date else business.founding_date,
business.legal_name
)

mailing_address = business.mailing_address.one_or_none()
Expand All @@ -126,7 +129,9 @@ async def _send_second_round_notification(self, batch_processing: BatchProcessin
new_furnishing = self._create_new_furnishing(
batch_processing,
eligible_details,
Furnishing.FurnishingType.MAIL
Furnishing.FurnishingType.MAIL,
business.last_ar_date if business.last_ar_date else business.founding_date,
business.legal_name
)

mailing_address = business.mailing_address.one_or_none()
Expand All @@ -138,11 +143,13 @@ async def _send_second_round_notification(self, batch_processing: BatchProcessin
new_furnishing.status = Furnishing.FurnishingStatus.PROCESSED
new_furnishing.processed_date = datetime.utcnow()

def _create_new_furnishing(
def _create_new_furnishing( # pylint: disable=too-many-arguments
self,
batch_processing: BatchProcessing,
eligible_details: InvoluntaryDissolutionService.EligibilityDetails,
furnishing_type: Furnishing.FurnishingType,
last_ar_date: datetime,
business_name: str,
email: str = None
) -> Furnishing:
"""Create new furnishing entry."""
Expand Down Expand Up @@ -172,6 +179,8 @@ def _create_new_furnishing(
last_modified=datetime.utcnow(),
status=Furnishing.FurnishingStatus.QUEUED,
grouping_identifier=grouping_identifier,
last_ar_date=last_ar_date,
business_name=business_name,
email=email
)
new_furnishing.save()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def process(app: Flask):
created_date=datetime.utcnow(),
last_modified=datetime.utcnow(),
status=Furnishing.FurnishingStatus.QUEUED,
grouping_identifier=grouping_identifier
grouping_identifier=grouping_identifier,
business_name=business.legal_name
)
new_furnishing.save()
# TODO: create data files and SFTPing to BC Laws
Expand Down
6 changes: 5 additions & 1 deletion jobs/furnishings/tests/unit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ def factory_furnishing(batch_id,
furnishing_type=Furnishing.FurnishingType.EMAIL,
status=Furnishing.FurnishingStatus.QUEUED,
created_date=datetime.datetime.utcnow(),
last_modified=datetime.datetime.utcnow()
last_modified=datetime.datetime.utcnow(),
last_ar_date=None,
business_name=None
):
"""Create a furnishing entry."""
furnishing = Furnishing(
Expand All @@ -148,6 +150,8 @@ def factory_furnishing(batch_id,
status=status,
created_date=created_date,
last_modified=last_modified,
last_ar_date=last_ar_date,
business_name=business_name
)
furnishing.save()
return furnishing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ async def test_process_first_notification(app, session, test_name, entity_type,
assert furnishing.furnishing_name == expected_furnishing_name
assert furnishing.status == Furnishing.FurnishingStatus.QUEUED
assert furnishing.grouping_identifier is not None
assert furnishing.last_ar_date == business.founding_date
assert furnishing.business_name == business.legal_name
else:
mock_send_email.assert_not_called()
furnishings = Furnishing.find_by(business_id=business.id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ def test_process_create_furnishings(app, session, test_name, entity_type, step,
furnishing_name=Furnishing.FurnishingName.INTENT_TO_DISSOLVE,
furnishing_type=Furnishing.FurnishingType.GAZETTE,
created_date=datetime.utcnow()+datedelta(years=1),
last_modified=datetime.utcnow()+datedelta(years=1)
last_modified=datetime.utcnow()+datedelta(years=1),
business_name=business.legal_name
)

process(app)
Expand All @@ -84,6 +85,7 @@ def test_process_create_furnishings(app, session, test_name, entity_type, step,
assert len(furnishings) == 1
furnishing = furnishings[0]
assert furnishing.furnishing_type == Furnishing.FurnishingType.GAZETTE
assert furnishing.business_name == business.legal_name
if entity_type == Business.LegalTypes.EXTRA_PRO_A.value:
assert furnishing.furnishing_name == Furnishing.FurnishingName.INTENT_TO_DISSOLVE_XPRO
else:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""add_columns_to_furnishings
Revision ID: feb206b2ce65
Revises: ac0065d92893
Create Date: 2024-07-10 17:33:24.126671
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'feb206b2ce65'
down_revision = 'ac0065d92893'
branch_labels = None
depends_on = None


def upgrade():
op.add_column('furnishings', sa.Column('last_ar_date', sa.DateTime(timezone=True), autoincrement=False, nullable=True))
op.add_column('furnishings', sa.Column('business_name', sa.String(length=1000), autoincrement=False, nullable=True))


def downgrade():
op.drop_column('furnishings', 'last_ar_date')
op.drop_column('furnishings', 'business_name')
2 changes: 2 additions & 0 deletions legal-api/src/legal_api/models/furnishing.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class FurnishingStatus(BaseEnum):
last_name = db.Column('last_name', db.String(30), default='', nullable=True)
first_name = db.Column('first_name', db.String(30), default='', nullable=True)
middle_name = db.Column('middle_name', db.String(30), default='', nullable=True)
last_ar_date = db.Column('last_ar_date', db.DateTime(timezone=True), nullable=True)
business_name = db.Column('business_name', db.String(1000), nullable=True)

# parent keys
batch_id = db.Column('batch_id', db.Integer, db.ForeignKey('batches.id'), index=True, nullable=False)
Expand Down
4 changes: 3 additions & 1 deletion legal-api/tests/unit/models/test_furnishing.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ def test_valid_furnishing_save(session):
batch_id = batch.id,
business_id = business.id,
business_identifier = business.identifier,
status = Furnishing.FurnishingStatus.QUEUED
status = Furnishing.FurnishingStatus.QUEUED,
last_ar_date=business.last_ar_date,
business_name=business.legal_name
)

furnishing.save()
Expand Down

0 comments on commit aef9edd

Please sign in to comment.