Skip to content

Commit

Permalink
Merge pull request #515 from awf-dbca/vessel-save-change-follow-up
Browse files Browse the repository at this point in the history
fixed get mooring per bay lookup to use draft vessel details
  • Loading branch information
xzzy authored Jan 14, 2025
2 parents 4cc335f + be92135 commit 8578bee
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
17 changes: 8 additions & 9 deletions mooringlicensing/components/proposals/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,9 @@ class GetMooringPerBay(views.APIView):
def get(self, request, format=None):

available_moorings = request.GET.get('available_moorings')
vessel_details_id = request.GET.get('vessel_details_id')
vessel_details = {}
vessel_details["vessel_length"] = request.GET.get('vessel_length')
vessel_details["vessel_draft"] = request.GET.get('vessel_draft')
wla_id = request.GET.get('wla_id')
aup_id = request.GET.get('aup_id')
search_term = request.GET.get('term', '')
Expand All @@ -325,13 +327,11 @@ def get(self, request, format=None):
except:
logger.error("wla_id {} is not an integer".format(wla_id))
raise serializers.ValidationError("wla_id is not an integer")
vessel_details_id = wla.current_proposal.vessel_details.id
## restrict search results to suitable vessels
vessel_details = VesselDetails.objects.get(id=vessel_details_id)
mooring_filter = Q(
Q(name__icontains=search_term) &
Q(vessel_size_limit__gte=vessel_details.vessel_applicable_length) &
Q(vessel_draft_limit__gte=vessel_details.vessel_draft)
Q(vessel_size_limit__gte=wla.current_proposal.vessel_length) &
Q(vessel_draft_limit__gte=wla.current_proposal.vessel_draft)
)
data = Mooring.available_moorings.filter(mooring_filter, active=True).values('id', 'name', 'mooring_licence', "vessel_size_limit", "vessel_draft_limit", "vessel_weight_limit")[:num_of_moorings_to_return]
else:
Expand All @@ -342,13 +342,12 @@ def get(self, request, format=None):
aup_mooring_ids = []
if aup_id:
aup_mooring_ids = [moa.mooring.id for moa in AuthorisedUserPermit.objects.get(id=aup_id).mooringonapproval_set.filter(active=True)]
if vessel_details_id:
if vessel_details:
## restrict search results to suitable vessels
vessel_details = VesselDetails.objects.get(id=vessel_details_id)
mooring_filter = Q(
Q(name__icontains=search_term) &
Q(vessel_size_limit__gte=vessel_details.vessel_applicable_length) &
Q(vessel_draft_limit__gte=vessel_details.vessel_draft) &
Q(vessel_size_limit__gte=vessel_details["vessel_length"]) &
Q(vessel_draft_limit__gte=vessel_details["vessel_draft"]) &
~Q(id__in=aup_mooring_ids) &
Q(active=True) &
Q(mooring_licence__status__in=MooringLicence.STATUSES_AS_CURRENT) # Make sure this mooring is licensed because an unlicensed mooring would never be allocated to an AU permit.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,9 @@ export default {
term: params.term,
type: 'public',
mooring_bay_id: vm.approval.mooring_bay_id,
vessel_details_id: vm.proposal.vessel_details_id,
vessel_length:vm.proposal.vessel_length,
vessel_draft:vm.proposal.vessel_draft,
vessel_weight:vm.proposal.vessel_weight,
aup_id: vm.proposal.approval_id,
}
console.log('in data()')
Expand Down

0 comments on commit 8578bee

Please sign in to comment.