Skip to content

Commit

Permalink
Merge pull request #542 from awf-dbca/constrain-renewal-notices
Browse files Browse the repository at this point in the history
max number of renewal notices per application
  • Loading branch information
xzzy authored Feb 19, 2025
2 parents 327bbc5 + 44e5a21 commit 9b64b3e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
15 changes: 9 additions & 6 deletions mooringlicensing/management/commands/approval_renewal_notices.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
CODE_DAYS_FOR_RENEWAL_AUP,
CODE_DAYS_FOR_RENEWAL_ML,
CODE_DAYS_FOR_RENEWAL_DCVP,
MAX_RENEWAL_NOTICES_PER_RUN,
)

logger = logging.getLogger('cron_tasks')
Expand All @@ -32,7 +33,7 @@
class Command(BaseCommand):
help = 'Send Approval renewal notice when approval is due to expire in X days'

def perform_per_type(self, number_of_days_code, approval_class, updates, errors):
def perform_per_type(self, number_of_days_code, approval_class, updates, errors, max_renewal_notices):
today = timezone.localtime(timezone.now()).date()

# Retrieve the number of days before expiry date of the approvals to email
Expand All @@ -59,7 +60,7 @@ def perform_per_type(self, number_of_days_code, approval_class, updates, errors)
queries &= Q(renewal_sent=False)
queries &= Q(status__in=[Approval.APPROVAL_STATUS_CURRENT, Approval.APPROVAL_STATUS_SUSPENDED,])

approvals = approval_class.objects.filter(queries)
approvals = approval_class.objects.filter(queries).order_by('issue_date')[:max_renewal_notices]
for a in approvals:
try:
if not approval_class == DcvPermit:
Expand Down Expand Up @@ -89,10 +90,12 @@ def perform_per_type(self, number_of_days_code, approval_class, updates, errors)
def handle(self, *args, **options):
updates, errors = [], []

self.perform_per_type(CODE_DAYS_FOR_RENEWAL_WLA, WaitingListAllocation, updates, errors)
self.perform_per_type(CODE_DAYS_FOR_RENEWAL_AAP, AnnualAdmissionPermit, updates, errors)
self.perform_per_type(CODE_DAYS_FOR_RENEWAL_AUP, AuthorisedUserPermit, updates, errors)
self.perform_per_type(CODE_DAYS_FOR_RENEWAL_ML, MooringLicence, updates, errors)
max_renewal_notices = int(MAX_RENEWAL_NOTICES_PER_RUN)

self.perform_per_type(CODE_DAYS_FOR_RENEWAL_WLA, WaitingListAllocation, updates, errors, max_renewal_notices)
self.perform_per_type(CODE_DAYS_FOR_RENEWAL_AAP, AnnualAdmissionPermit, updates, errors, max_renewal_notices)
self.perform_per_type(CODE_DAYS_FOR_RENEWAL_AUP, AuthorisedUserPermit, updates, errors, max_renewal_notices)
self.perform_per_type(CODE_DAYS_FOR_RENEWAL_ML, MooringLicence, updates, errors, max_renewal_notices)

cmd_name = __name__.split('.')[-1].replace('_', ' ').upper()
msg = construct_email_message(cmd_name, errors, updates)
Expand Down
1 change: 1 addition & 0 deletions mooringlicensing/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
SHOW_TESTS_URL = env('SHOW_TESTS_URL', False)
SHOW_DEBUG_TOOLBAR = env('SHOW_DEBUG_TOOLBAR', False)
SHOW_API_ROOT = env('SHOW_API_ROOT', False)
MAX_RENEWAL_NOTICES_PER_RUN = env('MAX_RENEWAL_NOTICES_PER_RUN', 5)

#Settings for rounding application fee items
ROUND_FEE_ITEMS = env('ROUND_FEE_ITEMS', False)
Expand Down
1 change: 1 addition & 0 deletions python-cron
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
10 * * * * python manage_ml.py import_mooring_bookings_data >> logs/run_import_mooring_bookings_data_cron_task.log 2>&1
*/10 * * * * python manage_ml.py export_to_mooring_booking_cron_task >> logs/run_export_to_mooring_booking_cron_task.log 2>&1
*/5 * * * * python manage_ml.py runcrons >> logs/runcrons.log 2>&1
*/4 * * * * python manage_ml.py approval_renewal_notices >> logs/run_approval_renewal_notices_cron_task.log 2>&1
30 3 * * 4 python manage_ml.py clearsessions >> logs/clearsessions.log 2>&1
30 * * * * python manage_ml.py auto_lock_system_account >> logs/auto_lock_system_account.log 2>&1

0 comments on commit 9b64b3e

Please sign in to comment.