diff --git a/mooringlicensing/components/approvals/email.py b/mooringlicensing/components/approvals/email.py index 86f89d27..abed0564 100755 --- a/mooringlicensing/components/approvals/email.py +++ b/mooringlicensing/components/approvals/email.py @@ -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: @@ -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: diff --git a/mooringlicensing/components/approvals/models.py b/mooringlicensing/components/approvals/models.py index c2e37d87..dfc3c14b 100755 --- a/mooringlicensing/components/approvals/models.py +++ b/mooringlicensing/components/approvals/models.py @@ -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() @@ -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): diff --git a/mooringlicensing/components/emails/utils.py b/mooringlicensing/components/emails/utils.py index e861297b..7480b977 100644 --- a/mooringlicensing/components/emails/utils.py +++ b/mooringlicensing/components/emails/utils.py @@ -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 @@ -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: @@ -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) diff --git a/mooringlicensing/doctopdf.py b/mooringlicensing/doctopdf.py index 2a7f1fc5..02265064 100644 --- a/mooringlicensing/doctopdf.py +++ b/mooringlicensing/doctopdf.py @@ -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/" @@ -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/" diff --git a/mooringlicensing/management/commands/update_approval_status.py b/mooringlicensing/management/commands/update_approval_status.py index 57c3dd19..7133dd78 100755 --- a/mooringlicensing/management/commands/update_approval_status.py +++ b/mooringlicensing/management/commands/update_approval_status.py @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: diff --git a/mooringlicensing/migrations/0363_merge_20241010_1649.py b/mooringlicensing/migrations/0363_merge_20241010_1649.py new file mode 100644 index 00000000..d79eff5b --- /dev/null +++ b/mooringlicensing/migrations/0363_merge_20241010_1649.py @@ -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 = [ + ] diff --git a/mooringlicensing/templates/mooringlicensing/emails_2/email_30.html b/mooringlicensing/templates/mooringlicensing/emails_2/email_30.html index 91dee729..37b6be67 100755 --- a/mooringlicensing/templates/mooringlicensing/emails_2/email_30.html +++ b/mooringlicensing/templates/mooringlicensing/emails_2/email_30.html @@ -5,13 +5,13 @@

Thank you for notifying us of the surrender of your {{ approval.description }} {{ approval.lodgement_number }} as of {{ surrender_date }}.

- +{% endif %} {% if details %}

Details: {{ details }}

{% endif %} {% include "mooringlicensing/emails/signature-rottnest.html" %} {% endblock %} diff --git a/mooringlicensing/templates/mooringlicensing/emails_2/email_30.txt b/mooringlicensing/templates/mooringlicensing/emails_2/email_30.txt index 8f1e7f16..0404028f 100755 --- a/mooringlicensing/templates/mooringlicensing/emails_2/email_30.txt +++ b/mooringlicensing/templates/mooringlicensing/emails_2/email_30.txt @@ -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 %} diff --git a/mooringlicensing/templates/mooringlicensing/emails_2/email_30_future.html b/mooringlicensing/templates/mooringlicensing/emails_2/email_30_future.html index 48fde5fa..6915c11e 100755 --- a/mooringlicensing/templates/mooringlicensing/emails_2/email_30_future.html +++ b/mooringlicensing/templates/mooringlicensing/emails_2/email_30_future.html @@ -3,6 +3,13 @@ {% block content_body %} {% include "mooringlicensing/emails_2/salutation.html" %}

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.html" %} {% endblock %} diff --git a/mooringlicensing/templates/mooringlicensing/emails_2/email_30_future.txt b/mooringlicensing/templates/mooringlicensing/emails_2/email_30_future.txt index 1c97d7d5..4e334736 100755 --- a/mooringlicensing/templates/mooringlicensing/emails_2/email_30_future.txt +++ b/mooringlicensing/templates/mooringlicensing/emails_2/email_30_future.txt @@ -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 %}