Skip to content

Commit

Permalink
Merge pull request #353 from shibaken/main
Browse files Browse the repository at this point in the history
shibaken/main to dbca-wa/main
  • Loading branch information
jawaidm authored Sep 22, 2023
2 parents b7b60c5 + d4a42ce commit d3e7b31
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 43 deletions.
2 changes: 1 addition & 1 deletion mooringlicensing/components/approvals/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@admin.register(models.Sticker)
class StickerAdmin(admin.ModelAdmin):
list_display = ['id', 'number', 'status', 'approval', 'dcv_permit', 'printing_date', 'mailing_date', 'fee_season',]
list_display = ['id', 'number', 'status', 'approval', 'dcv_permit', 'printing_date', 'mailing_date', 'fee_season', 'date_created', 'date_updated',]
search_fields = ['id', 'number', 'approval__lodgement_number',]
list_filter = ['status',]
list_display_links = ['id', 'number',]
Expand Down
2 changes: 1 addition & 1 deletion mooringlicensing/components/approvals/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ def get_queryset(self):
if debug:
qs = Sticker.objects.all()
else:
qs = Sticker.objects.filter(status__in=Sticker.EXPOSED_STATUS)
qs = Sticker.objects.filter(status__in=Sticker.EXPOSED_STATUS).order_by('-date_updated', '-date_created')
return qs


Expand Down
12 changes: 7 additions & 5 deletions mooringlicensing/components/approvals/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,10 +933,10 @@ def send_reissue_aap_after_sale_recorded_email(approval, request, vessel_ownersh
_log_user_email(msg, approval.submitter_obj, proposal.submitter_obj, sender=sender)


def send_sticker_replacement_email(request, old_sticker, new_sticker, invoice_reference):
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
# approval = new_sticker.approval
proposal = approval.current_proposal

email = TemplateEmailBase(
Expand All @@ -954,7 +954,7 @@ def send_sticker_replacement_email(request, old_sticker, new_sticker, invoice_re
url = f'{settings.LEDGER_API_URL}/ledgergw/invoice-pdf/{settings.LEDGER_API_KEY}/{invoice_reference}'
invoice_pdf = requests.get(url=url)
if invoice_pdf.status_code == 200:
attachment = ('invoice#{}.pdf'.format(proposal.invoice.reference), invoice_pdf.content, 'application/pdf')
attachment = ('invoice#{}.pdf'.format(invoice_reference), invoice_pdf.content, 'application/pdf')

# url = get_invoice_url(invoice.reference, request)
# invoice_pdf = requests.get(url=url)
Expand All @@ -965,7 +965,7 @@ def send_sticker_replacement_email(request, old_sticker, new_sticker, invoice_re
context = {
'public_url': get_public_url(request),
'recipient': approval.submitter_obj,
'sticker': old_sticker,
'old_sticker_numbers': ','.join(old_sticker_numbers),
'dashboard_external_url': get_public_url(request),
}

Expand All @@ -975,7 +975,9 @@ def send_sticker_replacement_email(request, old_sticker, new_sticker, invoice_re
if cc_list:
all_ccs = [cc_list]

msg = email.send(proposal.submitter_obj.email, cc=all_ccs, context=context, attachments=attachments)
bcc = proposal.assessor_recipients

msg = email.send(proposal.submitter_obj.email, cc=all_ccs, bcc=bcc, context=context, attachments=attachments)
if msg:
sender = request.user if request else settings.DEFAULT_FROM_EMAIL
_log_approval_email(msg, approval, sender=sender, attachments=attachments)
Expand Down
4 changes: 3 additions & 1 deletion mooringlicensing/components/approvals/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2808,10 +2808,12 @@ class Sticker(models.Model):
vessel_ownership = models.ForeignKey('VesselOwnership', blank=True, null=True, on_delete=models.SET_NULL)
proposal_initiated = models.ForeignKey('Proposal', blank=True, null=True, on_delete=models.SET_NULL) # This propposal created this sticker object. Can be None when sticker created by RequestNewSticker action or so.
sticker_to_replace = models.ForeignKey('self', null=True, blank=True, on_delete=models.SET_NULL) # This sticker object replaces the sticker_to_replace for renewal
date_created = models.DateTimeField(blank=True, null=True, auto_now_add=True)
date_updated = models.DateTimeField(blank=True, null=True, auto_now=True)

class Meta:
app_label = 'mooringlicensing'
ordering = ['-number']
ordering = ['-date_updated', '-date_created', '-number',]

def get_invoices(self):
invoices = []
Expand Down
12 changes: 12 additions & 0 deletions mooringlicensing/components/approvals/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,7 @@ def validate(self, data):

class StickerSerializerSimple(serializers.ModelSerializer):
invoices = serializers.SerializerMethodField()
vessel_rego_no = serializers.SerializerMethodField()

class Meta:
model = Sticker
Expand All @@ -1240,6 +1241,7 @@ class Meta:
'number',
'mailing_date',
'invoices',
'vessel_rego_no',
)

def get_invoices(self, obj):
Expand All @@ -1250,6 +1252,12 @@ def get_invoices(self, obj):
serializer = InvoiceSerializer(invoices, many=True)
return serializer.data

def get_vessel_rego_no(self, obj):
if obj.vessel_ownership and obj.vessel_ownership.vessel:
return obj.vessel_ownership.vessel.rego_no
else:
return ''


class StickerSerializer(serializers.ModelSerializer):
status = serializers.SerializerMethodField()
Expand Down Expand Up @@ -1286,6 +1294,8 @@ class Meta:
'fee_season',
'invoices',
'can_view_payment_details',
'date_created',
'date_updated',
)
datatables_always_serialize = (
'id',
Expand All @@ -1304,6 +1314,8 @@ class Meta:
'fee_season',
'invoices',
'can_view_payment_details',
'date_created',
'date_updated',
)

def get_fee_season(self, obj):
Expand Down
2 changes: 1 addition & 1 deletion mooringlicensing/components/payments_ml/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class StickerActionFee(Payment):
def __str__(self):
stickers = []
for sticker_action_detail in self.sticker_action_details.all():
stickers. append(sticker_action_detail.sticker.number)
stickers.append(sticker_action_detail.sticker.number)
return 'Sticker(s): [{}] : Invoice {}'.format(','.join(stickers), self.invoice_reference)

class Meta:
Expand Down
23 changes: 15 additions & 8 deletions mooringlicensing/components/payments_ml/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ def post(self, request, *args, **kwargs):
request.user,
lines,
return_url=request.build_absolute_uri(reverse('sticker_replacement_fee_success', kwargs={"uuid": sticker_action_fee.uuid})),
return_preload_url=settings.MOORING_LICENSING_EXTERNAL_URL + reverse("sticker_replacement_fee_success_preload", kwargs={"uuid": sticker_action_fee.uuid}),
booking_reference=str(sticker_action_fee.uuid),
invoice_text='{}'.format(application_type.description),
)
Expand Down Expand Up @@ -306,15 +307,21 @@ def get(self, request, uuid, format=None):
sticker_action_fee.expiry_time = None
sticker_action_fee.save()

# for sticker_action_detail in sticker_action_details.all():
# old_sticker = sticker_action_detail.sticker
# new_sticker = old_sticker.request_replacement(Sticker.STICKER_STATUS_LOST)
sticker_action_detail = sticker_action_details.first()
old_sticker = sticker_action_detail.sticker
new_sticker = old_sticker.request_replacement(Sticker.STICKER_STATUS_LOST)

old_sticker_numbers = []
for sticker_action_detail in sticker_action_details.all():
old_sticker = sticker_action_detail.sticker
new_sticker = old_sticker.request_replacement(Sticker.STICKER_STATUS_LOST)
old_sticker_numbers.append(old_sticker.number)
# Send email with the invoice
send_sticker_replacement_email(request, old_sticker_numbers, new_sticker.approval, invoice.reference)

# sticker_action_detail = sticker_action_details.first()
# old_sticker = sticker_action_detail.sticker
# new_sticker = old_sticker.request_replacement(Sticker.STICKER_STATUS_LOST)

# Send email with the invoice
send_sticker_replacement_email(request, old_sticker, new_sticker, invoice.reference)
# send_sticker_replacement_email(request, old_sticker, new_sticker, invoice.reference)

logger.info(
"Returning status.HTTP_200_OK. Order created successfully.",
Expand All @@ -338,7 +345,7 @@ def get(self, request, uuid):
# invoice_url = get_invoice_url(invoice.reference, request)
# api_key = settings.LEDGER_API_KEY
# invoice_url = settings.LEDGER_API_URL+'/ledgergw/invoice-pdf/'+api_key+'/' + self.invoice.reference
invoice_url = f'/ledger-toolkit-api/invoice-pdf/{self.invoice.reference}/'
invoice_url = f'/ledger-toolkit-api/invoice-pdf/{invoice.reference}/'
# invoice_pdf = requests.get(url=url)
submitter = retrieve_email_userro(sticker_action_fee.created_by) if sticker_action_fee.created_by else ''

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ export default {
'Start Date',
'Expiry Date',
'Vessel Rego',
'Mooring',
'Action',
'Approval letter',
'Sticker replacement',
Expand Down Expand Up @@ -364,6 +365,7 @@ export default {
}
},
columnMooring: function(){
let vm = this
return {
data: "id",
orderable: true,
Expand All @@ -372,7 +374,11 @@ export default {
'render': function(row, type, full){
let links = ''
for (let mooring of full.moorings){
links += `<a href='/internal/moorings/${mooring.id}' target='_blank'>${mooring.mooring_name}</a><br/>`;
if (vm.is_internal){
links += `<a href='/internal/moorings/${mooring.id}' target='_blank'>${mooring.mooring_name}</a><br/>`
} else {
links += `${mooring.mooring_name}<br/>`
}
}
return links
},
Expand Down Expand Up @@ -641,9 +647,7 @@ export default {
'render': function(row, type, full){
let ret_str = ''
for (let sticker of full.stickers){
console.log('sticker')
console.log(sticker)
ret_str += sticker.number + '<br />'
ret_str += sticker.number + ' (' + sticker.vessel_rego_no + ')<br />'
}
return ret_str
},
Expand Down Expand Up @@ -780,6 +784,7 @@ export default {
vm.columnExpiryDate,
// vm.columnVesselRegistration,
vm.columnVesselRegos,
vm.columnMooring,
vm.columnAction,
vm.columnApprovalLetter,
vm.columnStickerReplacement,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export default {
return []
}
if (this.is_internal){
return ['id', 'Number', 'Permit or Licence', 'Vessel rego', 'Date sent / printed / mailed', 'Status', 'Season', 'Invoice', 'Action']
return ['id', 'Date Updated', 'Number', 'Permit or Licence', 'Vessel rego', 'Date sent / printed / mailed', 'Status', 'Season', 'Invoice', 'Action']
}
},
column_id: function(){
Expand All @@ -132,6 +132,17 @@ export default {
}
}
},
column_date_updated: function(){
return {
data: "date_updated",
orderable: true,
searchable: false,
visible: this.debug,
'render': function(row, type, full){
return full.date_updated
}
}
},
column_vessel_rego_no: function(){
return {
// 2. Number
Expand Down Expand Up @@ -296,6 +307,7 @@ export default {
if(vm.is_internal){
columns = [
vm.column_id,
vm.column_date_updated,
vm.column_number,
vm.column_permit_or_licence,
vm.column_vessel_rego_no,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,13 @@ export default {
regoReadonly: function () {
let readonly = false;
//if (this.proposal && this.proposal.approval_reissued && !this.proposal.approval_vessel_rego_no &&
if (this.proposal && !this.proposal.approval_vessel_rego_no && !this.proposal.current_vessels_rego_list && !this.readonly) {
if (!this.vesselOwnershipExists){
readonly = false
} else if (this.proposal && !this.proposal.approval_vessel_rego_no && !this.proposal.current_vessels_rego_list && !this.readonly) {
readonly = false;
} else if ((this.proposal && this.keep_current_vessel && ['amendment', 'renewal'].includes(this.proposal.proposal_type.code)) ||
this.readonly ||
(this.proposal.pending_amendment_request && ['wla', 'aaa'].includes(this.proposal.application_type_code))
) {
(this.proposal.pending_amendment_request && ['wla', 'aaa'].includes(this.proposal.application_type_code))) {
readonly = true;
}
return readonly;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,24 +207,9 @@ export default {
disableSubmit: function() {
console.log('%cdisableSubmit() is being called...', 'color: #FF0000')
let disable = false;
// if (this.proposal && this.proposal.proposal_type.code ==='amendment' && this.missingVessel) {
// console.log('%cHere1', 'color: #FF0000')
// disable = true;
// } else if (this.proposal && this.proposal.proposal_type.code ==='amendment') {
// if (['aaa', 'mla'].includes(this.proposal.application_type_code) && !this.vesselChanged) {
// console.log('%cHere2', 'color: #FF0000')
// disable = true;
// } else if (this.proposal.application_type_code === 'wla' && !this.vesselChanged && !this.mooringPreferenceChanged) {
// console.log('%cHere3', 'color: #FF0000')
// disable = true;
// } else if (this.proposal.application_type_code === 'aua' && !this.vesselChanged && !this.mooringOptionsChanged) {
// console.log('%cHere4', 'color: #FF0000')
// disable = true;
// }
// }
if (this.proposal){
if (this.proposal.proposal_type.code ==='amendment'){
if (this.missingVessel){
if (this.missingVessel && ['aaa', 'aua'].includes(this.proposal.application_type_code)){
disable = true;
} else {
if (['aaa', 'mla'].includes(this.proposal.application_type_code)){
Expand Down
27 changes: 27 additions & 0 deletions mooringlicensing/migrations/0331_auto_20230922_1042.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 3.2.20 on 2023-09-22 02:42

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('mooringlicensing', '0330_remove_companyownership_status'),
]

operations = [
migrations.AlterModelOptions(
name='sticker',
options={'ordering': ['-date_updated', '-date_created']},
),
migrations.AddField(
model_name='sticker',
name='date_created',
field=models.DateTimeField(auto_now_add=True, null=True),
),
migrations.AddField(
model_name='sticker',
name='date_updated',
field=models.DateTimeField(auto_now=True, null=True),
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{% block content_body %}
{% include "mooringlicensing/emails_2/salutation.html" %}
<p>Your request to replace {{ sticker.number }} has been received. Please find attached to this email your invoice as proof of payment.</p>
<p>Your request to replace sticker(s): {{ old_sticker_numbers }} has been received. Please find attached to this email your invoice as proof of payment.</p>
<p>Your replacement sticker(s) will be posted to you in the coming days. Once received, you must ensure it is displayed on your vessel at all times whilst within the limits of the Reserve.</p>
{% include "mooringlicensing/emails/signature-rottnest.html" %}
{% endblock %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{% block content_body %}
{% include "mooringlicensing/emails_2/salutation.txt" %}
Your request to replace {{ sticker.number }} has been received. Please find attached to this email your invoice as proof of payment.
Your request to replace sticker(s): {{ old_sticker_numbers }} has been received. Please find attached to this email your invoice as proof of payment.
Your replacement sticker(s) will be posted to you in the coming days. Once received, you must ensure it is displayed on your vessel at all times whilst within the limits of the Reserve.
{% include "mooringlicensing/emails/signature-rottnest.txt" %}
{% endblock %}
Expand Down

0 comments on commit d3e7b31

Please sign in to comment.