-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #490 from awf-dbca/invoice-due-date
Invoice due date
- Loading branch information
Showing
24 changed files
with
348 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
mooringlicensing/management/commands/expire_application_due_to_no_payment.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from datetime import timedelta | ||
|
||
from django.utils import timezone | ||
from django.core.management.base import BaseCommand | ||
from django.core.exceptions import ImproperlyConfigured | ||
from django.db.models import Q | ||
|
||
import logging | ||
|
||
from mooringlicensing.components.proposals.email import send_expire_application_email, send_expire_notification_to_assessor | ||
from mooringlicensing.components.main.models import NumberOfDaysType, NumberOfDaysSetting | ||
from mooringlicensing.components.proposals.models import Proposal | ||
from mooringlicensing.management.commands.utils import construct_email_message | ||
from mooringlicensing.settings import CODE_DAYS_BEFORE_DUE_PAYMENT | ||
|
||
logger = logging.getLogger('cron_tasks') | ||
cron_email = logging.getLogger('cron_email') | ||
|
||
class Command(BaseCommand): | ||
help = 'expire application if not paid within configurable number of days after being approved and send email to inform applicant' | ||
|
||
def handle(self, *args, **options): | ||
errors = [] | ||
updates = [] | ||
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_setting = NumberOfDaysSetting.get_setting_by_date(days_type, today) | ||
if not days_setting: | ||
# No number of days found | ||
raise ImproperlyConfigured("NumberOfDays: {} is not defined for the date: {}".format(days_type.name, today)) | ||
|
||
logger.info('Running command {}'.format(__name__)) | ||
|
||
# Construct queries | ||
queries = Q() | ||
queries &= Q(processing_status=Proposal.PROCESSING_STATUS_AWAITING_PAYMENT) | ||
queries &= Q(payment_due_date__lt=today) | ||
|
||
for p in Proposal.objects.filter(queries): | ||
try: | ||
p.processing_status = Proposal.PROCESSING_STATUS_EXPIRED | ||
p.save() | ||
|
||
send_expire_application_email(p, p.payment_due_date) | ||
send_expire_notification_to_assessor(p, p.payment_due_date) | ||
logger.info('Expired notification sent for Proposal {}'.format(p.lodgement_number)) | ||
updates.append(p.lodgement_number) | ||
except Exception as e: | ||
err_msg = 'Error sending expired notification for Proposal {}'.format(p.lodgement_number) | ||
logger.error('{}\n{}'.format(err_msg, str(e))) | ||
errors.append(err_msg) | ||
|
||
cmd_name = __name__.split('.')[-1].replace('_', ' ').upper() | ||
msg = construct_email_message(cmd_name, errors, updates) | ||
logger.info(msg) | ||
cron_email.info(msg) |
58 changes: 58 additions & 0 deletions
58
mooringlicensing/management/commands/send_application_payment_due_reminder.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from datetime import timedelta | ||
|
||
from django.utils import timezone | ||
from django.core.management.base import BaseCommand | ||
from django.core.exceptions import ImproperlyConfigured | ||
from django.db.models import Q | ||
|
||
import logging | ||
|
||
from mooringlicensing.components.proposals.email import send_payment_reminder_email | ||
from mooringlicensing.components.main.models import NumberOfDaysType, NumberOfDaysSetting | ||
from mooringlicensing.components.proposals.models import Proposal | ||
from mooringlicensing.management.commands.utils import construct_email_message | ||
from mooringlicensing.settings import CODE_DAYS_FOR_DUE_PAYMENT_REMINDER | ||
|
||
logger = logging.getLogger('cron_tasks') | ||
cron_email = logging.getLogger('cron_email') | ||
|
||
class Command(BaseCommand): | ||
help = 'send email reminder to applicant to submit payment for an application if not paid within configurable number of days after being approved' | ||
|
||
def handle(self, *args, **options): | ||
errors = [] | ||
updates = [] | ||
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_setting = NumberOfDaysSetting.get_setting_by_date(days_type, today) | ||
if not days_setting: | ||
# No number of days found | ||
raise ImproperlyConfigured("NumberOfDays: {} is not defined for the date: {}".format(days_type.name, today)) | ||
boundary_date = today + timedelta(days=days_setting.number_of_days) | ||
|
||
logger.info('Running command {}'.format(__name__)) | ||
|
||
# Construct queries | ||
queries = Q() | ||
queries &= Q(processing_status=Proposal.PROCESSING_STATUS_AWAITING_PAYMENT) | ||
queries &= Q(payment_due_date__lt=boundary_date) | ||
queries &= Q(payment_reminder_sent=False) | ||
|
||
for p in Proposal.objects.filter(queries): | ||
try: | ||
p.payment_reminder_sent = True | ||
p.save() | ||
send_payment_reminder_email(p) | ||
logger.info('Payment reminder sent for Proposal {}'.format(p.lodgement_number)) | ||
updates.append(p.lodgement_number) | ||
except Exception as e: | ||
err_msg = 'Error sending payment reminder for Proposal {}'.format(p.lodgement_number) | ||
logger.error('{}\n{}'.format(err_msg, str(e))) | ||
errors.append(err_msg) | ||
|
||
cmd_name = __name__.split('.')[-1].replace('_', ' ').upper() | ||
msg = construct_email_message(cmd_name, errors, updates) | ||
logger.info(msg) | ||
cron_email.info(msg) |
Oops, something went wrong.