Skip to content

Commit

Permalink
Merge pull request #361 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 Oct 13, 2023
2 parents c191a85 + bba00a8 commit 6fb4185
Show file tree
Hide file tree
Showing 12 changed files with 238 additions and 136 deletions.
47 changes: 26 additions & 21 deletions mooringlicensing/components/approvals/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,26 +331,31 @@ def get_licence_document_as_attachment(self):
attachment = (file_name, licence_document.file.read(), 'application/pdf')
return attachment

@property
def postal_address_obj(self):
if self.submitter_obj.postal_same_as_residential:
address_obj = self.submitter_obj.residential_address
else:
address_obj = self.submitter_obj.postal_address
return address_obj

@property
def postal_address_line1(self):
try:
if self.current_proposal.proposal_applicant.postal_same_as_residential:
ret_value = self.current_proposal.proposal_applicant.residential_line1
else:
ret_value = self.current_proposal.proposal_applicant.postal_line1
ret_value = self.postal_address_obj.line1
except:
logger.error(f'Postal address line1 cannot be retrieved for the approval [{self}]')
logger.error(f'Postal address line1 cannot be retrieved for the approval [{self}].')
return ''

if not ret_value:
logger.warning(f'Empty postal_address_line1 found for the Approval: [{self}].')

return ret_value

@property
def postal_address_line2(self):
try:
if self.current_proposal.proposal_applicant.postal_same_as_residential:
ret_value = self.current_proposal.proposal_applicant.residential_line2
else:
ret_value = self.current_proposal.proposal_applicant.postal_line2
ret_value = self.postal_address_obj.line2
except:
logger.error(f'Postal address line2 cannot be retrieved for the approval [{self}]')
return ''
Expand All @@ -360,40 +365,40 @@ def postal_address_line2(self):
@property
def postal_address_state(self):
try:
if self.current_proposal.proposal_applicant.postal_same_as_residential:
ret_value = self.current_proposal.proposal_applicant.residential_state
else:
ret_value = self.current_proposal.proposal_applicant.postal_state
ret_value = self.postal_address_obj.state
except:
logger.error(f'Postal address state cannot be retrieved for the approval [{self}]')
return ''

if not ret_value:
logger.warning(f'Empty state found for the postal address of the Approval: [{self}].')

return ret_value

@property
def postal_address_suburb(self):
try:
if self.current_proposal.proposal_applicant.postal_same_as_residential:
ret_value = self.current_proposal.proposal_applicant.residential_locality
else:
ret_value = self.current_proposal.proposal_applicant.postal_locality
ret_value = self.postal_address_obj.locality
except:
logger.error(f'Postal address locality cannot be retrieved for the approval [{self}]')
return ''

if not ret_value:
logger.warning(f'Empty locality found for the postal address of the Approval: [{self}].')

return ret_value

@property
def postal_address_postcode(self):
try:
if self.current_proposal.proposal_applicant.postal_same_as_residential:
ret_value = self.current_proposal.proposal_applicant.residential_postcode
else:
ret_value = self.current_proposal.proposal_applicant.postal_postcode
ret_value = self.postal_address_obj.postcode
except:
logger.error(f'Postal address postcode cannot be retrieved for the approval [{self}]')
return ''

if not ret_value:
logger.warning(f'Empty postcode found for the postal address of the Approval: [{self}].')

return ret_value

@property
Expand Down
2 changes: 1 addition & 1 deletion mooringlicensing/components/approvals/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,7 @@ class StickerActionDetailSerializer(serializers.ModelSerializer):
date_created = serializers.DateTimeField(read_only=True)
date_updated = serializers.DateTimeField(read_only=True)
user_detail = serializers.SerializerMethodField()
waive_the_fee = serializers.BooleanField()
waive_the_fee = serializers.BooleanField(required=False)

class Meta:
model = StickerActionDetail
Expand Down
7 changes: 5 additions & 2 deletions mooringlicensing/components/main/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ def sticker_export():
mooring_names = [mooring.name for mooring in moorings]
mooring_names = ', '.join(mooring_names)

if not sticker.postal_address_line1 or not sticker.postal_address_suburb or not sticker.postal_address_state or not sticker.postal_address_postcode:
logger.warning(f'Postal address not found for the Sticker: [{sticker}].')
continue

ws1.append([
today.strftime('%d/%m/%Y'),
sticker.first_name,
Expand Down Expand Up @@ -546,11 +550,9 @@ def update_personal_details(request, user_id):
if dob:
dob = datetime.strptime(dob, '%d/%m/%Y')
payload['dob'] = dob.strftime('%Y-%m-%d')

residential_address = payload.get('residential_address', None)
if residential_address:
payload.update(residential_address)

postal_address = payload.get('postal_address', None)
if postal_address:
payload.update(postal_address)
Expand All @@ -568,5 +570,6 @@ def update_personal_details(request, user_id):
serializer = ProposalApplicantSerializer(proposal_applicant, data=payload)
serializer.is_valid(raise_exception=True)
proposal_applicant = serializer.save()
logger.info(f'ProposalApplicant: [{proposal_applicant}] has been updated with the data: [{payload}].')

return ret
75 changes: 28 additions & 47 deletions mooringlicensing/components/proposals/api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import os
import traceback
import pathlib
Expand All @@ -20,6 +21,7 @@
from ledger_api_client.settings_base import TIME_ZONE, LOGGING
# from ledger.accounts.models import EmailUser, Address
from ledger_api_client.ledger_models import EmailUserRO as EmailUser, Address
from ledger_api_client import api
from mooringlicensing import settings
from mooringlicensing.components.main.models import GlobalSettings
from mooringlicensing.components.organisations.models import Organisation
Expand Down Expand Up @@ -111,6 +113,7 @@
from copy import deepcopy

import logging
from mooringlicensing.ledger_api_utils import MyUserForLedgerAPI, update_account_details_in_ledger

from mooringlicensing.settings import PROPOSAL_TYPE_NEW, PROPOSAL_TYPE_AMENDMENT, PROPOSAL_TYPE_RENEWAL, \
PAYMENT_SYSTEM_ID, BASE_DIR, MAKE_PRIVATE_MEDIA_FILENAME_NON_GUESSABLE
Expand Down Expand Up @@ -1377,8 +1380,14 @@ def update_personal(self, request, *args, **kwargs):
serializer = ProposalApplicantSerializer(proposal_applicant, data=data)
serializer.is_valid(raise_exception=True)
serializer.save()

logger.info(f'Personal details of the proposal: {proposal} have been updated with the data: {data}')

# format dob for ledger
data['dob'] = dob.strftime('%d/%m/%Y')

## Update the ledger
ret = update_account_details_in_ledger(request, data)

return Response(serializer.data)

@detail_route(methods=['POST',], detail=True)
Expand All @@ -1396,8 +1405,11 @@ def update_contact(self, request, *args, **kwargs):
serializer = ProposalApplicantSerializer(proposal_applicant, data=data)
serializer.is_valid(raise_exception=True)
serializer.save()

logger.info(f'Contact details of the proposal: {proposal} have been updated with the data: {data}')

## Update the ledger
ret = update_account_details_in_ledger(request, data)

return Response(serializer.data)

@detail_route(methods=['POST',], detail=True)
Expand Down Expand Up @@ -1440,54 +1452,23 @@ def update_address(self, request, *args, **kwargs):
serializer = ProposalApplicantSerializer(proposal_applicant, data=data)
serializer.is_valid(raise_exception=True)
serializer.save()

logger.info(f'Address details of the proposal: {proposal} have been updated with the data: {data}')
return Response(serializer.data)

# print(request.data)
# instance = self.get_object()
# # residential address
# residential_serializer = UserAddressSerializer(data=request.data.get('residential_address'))
# residential_serializer.is_valid(raise_exception=True)
# residential_address, created = Address.objects.get_or_create(
# line1 = residential_serializer.validated_data['line1'],
# locality = residential_serializer.validated_data['locality'],
# state = residential_serializer.validated_data['state'],
# country = residential_serializer.validated_data['country'],
# postcode = residential_serializer.validated_data['postcode'],
# user = instance
# )
# instance.residential_address = residential_address
# # postal address
# postal_address_data = request.data.get('postal_address')
# postal_address = None
# if request.data.get('postal_same_as_residential'):
# instance.postal_same_as_residential = True
# instance.postal_address = residential_address
# elif postal_address_data and postal_address_data.get('line1'):
# postal_serializer = UserAddressSerializer(data=postal_address_data)
# postal_serializer.is_valid(raise_exception=True)
# postal_address, created = Address.objects.get_or_create(
# line1 = postal_serializer.validated_data['line1'],
# locality = postal_serializer.validated_data['locality'],
# state = postal_serializer.validated_data['state'],
# country = postal_serializer.validated_data['country'],
# postcode = postal_serializer.validated_data['postcode'],
# user = instance
# )
# instance.postal_address = postal_address
# instance.postal_same_as_residential = False
# else:
# instance.postal_same_as_residential = False
# instance.save()
#
# # Postal address form must be completed or checkbox ticked
# if not postal_address and not instance.postal_same_as_residential:
# raise serializers.ValidationError("Postal address not provided")
#
# serializer = UserSerializer(instance)
# return Response(serializer.data)
# Construct data for ledger
data_for_ledger = {
'residential_address': {},
'postal_address': {}
}
for key, value in data.items():
if 'postal' in key:
data_for_ledger['postal_address'][key] = value
elif 'residential' in key:
data_for_ledger['residential_address'][key] = value

## Update the ledger
ret = update_account_details_in_ledger(request, data_for_ledger)

return Response(serializer.data)


class ProposalRequirementViewSet(viewsets.ModelViewSet):
Expand Down
6 changes: 4 additions & 2 deletions mooringlicensing/components/proposals/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ class Proposal(DirtyFieldsMixin, RevisionedMixin):
site_licensee_email = models.CharField(max_length=200, blank=True, null=True)
mooring = models.ForeignKey('Mooring', null=True, blank=True, on_delete=models.SET_NULL)
endorser_reminder_sent = models.BooleanField(default=False)
declined_by_endorser = models.BooleanField(default=False)
## MLA
allocated_mooring = models.ForeignKey('Mooring', null=True, blank=True, on_delete=models.SET_NULL, related_name="ria_generated_proposal")
waiting_list_allocation = models.ForeignKey('mooringlicensing.WaitingListAllocation',null=True,blank=True, related_name="ria_generated_proposal", on_delete=models.SET_NULL)
Expand Down Expand Up @@ -853,13 +854,14 @@ def final_status(self):

def endorse_approved(self, request):
self.processing_status = Proposal.PROCESSING_STATUS_WITH_ASSESSOR

self.save()
logger.info(f'Endorsement approved for the Proposal: [{self}] by the endorser: [{request.user}].')

def endorse_declined(self, request):
self.processing_status = Proposal.PROCESSING_STATUS_DECLINED

self.declined_by_endorser = True
self.save()
logger.info(f'Endorsement declined for the Proposal: [{self}] by the endorser: [{request.user}].')

def update_customer_status(self):
matrix = {
Expand Down
94 changes: 49 additions & 45 deletions mooringlicensing/components/proposals/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,54 +413,58 @@ class ListProposalSerializer(BaseProposalSerializer):
class Meta:
model = Proposal
fields = (
'id',
'migrated',
'application_type_dict',
'proposal_type',
'customer_status',
'processing_status',
'applicant',
'submitter',
'assigned_officer',
'assigned_approver',
'lodgement_date',
'can_user_edit',
'can_user_view',
'lodgement_number',
'assessor_process',
'invoices',
'mooring_id',
'mooring',
'uuid',
'document_upload_url',
'can_view_payment_details',
'invoice_links',
)
'id',
'migrated',
'application_type_dict',
'proposal_type',
'customer_status',
'processing_status',
'applicant',
'submitter',
'assigned_officer',
'assigned_approver',
'lodgement_date',
'can_user_edit',
'can_user_view',
'lodgement_number',
'assessor_process',
'invoices',
'mooring_id',
'mooring',
'uuid',
'document_upload_url',
'can_view_payment_details',
'invoice_links',
'mooring_authorisation_preference',
'declined_by_endorser',
)
# the serverSide functionality of datatables is such that only columns that have field 'data' defined are requested from the serializer. We
# also require the following additional fields for some of the mRender functions
datatables_always_serialize = (
'id',
'migrated',
'proposal_type',
'customer_status',
'application_type_dict',
'processing_status',
'submitter',
'assigned_officer',
'assigned_approver',
'lodgement_date',
'can_user_edit',
'can_user_view',
'lodgement_number',
'assessor_process',
'invoices',
'mooring_id',
'mooring',
'uuid',
'document_upload_url',
'can_view_payment_details',
'invoice_links',
)
'id',
'migrated',
'proposal_type',
'customer_status',
'application_type_dict',
'processing_status',
'submitter',
'assigned_officer',
'assigned_approver',
'lodgement_date',
'can_user_edit',
'can_user_view',
'lodgement_number',
'assessor_process',
'invoices',
'mooring_id',
'mooring',
'uuid',
'document_upload_url',
'can_view_payment_details',
'invoice_links',
'mooring_authorisation_preference',
'declined_by_endorser',
)

def get_submitter(self, obj):
if obj.submitter:
Expand Down
Loading

0 comments on commit 6fb4185

Please sign in to comment.