Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code cleanup, minor fixes, and endorsement fixes #508

Merged
merged 9 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions mooringlicensing/components/approvals/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
DcvVesselSerializer,
ListDcvPermitSerializer,
ListDcvAdmissionSerializer, StickerSerializer, StickerActionDetailSerializer,
ApprovalHistorySerializer, LookupDcvAdmissionSerializer, LookupDcvPermitSerializer, StickerForDcvSaveSerializer,
ApprovalHistorySerializer, StickerForDcvSaveSerializer,
StickerPostalAddressSaveSerializer
)
from mooringlicensing.components.users.utils import get_user_name
Expand Down Expand Up @@ -1370,7 +1370,6 @@ def request_new_stickers(self, request, *args, **kwargs):
#internal
dcv_permit = self.get_object()
details = request.data['details']
# sticker_ids = [sticker['id'] for sticker in request.data['stickers']]
sticker_ids = []
for sticker in request.data['stickers']:
if sticker['checked'] == True:
Expand All @@ -1384,8 +1383,6 @@ def request_new_stickers(self, request, *args, **kwargs):
data = {}
today = datetime.now(pytz.timezone(settings.TIME_ZONE)).date()
for sticker in stickers:
print("sticker address")
print(sticker.postal_address_line1)
data['action'] = 'Request new sticker'
data['user'] = request.user.id
data['reason'] = details['reason']
Expand Down
20 changes: 1 addition & 19 deletions mooringlicensing/components/approvals/email.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
import datetime
import logging
import ledger_api_client
import mimetypes
import pytz
import requests
from dateutil.relativedelta import relativedelta
from django.contrib.auth.models import Group
from django.core.mail import EmailMultiAlternatives, EmailMessage
from django.utils.encoding import smart_str
# from django.core.urlresolvers import reverse
from django.urls import reverse
from django.conf import settings
from datetime import timedelta
# from ledger.payments.pdf import create_invoice_pdf_bytes
from mooringlicensing import settings
from mooringlicensing.components.emails.emails import TemplateEmailBase, _extract_email_headers
from ledger_api_client.ledger_models import EmailUserRO as EmailUser, EmailUserRO
from mooringlicensing.components.emails.utils import get_user_as_email_user, get_public_url, make_http_https
from mooringlicensing.components.users.models import EmailUserLogEntry
# from mooringlicensing.components.main.utils import _log_user_email
#from django.core.files.storage import default_storage
from django.core.files.base import ContentFile

from mooringlicensing.components.users.utils import _log_user_email
Expand All @@ -36,8 +27,6 @@

class ApprovalExpireNotificationEmail(TemplateEmailBase):
subject = 'Approval expired' # This is default and should be overwitten
# html_template = 'mooringlicensing/emails/approval_expire_notification.html'
# txt_template = 'mooringlicensing/emails/approval_expire_notification.txt'
html_template = 'mooringlicensing/emails_2/approval_expire_notification.html'
txt_template = 'mooringlicensing/emails_2/approval_expire_notification.txt'

Expand Down Expand Up @@ -114,12 +103,6 @@ def send_auth_user_mooring_removed_notification(approval, mooring_licence):


def send_approval_expire_email_notification(approval):
# if approval.is_lawful_authority:
# email = FilmingLawfulAuthorityApprovalExpireNotificationEmail()
# if approval.is_filming_licence:
# email = FilmingLicenceApprovalExpireNotificationEmail()
# else:
# email = ApprovalExpireNotificationEmail()
email = ApprovalExpireNotificationEmail(approval)
proposal = approval.current_proposal

Expand Down Expand Up @@ -740,7 +723,7 @@ def send_reissue_aap_after_sale_recorded_email(approval, request, vessel_ownersh
# email to annual admission permit holder upon automatic re-issue after date of sale is recorded (regardless of whether new vessel added at that time)
proposal = approval.current_proposal

# Calculate new vessle nomination due date
# Calculate new vessel nomination due date
sale_date = vessel_ownership.end_date
six_months = relativedelta(months=6)
due_date = sale_date + six_months
Expand Down Expand Up @@ -778,7 +761,6 @@ def send_reissue_aap_after_sale_recorded_email(approval, request, vessel_ownersh
def send_sticker_replacement_email(request, old_sticker_numbers, approval, invoice_reference):
# 36
# email to licence/permit holder when sticker replacement request has been submitted (with payment)
# approval = new_sticker.approval
proposal = approval.current_proposal
vessel_rego = proposal.vessel_ownership.vessel.rego_no
email = TemplateEmailBase(
Expand Down
4 changes: 1 addition & 3 deletions mooringlicensing/components/approvals/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import math
from dateutil.relativedelta import relativedelta

import ledger_api_client.utils
Expand Down Expand Up @@ -1185,7 +1184,6 @@ def set_wla_order(self):
def processes_after_cancel(self):
self.internal_status = None
self.status = Approval.APPROVAL_STATUS_CANCELLED # Cancelled has been probably set before reaching here.
# self.wla_queue_date = None
self.wla_order = None
self.save()
logger.info(f'Set attributes as follows: [internal_status=None, status=cancelled, wla_order=None] of the WL Allocation: [{self}].')
Expand Down Expand Up @@ -2659,7 +2657,7 @@ def create_fee_lines(self):
db_processes_after_success['datetime_for_calculating_fee'] = target_datetime.__str__()

application_type = ApplicationType.objects.get(code=settings.APPLICATION_TYPE_DCV_ADMISSION['code'])
# vessel_length = 1 # any number greater than 0

vessel_length = GlobalSettings.default_values[GlobalSettings.KEY_MINIMUM_VESSEL_LENGTH] + 1
proposal_type = None
oracle_code = application_type.get_oracle_code_by_date(target_date=target_date)
Expand Down
6 changes: 2 additions & 4 deletions mooringlicensing/components/approvals/pdf.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import datetime
from io import BytesIO

from django.core.files.base import ContentFile

from mooringlicensing.doctopdf import (
create_dcv_permit_pdf_tytes,
create_dcv_permit_pdf_bytes,
create_dcv_admission_pdf_bytes,
create_approval_doc_bytes,
)


def create_dcv_permit_document(dcv_permit):
# create bytes
contents_as_bytes = create_dcv_permit_pdf_tytes(dcv_permit)
contents_as_bytes = create_dcv_permit_pdf_bytes(dcv_permit)

filename = 'dcv_permit-{}.pdf'.format(dcv_permit.lodgement_number)
from mooringlicensing.components.approvals.models import DcvPermitDocument
Expand Down
2 changes: 0 additions & 2 deletions mooringlicensing/components/approvals/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,7 @@ def get_mooring_licence_vessels_detail(self, obj):
for sticker in obj.stickers.filter(
status__in=['current', 'awaiting_printing', 'to_be_returned'],
vessel_ownership=vessel_ownership).order_by('-number'):
# sticker_numbers += sticker.number + '<br>, '
sticker_numbers.append(sticker.number)
# sticker_numbers = sticker_numbers[0:-2]
sticker_numbers = '<br/>'.join(sticker_numbers)

vessel_details.append({
Expand Down
1 change: 0 additions & 1 deletion mooringlicensing/components/compliances/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

from mooringlicensing.components.emails.emails import TemplateEmailBase
from ledger_api_client.ledger_models import EmailUserRO as EmailUser
from django.core.files.base import ContentFile

from mooringlicensing.components.emails.utils import get_public_url, make_http_https
from mooringlicensing.components.users.utils import _log_user_email
Expand Down
2 changes: 1 addition & 1 deletion mooringlicensing/components/compliances/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Document, RevisionedMixin
)
from django.core.files.storage import FileSystemStorage
from mooringlicensing.components.proposals.models import ProposalRequirement, AmendmentReason
from mooringlicensing.components.proposals.models import ProposalRequirement
from mooringlicensing.components.compliances.email import (
send_compliance_accept_email_notification,
send_amendment_email_notification,
Expand Down
1 change: 0 additions & 1 deletion mooringlicensing/components/emails/emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ def send(self, to_addresses, from_address=None, context=None, attachments=None,


def _extract_email_headers(email_message, sender=None):
print(sender)
if isinstance(email_message, (EmailMultiAlternatives, EmailMessage,)):
# instead
text = email_message.body
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<p></p>
<p>
{{settings.BRANCH_NAME}}<br>
<!-- {{settings.DEP_NAME}}<br>-->
{{settings.RIA_NAME}}<br>
Phone: {{ settings.DEP_PHONE_SUPPORT }}<br>
Address: {{ settings.DEP_ADDRESS}}<br>
Expand All @@ -29,21 +28,11 @@
<p></p>
<p></p>
<p>
<!--
<strong><em>Please do not reply directly to this email. Should you need to contact the licensing section of the Department of
Biodiversity, Conservation and Attractions, please send emails to <a href="mailto:[email protected]">[email protected]</a>
or call (08) 9219 9000.</em></strong>
-->

<strong><em>
Please do not reply directly to this email. Should you need to contact the {{ settings.BRANCH_NAME}},
please send emails to <a href="mailto:{{ settings.SUPPORT_EMAIL }}">{{ settings.SUPPORT_EMAIL }}</a> or call {{ settings.DEP_PHONE_SUPPORT }}.
</em></strong>
</p>
<!-- <p>{{PUBLIC_URL}}</p> -->
<!-- <p>
<img src="{{settings.PUBLIC_URL}}/static/mooringlicensing/img/dbca-logo.jpg" title="None" width="500" style="height: auto;">
</p> -->
{% endblock %}
</body>
</html>
5 changes: 0 additions & 5 deletions mooringlicensing/components/emails/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ 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 = make_http_https(url)
return url

Expand All @@ -29,8 +27,6 @@ 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' in url:
url = url.replace('-uat-internal', '-uat')
else:
Expand All @@ -39,7 +35,6 @@ 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', '')

web_url = make_http_https(url)

Expand Down
5 changes: 0 additions & 5 deletions mooringlicensing/components/main/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
import traceback
from django.db import connection, reset_queries
import functools
from django.conf import settings
from django.core.exceptions import ValidationError
from django.core.handlers.wsgi import WSGIRequest
from django.http import HttpRequest
from rest_framework import serializers
from rest_framework.request import Request
import logging
from functools import wraps

Expand Down Expand Up @@ -41,7 +37,6 @@ def timed(*args, **kw):
kw['log_time'][name] = int((te - ts) * 1000)
else:
print('%r %2.2f ms' % (method.__name__, (te - ts) * 1000))
#logger.error('%r %2.2f ms' % (method.__name__, (te - ts) * 1000))
return result
return timed

Expand Down
6 changes: 0 additions & 6 deletions mooringlicensing/components/main/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,19 +343,13 @@ def is_editable(self):

@receiver(post_save, sender=VesselSizeCategory)
def _post_save_vsc(sender, instance, **kwargs):
print('VesselSizeCategory post save()')
print(instance.vessel_size_category_group)

for fee_constructor in instance.vessel_size_category_group.fee_constructors.all():
if fee_constructor.is_editable:
fee_constructor.reconstruct_fees()


@receiver(post_delete, sender=VesselSizeCategory)
def _post_delete_vsc(sender, instance, **kwargs):
print('VesselSizeCategory post delete()')
print(instance.vessel_size_category_group)

for fee_constructor in instance.vessel_size_category_group.fee_constructors.all():
if fee_constructor.is_editable:
fee_constructor.reconstruct_fees()
Expand Down
8 changes: 0 additions & 8 deletions mooringlicensing/components/main/process_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import os
from django.core.files.base import ContentFile
import traceback
from django.conf import settings

from mooringlicensing.components.proposals.models import (
ProposalMooringReportDocument, ProposalWrittenProofDocument, ProposalSignedLicenceAgreementDocument,
Expand Down Expand Up @@ -64,8 +63,6 @@ def process_generic_document(request, instance, document_type=None, *args, **kwa
elif document_type == 'proof_of_identity_document':
documents_qs = instance.proof_of_identity_documents.filter(proposalproofofidentitydocument__enabled=True)

print(documents_qs)

returned_file_data = [dict(file=d._file.url, id=d.id, name=d.name,) for d in documents_qs.filter(input_name=input_name) if d._file]
ret = {'filedata': returned_file_data}
else:
Expand Down Expand Up @@ -191,26 +188,21 @@ def save_document(request, instance, comms_instance, document_type, input_name=N
if document_type == 'mooring_report_document':
document = instance.mooring_report_documents.get_or_create(input_name=input_name, name=filename)[0]
proposal_document = ProposalMooringReportDocument.objects.filter(mooring_report_document=document).first()
# path_format_string = '{}/proposals/{}/mooring_report_documents/{}'
path_format_string = 'proposal/{}/mooring_report_documents/{}'
elif document_type == 'written_proof_document':
document = instance.written_proof_documents.get_or_create(input_name=input_name, name=filename)[0]
proposal_document = ProposalWrittenProofDocument.objects.filter(written_proof_document=document).first()
# path_format_string = '{}/proposals/{}/written_proof_documents/{}'
path_format_string = 'proposal/{}/written_proof_documents/{}'
elif document_type == 'signed_licence_agreement_document':
document = instance.signed_licence_agreement_documents.get_or_create(input_name=input_name, name=filename)[0]
proposal_document = ProposalSignedLicenceAgreementDocument.objects.filter(signed_licence_agreement_document=document).first()
# path_format_string = '{}/proposals/{}/signed_licence_agreement_documents/{}'
path_format_string = 'proposal/{}/signed_licence_agreement_documents/{}'
elif document_type == 'proof_of_identity_document':
document = instance.proof_of_identity_documents.get_or_create(input_name=input_name, name=filename)[0]
proposal_document = ProposalProofOfIdentityDocument.objects.filter(proof_of_identity_document=document).first()
# path_format_string = '{}/proposals/{}/proof_of_identity_documents/{}'
path_format_string = 'proposal/{}/proof_of_identity_documents/{}'
elif document_type == 'waiting_list_offer_document':
document = instance.waiting_list_offer_documents.get_or_create(input_name=input_name, name=filename)[0]
# path_format_string = '{}/approvals/{}/waiting_list_offer_documents/{}'
path_format_string = 'approval/{}/waiting_list_offer_documents/{}'

path = private_storage.save(path_format_string.format(instance.id, filename), ContentFile(_file.read()))
Expand Down
4 changes: 1 addition & 3 deletions mooringlicensing/components/main/serializers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from rest_framework import serializers
from mooringlicensing import settings
from mooringlicensing.components.main.models import CommunicationsLogEntry
from ledger_api_client.ledger_models import EmailUserRO, Invoice
from mooringlicensing.ledger_api_utils import get_invoice_payment_status
from ledger_api_client.ledger_models import EmailUserRO


class CommunicationLogEntrySerializer(serializers.ModelSerializer):
Expand Down
5 changes: 0 additions & 5 deletions mooringlicensing/components/main/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
from io import BytesIO

from ledger_api_client import api
from ledger_api_client.settings_base import TIME_ZONE
from django.utils import timezone
from confy import env
Expand All @@ -24,7 +23,6 @@
StickerPrintingBatch,
Proposal,
)
from mooringlicensing.components.main.decorators import query_debugger
from rest_framework import serializers
from openpyxl import Workbook
from copy import deepcopy
Expand Down Expand Up @@ -200,7 +198,6 @@ def retrieve_mooring_areas():
res = requests.get(url)
res.raise_for_status()
data = res.json().get('data')
#return data
# update Mooring records
with transaction.atomic():
for mooring in data:
Expand Down Expand Up @@ -561,8 +558,6 @@ def export_to_mooring_booking(approval_id):


def calculate_minimum_max_length(fee_items_interested, max_amount_paid):
for item in fee_items_interested:
print(item)
"""
Find out MINIMUM max-length from fee_items_interested by max_amount_paid
"""
Expand Down
12 changes: 1 addition & 11 deletions mooringlicensing/components/payments_ml/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ def clean(self):
if num_of_periods < 1:
# No periods configured for this season
raise forms.ValidationError('At lease one period must exist in a season.')
elif num_of_periods == 1:
# There is one period configured
# All fine
pass
else:
elif num_of_periods > 1:
# There are more than one periods configured
# Check if all the periods sit in one year span
sorted_cleaned_data = sorted(self.cleaned_data, key=lambda item: item['start_date'])
Expand All @@ -45,12 +41,6 @@ def clean(self):
raise forms.ValidationError('Period\'s start date must be unique, but {} is duplicated.'.format(item['start_date']))



# @admin.register(FeePeriod)
# class FeePeriodAdmin(admin.ModelAdmin):
# list_display = ['id', 'name', 'start_date', 'is_first_period',]


class FeePeriodForm(forms.ModelForm):
class Meta:
model = FeePeriod
Expand Down
6 changes: 2 additions & 4 deletions mooringlicensing/components/payments_ml/invoice_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ def __payment_line(self):
canvas = self.canv
current_y, current_x = self.current_y, self.current_x
bpay_logo = ImageReader(BPAY_LOGO)
# Pay By Cheque
cheque_x = current_x + 4 * inch
cheque_y = current_y - 10

if self.invoice.payment_method in [self.invoice.PAYMENT_METHOD_MONTHLY_INVOICING, self.invoice.PAYMENT_METHOD_BPAY]:
# Outer BPAY Box
canvas.rect(current_x,current_y - 25,2.3*inch,-1.2*inch)
Expand Down Expand Up @@ -321,7 +319,7 @@ def _create_invoice(invoice_buffer, invoice, proposal):
elements.append(t)
elements.append(Spacer(1, SECTION_BUFFER_HEIGHT * 2))
# /Products Table
invoice_payment_status = invoice.id)
invoice_payment_status = invoice.id
if invoice_payment_status != 'paid' and invoice_payment_status != 'over_paid':
elements.append(Paragraph(settings.INVOICE_UNPAID_WARNING, styles['Left']))

Expand Down
Loading
Loading