Skip to content

Commit

Permalink
Merge pull request #493 from awf-dbca/nod-setting-query
Browse files Browse the repository at this point in the history
Number of Day Type Settings Update
  • Loading branch information
xzzy authored Dec 5, 2024
2 parents 72d9fbb + 727d2d6 commit 4594bb6
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions mooringlicensing/components/proposals/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ def send_create_mooring_licence_application_email_notification(request, waiting_
url = MOORING_LICENSING_EXTERNAL_URL + reverse('external-proposal-detail', kwargs={'proposal_pk': mooring_licence_application.id})

today = datetime.now(pytz.timezone(settings.TIME_ZONE)).date()
days_type = NumberOfDaysType.objects.get(code=CODE_DAYS_IN_PERIOD_MLA)
days_type = NumberOfDaysType.objects.filter(code=CODE_DAYS_IN_PERIOD_MLA).first()
days_setting_application_period = NumberOfDaysSetting.get_setting_by_date(days_type, today)
days_type = NumberOfDaysType.objects.get(code=CODE_DAYS_FOR_SUBMIT_DOCUMENTS_MLA)
days_type = NumberOfDaysType.objects.filter(code=CODE_DAYS_FOR_SUBMIT_DOCUMENTS_MLA).first()
days_setting_documents_period = NumberOfDaysSetting.get_setting_by_date(days_type, today)
details = request.data.get('message_details', '')

Expand Down Expand Up @@ -271,7 +271,7 @@ def send_documents_upload_for_mooring_licence_application_email(request, proposa
)

today = datetime.now(pytz.timezone(settings.TIME_ZONE)).date()
days_type = NumberOfDaysType.objects.get(code=CODE_DAYS_FOR_SUBMIT_DOCUMENTS_MLA)
days_type = NumberOfDaysType.objects.filter(code=CODE_DAYS_FOR_SUBMIT_DOCUMENTS_MLA).first()
days_setting = NumberOfDaysSetting.get_setting_by_date(days_type, today)

url = request.build_absolute_uri(reverse('external-proposal-detail', kwargs={'proposal_pk': proposal.id}))
Expand Down
4 changes: 2 additions & 2 deletions mooringlicensing/components/proposals/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1765,7 +1765,7 @@ def final_approval_for_AUA_MLA(self, request=None):

invoice_name = self.proposal_applicant.get_full_name()
today = timezone.localtime(timezone.now()).date()
days_type = NumberOfDaysType.objects.get(code=settings.CODE_DAYS_BEFORE_DUE_PAYMENT)
days_type = NumberOfDaysType.objects.filter(code=settings.CODE_DAYS_BEFORE_DUE_PAYMENT).first()
days_setting = NumberOfDaysSetting.get_setting_by_date(days_type, today)
self.payment_due_date = today + datetime.timedelta(days=days_setting.number_of_days)
self.save()
Expand Down Expand Up @@ -3198,7 +3198,7 @@ def create_fee_lines(self):
return line_items, fee_items_to_store

def get_due_date_for_endorsement_by_target_date(self, target_date=timezone.localtime(timezone.now()).date()):
days_type = NumberOfDaysType.objects.get(code=CODE_DAYS_FOR_ENDORSER_AUA)
days_type = NumberOfDaysType.objects.filter(code=CODE_DAYS_FOR_ENDORSER_AUA).first()
days_setting = NumberOfDaysSetting.get_setting_by_date(days_type, target_date)
if not days_setting:
# No number of days found
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def perform_per_type(self, number_of_days_code, approval_class, updates, errors)
today = timezone.localtime(timezone.now()).date()

# Retrieve the number of days before expiry date of the approvals to email
days_type = NumberOfDaysType.objects.get(code=number_of_days_code)
days_type = NumberOfDaysType.objects.filter(code=number_of_days_code).first()
days_setting = NumberOfDaysSetting.get_setting_by_date(days_type, today)
if not days_setting:
err_msg = "NumberOfDays: {} is not defined for the date: {}".format(days_type.name, today)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def handle(self, *args, **options):
today = timezone.localtime(timezone.now()).date()

# Retrieve the number of days before expiry date of the proposals to email
days_type = NumberOfDaysType.objects.get(code=CODE_DAYS_BEFORE_DUE_PAYMENT)
days_type = NumberOfDaysType.objects.filter(code=CODE_DAYS_BEFORE_DUE_PAYMENT).first()
days_setting = NumberOfDaysSetting.get_setting_by_date(days_type, today)
if not days_setting:
# No number of days found
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def handle(self, *args, **options):
today = timezone.localtime(timezone.now()).date()

# Retrieve the number of days before expiry date of the approvals to email
days_type = NumberOfDaysType.objects.get(code=CODE_DAYS_FOR_SUBMIT_DOCUMENTS_MLA)
days_type = NumberOfDaysType.objects.filter(code=CODE_DAYS_FOR_SUBMIT_DOCUMENTS_MLA).first()
days_setting = NumberOfDaysSetting.get_setting_by_date(days_type, today)
if not days_setting:
# No number of days found
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def handle(self, *args, **options):
today = timezone.localtime(timezone.now()).date()

# Retrieve the number of days before expiry date of the approvals to email
days_type = NumberOfDaysType.objects.get(code=CODE_DAYS_IN_PERIOD_MLA)
days_type = NumberOfDaysType.objects.filter(code=CODE_DAYS_IN_PERIOD_MLA).first()
days_setting = NumberOfDaysSetting.get_setting_by_date(days_type, today)
if not days_setting:
# No number of days found
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def handle(self, *args, **options):
today = timezone.localtime(timezone.now()).date()

# Retrieve the number of days before expiry date of the proposals to email
days_type = NumberOfDaysType.objects.get(code=CODE_DAYS_FOR_DUE_PAYMENT_REMINDER)
days_type = NumberOfDaysType.objects.filter(code=CODE_DAYS_FOR_DUE_PAYMENT_REMINDER).first()
days_setting = NumberOfDaysSetting.get_setting_by_date(days_type, today)
if not days_setting:
# No number of days found
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ def handle(self, *args, **options):
errors = []
updates = []
logger.info('Running command {}'.format(__name__))
days_type_first_reminder = NumberOfDaysType.objects.get(code=CODE_DAYS_FOR_FIRST_REMINDER)
days_type_first_reminder = NumberOfDaysType.objects.filter(code=CODE_DAYS_FOR_FIRST_REMINDER).first()
days_setting_first_reminder = NumberOfDaysSetting.get_setting_by_date(days_type_first_reminder, today)
if not days_setting_first_reminder:
raise ImproperlyConfigured("NumberOfDays: {} is not defined for the date: {}".format(days_type_first_reminder.name, today))

days_type_second_reminder = NumberOfDaysType.objects.get(code=CODE_DAYS_FOR_SECOND_REMINDER)
days_type_second_reminder = NumberOfDaysType.objects.filter(code=CODE_DAYS_FOR_SECOND_REMINDER).first()
days_setting_second_reminder = NumberOfDaysSetting.get_setting_by_date(days_type_second_reminder, today)
if not days_setting_second_reminder:
raise ImproperlyConfigured("NumberOfDays: {} is not defined for the date: {}".format(days_type_second_reminder.name, today))

days_type_final_reminder = NumberOfDaysType.objects.get(code=CODE_DAYS_FOR_FINAL_REMINDER)
days_type_final_reminder = NumberOfDaysType.objects.filter(code=CODE_DAYS_FOR_FINAL_REMINDER).first()
days_setting_final_reminder = NumberOfDaysSetting.get_setting_by_date(days_type_final_reminder, today)
if not days_setting_final_reminder:
raise ImproperlyConfigured("NumberOfDays: {} is not defined for the date: {}".format(days_type_final_reminder.name, today))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def handle(self, *args, **options):
today = timezone.localtime(timezone.now()).date()

# Retrieve the number of days before expiry date of the approvals to email
days_type = NumberOfDaysType.objects.get(code=CODE_DAYS_FOR_ENDORSER_AUA_REMINDER)
days_type = NumberOfDaysType.objects.filter(code=CODE_DAYS_FOR_ENDORSER_AUA_REMINDER).first()
days_setting = NumberOfDaysSetting.get_setting_by_date(days_type, today)
if not days_setting:
# No number of days found
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@ def perform(self, approval_type, today, **options):
#Retrieve the date for which reminder email need to be sent
if approval_type == WaitingListAllocation.code:
approval_class = WaitingListAllocation
days_type_first_reminder = NumberOfDaysType.objects.get(code=CODE_DAYS_FOR_FIRST_REMINDER)
days_type_first_reminder = NumberOfDaysType.objects.filter(code=CODE_DAYS_FOR_FIRST_REMINDER).first()
days_setting_first_reminder = NumberOfDaysSetting.get_setting_by_date(days_type_first_reminder, today)
if not days_setting_first_reminder:
raise ImproperlyConfigured("NumberOfDays: {} is not defined for the date: {}".format(days_type_first_reminder.name, today))

days_type_second_reminder = NumberOfDaysType.objects.get(code=CODE_DAYS_FOR_SECOND_REMINDER)
days_type_second_reminder = NumberOfDaysType.objects.filter(code=CODE_DAYS_FOR_SECOND_REMINDER).first()
days_setting_second_reminder = NumberOfDaysSetting.get_setting_by_date(days_type_second_reminder, today)
if not days_setting_second_reminder:
raise ImproperlyConfigured("NumberOfDays: {} is not defined for the date: {}".format(days_type_second_reminder.name, today))

days_type_final_reminder = NumberOfDaysType.objects.get(code=CODE_DAYS_FOR_FINAL_REMINDER)
days_type_final_reminder = NumberOfDaysType.objects.filter(code=CODE_DAYS_FOR_FINAL_REMINDER).first()
days_setting_final_reminder = NumberOfDaysSetting.get_setting_by_date(days_type_final_reminder, today)
if not days_setting_final_reminder:
raise ImproperlyConfigured("NumberOfDays: {} is not defined for the date: {}".format(days_type_final_reminder.name, today))

days_type_total_period = NumberOfDaysType.objects.get(code=CODE_DAYS_FOR_SUBMIT_DOCUMENTS_MLA)
days_type_total_period = NumberOfDaysType.objects.filter(code=CODE_DAYS_FOR_SUBMIT_DOCUMENTS_MLA).first()
days_setting_total_period = NumberOfDaysSetting.get_setting_by_date(days_type_total_period, today)
if not days_setting_total_period:
raise ImproperlyConfigured("NumberOfDays: {} is not defined for the date: {}".format(days_type_total_period.name, today))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@ def perform(self, approval_type, today, **options):
#Retrieve the date for which reminder email need to be sent
if approval_type == WaitingListAllocation.code:
approval_class = WaitingListAllocation
days_type_first_reminder = NumberOfDaysType.objects.get(code=CODE_DAYS_FOR_FIRST_REMINDER)
days_type_first_reminder = NumberOfDaysType.objects.filter(code=CODE_DAYS_FOR_FIRST_REMINDER).first()
days_setting_first_reminder = NumberOfDaysSetting.get_setting_by_date(days_type_first_reminder, today)
if not days_setting_first_reminder:
raise ImproperlyConfigured("NumberOfDays: {} is not defined for the date: {}".format(days_type_first_reminder.name, today))

days_type_second_reminder = NumberOfDaysType.objects.get(code=CODE_DAYS_FOR_SECOND_REMINDER)
days_type_second_reminder = NumberOfDaysType.objects.filter(code=CODE_DAYS_FOR_SECOND_REMINDER).first()
days_setting_second_reminder = NumberOfDaysSetting.get_setting_by_date(days_type_second_reminder, today)
if not days_setting_second_reminder:
raise ImproperlyConfigured("NumberOfDays: {} is not defined for the date: {}".format(days_type_second_reminder.name, today))

days_type_final_reminder = NumberOfDaysType.objects.get(code=CODE_DAYS_FOR_FINAL_REMINDER)
days_type_final_reminder = NumberOfDaysType.objects.filter(code=CODE_DAYS_FOR_FINAL_REMINDER).first()
days_setting_final_reminder = NumberOfDaysSetting.get_setting_by_date(days_type_final_reminder, today)
if not days_setting_final_reminder:
raise ImproperlyConfigured("NumberOfDays: {} is not defined for the date: {}".format(days_type_final_reminder.name, today))

days_type_total_period = NumberOfDaysType.objects.get(code=CODE_DAYS_FOR_SUBMIT_DOCUMENTS_MLA)
days_type_total_period = NumberOfDaysType.objects.filter(code=CODE_DAYS_FOR_SUBMIT_DOCUMENTS_MLA).first()
days_setting_total_period = NumberOfDaysSetting.get_setting_by_date(days_type_total_period, today)
if not days_setting_total_period:
raise ImproperlyConfigured("NumberOfDays: {} is not defined for the date: {}".format(days_type_total_period.name, today))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ def perform(self, approval_type, today, **options):

# Retrieve the number of days before expiry date of the approvals to email
if approval_type == WaitingListAllocation.code:
days_type = NumberOfDaysType.objects.get(code=CODE_DAYS_BEFORE_END_OF_SIX_MONTH_PERIOD_WLA)
days_type = NumberOfDaysType.objects.filter(code=CODE_DAYS_BEFORE_END_OF_SIX_MONTH_PERIOD_WLA).first()
approval_class = WaitingListAllocation
elif approval_type == MooringLicence.code:
days_type = NumberOfDaysType.objects.get(code=CODE_DAYS_BEFORE_END_OF_SIX_MONTH_PERIOD_ML)
days_type = NumberOfDaysType.objects.filter(code=CODE_DAYS_BEFORE_END_OF_SIX_MONTH_PERIOD_ML).first(0)
approval_class = MooringLicence
else:
# Do nothing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Command(BaseCommand):

def handle(self, *args, **options):
today = timezone.localtime(timezone.now()).date()
days_type = NumberOfDaysType.objects.get(code=CODE_DAYS_BEFORE_DUE_COMPLIANCE)
days_type = NumberOfDaysType.objects.filter(code=CODE_DAYS_BEFORE_DUE_COMPLIANCE).first()
days_setting = NumberOfDaysSetting.get_setting_by_date(days_type, today)
compare_date = today + datetime.timedelta(days=days_setting.number_of_days)

Expand Down

0 comments on commit 4594bb6

Please sign in to comment.