Skip to content

Commit

Permalink
Merge pull request #471 from NishantPhour/main
Browse files Browse the repository at this point in the history
Latest work
  • Loading branch information
xzzy authored Oct 11, 2024
2 parents 9d0f10d + c9fd3ce commit bc271bd
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 25 deletions.
3 changes: 2 additions & 1 deletion mooringlicensing/components/approvals/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ def send_approval_suspend_email_notification(approval, request=None):
_log_user_email(msg, approval.applicant_obj, proposal.applicant_obj, sender=sender_user)


def send_approval_surrender_email_notification(approval, request=None, already_surrendered=True):
def send_approval_surrender_email_notification(approval, request=None, already_surrendered=True, stickers_to_be_returned=[]):
# 30 Surrendered
# email to licence/permit holder when licence/permit is surrendered
if already_surrendered:
Expand Down Expand Up @@ -554,6 +554,7 @@ def send_approval_surrender_email_notification(approval, request=None, already_s
'recipient': approval.applicant_obj,
'details': details,
'surrender_date': surrender_date,
'stickers_to_be_returned': stickers_to_be_returned,
}
sender = settings.DEFAULT_FROM_EMAIL
try:
Expand Down
38 changes: 35 additions & 3 deletions mooringlicensing/components/approvals/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1011,15 +1011,17 @@ def approval_surrender(self,request,details):
today = timezone.now().date()
surrender_date = datetime.datetime.strptime(self.surrender_details['surrender_date'],'%d/%m/%Y')
surrender_date = surrender_date.date()
# Process stickers before sending the surrender email
stickers_to_be_returned = self._process_stickers()
if surrender_date <= today:
if not self.status == Approval.APPROVAL_STATUS_SURRENDERED:
self.status = Approval.APPROVAL_STATUS_SURRENDERED
self.set_to_surrender = False
self.save()
send_approval_surrender_email_notification(self)
send_approval_surrender_email_notification(self, stickers_to_be_returned=stickers_to_be_returned)
else:
self.set_to_surrender = True
send_approval_surrender_email_notification(self, already_surrendered=False)
send_approval_surrender_email_notification(self, already_surrendered=False, stickers_to_be_returned=stickers_to_be_returned)
self.save()
if type(self.child_obj) == WaitingListAllocation:
self.child_obj.processes_after_surrender()
Expand All @@ -1029,7 +1031,37 @@ def approval_surrender(self,request,details):
self.current_proposal.log_user_action(ProposalUserAction.ACTION_SURRENDER_APPROVAL.format(self.current_proposal.id),request)
except:
raise


def _process_stickers(self):
"""
Helper function to handle sticker status updates and return the list of stickers to be returned.
"""
stickers_to_be_returned = []
stickers_updated = []
# Handle stickers with status CURRENT and AWAITING_PRINTING
for a_sticker in Sticker.objects.filter(approval = self, status__in=[Sticker.STICKER_STATUS_CURRENT, Sticker.STICKER_STATUS_AWAITING_PRINTING]):
a_sticker.status = Sticker.STICKER_STATUS_TO_BE_RETURNED
a_sticker.save()
stickers_to_be_returned.append(a_sticker)
stickers_updated.append(a_sticker)
logger.info(f'Status of the sticker: {a_sticker} has been changed to {Sticker.STICKER_STATUS_TO_BE_RETURNED}')

# Handle stickers with status READY and NOT_READY_YET
for a_sticker in Sticker.objects.filter(approval = self, status__in=[Sticker.STICKER_STATUS_READY, Sticker.STICKER_STATUS_NOT_READY_YET]):
a_sticker.status = Sticker.STICKER_STATUS_CANCELLED
a_sticker.save()
stickers_updated.append(a_sticker)
logger.info(f'Status of the sticker: {a_sticker} has been changed to {Sticker.STICKER_STATUS_CANCELLED}')

# Update MooringOnApproval records
moas = MooringOnApproval.objects.filter(sticker__in=stickers_updated)
for moa in moas:
moa.sticker = None
moa.save()
logger.info(f'Sticker: None is set to the MooringOnApproval: {moa}')

return stickers_to_be_returned

# required to clean db of approvals with no child objs
@property
def no_child_obj(self):
Expand Down
8 changes: 4 additions & 4 deletions mooringlicensing/components/emails/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def make_url_for_internal(url):
else:
url = url.replace('.dbca.wa.gov.au', '-internal.dbca.wa.gov.au')

url = url.replace('-internal.dbca', '-internal-oim01.dbca')
# url = url.replace('-internal.dbca', '-internal-oim01.dbca')

url = make_http_https(url)
return url
Expand All @@ -29,8 +29,8 @@ def make_url_for_external(url):
# Public URL should not have 'internal' substring
if '-dev-internal' in url:
url = url.replace('-dev-internal', '-dev')
elif '-uat-internal-oim01' in url:
url = url.replace('-uat-internal-oim01', '-uat')
# elif '-uat-internal-oim01' in url:
# url = url.replace('-uat-internal-oim01', '-uat')
elif '-uat-internal' in url:
url = url.replace('-uat-internal', '-uat')
else:
Expand All @@ -39,7 +39,7 @@ def make_url_for_external(url):
# For seg-dev environment
if '-ria-seg-dev' in url:
url = url.replace('-ria-seg-dev', '-seg-dev')
url = url.replace('-oim01', '')
# url = url.replace('-oim01', '')

web_url = make_http_https(url)

Expand Down
5 changes: 4 additions & 1 deletion mooringlicensing/doctopdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def create_dcv_permit_pdf_tytes(dcv_permit):
# context = context_obj.data
# doc.render(context)
context = dcv_permit.get_context_for_licence_permit()
if context['p_address_line2'] is None:
context['p_address_line2'] = ''
doc.render(context)

temp_directory = settings.BASE_DIR + "/tmp/"
Expand Down Expand Up @@ -151,7 +153,8 @@ def create_approval_doc_bytes(approval):
doc = DocxTemplate(path_to_template)

context = approval.child_obj.get_context_for_licence_permit() if type(approval) == Approval else approval.get_context_for_licence_permit()

if context['p_address_line2'] is None:
context['p_address_line2'] = ''
doc.render(context)

temp_directory = settings.BASE_DIR + "/tmp/"
Expand Down
29 changes: 15 additions & 14 deletions mooringlicensing/management/commands/update_approval_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ def handle(self, *args, **options):
send_approval_suspend_email_notification(a)

proposal = a.current_proposal
ApprovalUserAction.log_action(a, ApprovalUserAction.ACTION_SUSPEND_APPROVAL.format(a.id), user)
ProposalUserAction.log_action(proposal, ProposalUserAction.ACTION_SUSPEND_APPROVAL.format(proposal.lodgement_number), user)
ApprovalUserAction.log_action(a, ApprovalUserAction.ACTION_SUSPEND_APPROVAL.format(a.id), None)
ProposalUserAction.log_action(proposal, ProposalUserAction.ACTION_SUSPEND_APPROVAL.format(proposal.lodgement_number), None)
logger.info('Updated Approval {} status to {}'.format(a.id, a.status))
updates.append(dict(suspended=a.lodgement_number))
except Exception as e:
Expand All @@ -85,8 +85,8 @@ def handle(self, *args, **options):
send_approval_cancel_email_notification(a)

proposal = a.current_proposal
ApprovalUserAction.log_action(a, ApprovalUserAction.ACTION_CANCEL_APPROVAL.format(a.id), user)
ProposalUserAction.log_action(proposal, ProposalUserAction.ACTION_CANCEL_APPROVAL.format(proposal.lodgement_number), user)
ApprovalUserAction.log_action(a, ApprovalUserAction.ACTION_CANCEL_APPROVAL.format(a.id), None)
ProposalUserAction.log_action(proposal, ProposalUserAction.ACTION_CANCEL_APPROVAL.format(proposal.lodgement_number), None)
logger.info('Updated Approval {} status to {}'.format(a.id, a.status))
updates.append(dict(cancelled=a.lodgement_number))
except Exception as e:
Expand All @@ -96,17 +96,18 @@ def handle(self, *args, **options):

if a.surrender_details and a.set_to_surrender:
surrender_date = datetime.datetime.strptime(a.surrender_details['surrender_date'], '%d/%m/%Y')
surrender_date = surrender_date.date()
surrender_date = surrender_date.date()
stickers_to_be_returned = a._process_stickers()
if surrender_date <= today:
try:
a.status = Approval.APPROVAL_STATUS_SURRENDERED
a.set_to_surrender = False
a.save()
send_approval_surrender_email_notification(a)
send_approval_surrender_email_notification(a, stickers_to_be_returned=stickers_to_be_returned)

proposal = a.current_proposal
ApprovalUserAction.log_action(a, ApprovalUserAction.ACTION_SURRENDER_APPROVAL.format(a.id), user)
ProposalUserAction.log_action(proposal, ProposalUserAction.ACTION_SURRENDER_APPROVAL.format(proposal.lodgement_number), user)
ApprovalUserAction.log_action(a, ApprovalUserAction.ACTION_SURRENDER_APPROVAL.format(a.id), None)
ProposalUserAction.log_action(proposal, ProposalUserAction.ACTION_SURRENDER_APPROVAL.format(proposal.lodgement_number), None)
logger.info('Updated Approval {} status to {}'.format(a.id, a.status))
updates.append(dict(surrendered=a.lodgement_number))
except Exception as e:
Expand All @@ -125,8 +126,8 @@ def handle(self, *args, **options):
a.save()

proposal = a.current_proposal
ApprovalUserAction.log_action(a, ApprovalUserAction.ACTION_REINSTATE_APPROVAL.format(a.id), user)
ProposalUserAction.log_action(proposal, ProposalUserAction.ACTION_REINSTATE_APPROVAL.format(proposal.lodgement_number), user)
ApprovalUserAction.log_action(a, ApprovalUserAction.ACTION_REINSTATE_APPROVAL.format(a.id), None)
ProposalUserAction.log_action(proposal, ProposalUserAction.ACTION_REINSTATE_APPROVAL.format(proposal.lodgement_number), None)
logger.info('Updated Approval {} status to {}'.format(a.id, a.status))
updates.append(dict(current=a.lodgement_number))
except Exception as e:
Expand All @@ -147,8 +148,8 @@ def handle(self, *args, **options):
send_approval_cancel_email_notification(a)

proposal = a.current_proposal
ApprovalUserAction.log_action(a, ApprovalUserAction.ACTION_CANCEL_APPROVAL.format(a.id), user)
ProposalUserAction.log_action(proposal, ProposalUserAction.ACTION_CANCEL_APPROVAL.format(proposal.lodgement_number), user)
ApprovalUserAction.log_action(a, ApprovalUserAction.ACTION_CANCEL_APPROVAL.format(a.id), None)
ProposalUserAction.log_action(proposal, ProposalUserAction.ACTION_CANCEL_APPROVAL.format(proposal.lodgement_number), None)
logger.info('Updated Approval {} status to {}'.format(a.id,a.status))
updates.append(dict(cancelled=a.lodgement_number))
except Exception as e:
Expand All @@ -167,8 +168,8 @@ def handle(self, *args, **options):

send_approval_surrender_email_notification(a)
proposal = a.current_proposal
ApprovalUserAction.log_action(a, ApprovalUserAction.ACTION_SURRENDER_APPROVAL.format(a.id), user)
ProposalUserAction.log_action(proposal, ProposalUserAction.ACTION_SURRENDER_APPROVAL.format(proposal.lodgement_number), user)
ApprovalUserAction.log_action(a, ApprovalUserAction.ACTION_SURRENDER_APPROVAL.format(a.id), None)
ProposalUserAction.log_action(proposal, ProposalUserAction.ACTION_SURRENDER_APPROVAL.format(proposal.lodgement_number), None)
logger.info('Updated Approval {} status to {}'.format(a.id, a.status))
updates.append(dict(surrendered=a.lodgement_number))
except Exception as e:
Expand Down
14 changes: 14 additions & 0 deletions mooringlicensing/migrations/0363_merge_20241010_1649.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Generated by Django 5.0.9 on 2024-10-10 08:49

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('mooringlicensing', '0362_remove_approval_expiry_notice_count_and_more'),
('mooringlicensing', '0362_remove_organisationaction_organisation_and_more'),
]

operations = [
]
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@


<p>Thank you for notifying us of the surrender of your {{ approval.description }} {{ approval.lodgement_number }} as of {{ surrender_date }}.</p>
<!-- {% if stickers_to_be_returned|length > 0 %}
{% if stickers_to_be_returned|length > 0 %}
<p>If you have not already done so, per your permit(s) conditions, you are required to return all associated vessel sticker(s)
{% for sticker in stickers_to_be_returned %}
{{ sticker.number }}{% if forloop.last %}{% else %},{% endif %}
{% endfor %}
to the Rottnest Island Authority. Failure to return stickers to RIA upon request can result in the cancellation of your {{ approval.description }}. Once revoked, it cannot be reinstated.</p>
{% endif %} -->
{% endif %}
{% if details %}<p>Details: {{ details }}</p>{% endif %}
{% include "mooringlicensing/emails/signature-rottnest.html" %}
{% endblock %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
{% block content_body %}
{% include "mooringlicensing/emails_2/salutation.txt" %}
Your {{ approval.description }} {{ approval.lodgement_number }} has been surrendered as per {{ surrender_date }}.
{% if stickers_to_be_returned|length > 0 %}
If you have not already done so, per your permit(s) conditions, you are required to return all associated vessel sticker(s)
{% for sticker in stickers_to_be_returned %}
{{ sticker.number }}{% if forloop.last %}{% else %},{% endif %}
{% endfor %}
to the Rottnest Island Authority. Failure to return stickers to RIA upon request can result in the cancellation of your {{ approval.description }}. Once revoked, it cannot be reinstated.
{% endif %}
{% if details %}Details: {{ details }}{% endif %}
{% include "mooringlicensing/emails/signature-rottnest.txt" %}
{% endblock %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
{% block content_body %}
{% include "mooringlicensing/emails_2/salutation.html" %}
<p>Your {{ approval.description }} {{ approval.lodgement_number }} will be surrendered as per {{ surrender_date }}.</p>
{% if stickers_to_be_returned|length > 0 %}
<p>If you have not already done so, per your permit(s) conditions, you are required to return all associated vessel sticker(s)
{% for sticker in stickers_to_be_returned %}
{{ sticker.number }}{% if forloop.last %}{% else %},{% endif %}
{% endfor %}
to the Rottnest Island Authority. Failure to return stickers to RIA upon request can result in the cancellation of your {{ approval.description }}. Once revoked, it cannot be reinstated.</p>
{% endif %}
{% if details %}<p>Details: {{ details }}</p>{% endif %}
{% include "mooringlicensing/emails/signature-rottnest.html" %}
{% endblock %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
{% block content_body %}
{% include "mooringlicensing/emails_2/salutation.txt" %}
Your {{ approval.description }} {{ approval.lodgement_number }} will be surrendered as per {{ surrender_date }}.
{% if stickers_to_be_returned|length > 0 %}
If you have not already done so, per your permit(s) conditions, you are required to return all associated vessel sticker(s)
{% for sticker in stickers_to_be_returned %}
{{ sticker.number }}{% if forloop.last %}{% else %},{% endif %}
{% endfor %}
to the Rottnest Island Authority. Failure to return stickers to RIA upon request can result in the cancellation of your {{ approval.description }}. Once revoked, it cannot be reinstated.
{% endif %}
{% if details %}Details: {{ details }}{% endif %}
{% include "mooringlicensing/emails/signature-rottnest.txt" %}
{% endblock %}
Expand Down

0 comments on commit bc271bd

Please sign in to comment.