diff --git a/mooringlicensing/components/proposals/api.py b/mooringlicensing/components/proposals/api.py index cfa565408..3b8622255 100755 --- a/mooringlicensing/components/proposals/api.py +++ b/mooringlicensing/components/proposals/api.py @@ -1349,6 +1349,7 @@ def vessel_rego_document(self, request, *args, **kwargs): return Response({'filedata': returned_file_data}) + @detail_route(methods=['POST'], detail=True) @renderer_classes((JSONRenderer,)) @basic_exception_handler @@ -1859,7 +1860,6 @@ def approval_level_document(self, request, *args, **kwargs): @detail_route(methods=['POST',], detail=True) @basic_exception_handler def final_approval(self, request, *args, **kwargs): - print('final_approval() in ProposalViewSet') instance = self.get_object() serializer = ProposedApprovalSerializer(data=request.data) serializer.is_valid(raise_exception=True) @@ -2509,9 +2509,9 @@ def find_related_approvals(self, request, *args, **kwargs): def lookup_vessel_ownership(self, request, *args, **kwargs): vessel = self.get_object() if is_internal(request): - serializer = VesselFullOwnershipSerializer(vessel.filtered_vesselownership_set.distinct("owner"), many=True) + serializer = VesselFullOwnershipSerializer(vessel.filtered_vesselownership_set.order_by("owner","-updated").distinct("owner"), many=True) else: - serializer = VesselFullOwnershipSerializer(vessel.filtered_vesselownership_set.filter(owner__emailuser=request.user.id).distinct("owner"), many=True) + serializer = VesselFullOwnershipSerializer(vessel.filtered_vesselownership_set.filter(owner__emailuser=request.user.id).order_by("owner","-updated").distinct("owner"), many=True) return Response(serializer.data) @detail_route(methods=['GET',], detail=True) @@ -2611,8 +2611,7 @@ def list_internal(self, request, *args, **kwargs): raise serializers.ValidationError("error") else: raise serializers.ValidationError("no email user id provided") - - vessel_ownership_list = owner.vesselownership_set.distinct("vessel") + vessel_ownership_list = owner.vesselownership_set.order_by("vessel","-updated").distinct("vessel") # TODO review - rewrite following for vessel_ownership_list if search_text: @@ -2639,7 +2638,7 @@ def list_external(self, request, *args, **kwargs): owner_qs = Owner.objects.filter(emailuser=request.user.id) if owner_qs: owner = owner_qs[0] - vessel_ownership_list = owner.vesselownership_set.distinct("vessel") + vessel_ownership_list = owner.vesselownership_set.order_by("vessel","-updated").distinct("vessel") # rewrite following for vessel_ownership_list if search_text: diff --git a/mooringlicensing/components/proposals/models.py b/mooringlicensing/components/proposals/models.py index 4a86e4007..907ae56a1 100644 --- a/mooringlicensing/components/proposals/models.py +++ b/mooringlicensing/components/proposals/models.py @@ -509,8 +509,8 @@ def get_previous_vessel_ownerships(self): while True: if proposal.previous_application: if proposal.previous_application.vessel_ownership: - if proposal.previous_application.vessel_ownership.excludable(proposal): - vessel_ownerships.append(proposal.previous_application.vessel_ownership) + #if proposal.previous_application.vessel_ownership.excludable(proposal): + vessel_ownerships.append(proposal.previous_application.vessel_ownership) if get_out_of_loop: break diff --git a/mooringlicensing/components/proposals/serializers.py b/mooringlicensing/components/proposals/serializers.py index 377a12fd0..d9ababf0d 100644 --- a/mooringlicensing/components/proposals/serializers.py +++ b/mooringlicensing/components/proposals/serializers.py @@ -1647,7 +1647,8 @@ def validate(self, data): class VesselOwnershipSerializer(serializers.ModelSerializer): # company_ownership = CompanyOwnershipSerializer() company_ownership = serializers.SerializerMethodField() - + proposal_id = serializers.SerializerMethodField() + class Meta: model = VesselOwnership fields = '__all__' @@ -1660,7 +1661,12 @@ def get_company_ownership(self, obj): data = serializer.data return data - + def get_proposal_id(self, obj): + proposal = Proposal.objects.filter(vessel_ownership=obj).last() + if(proposal): + return proposal.id + return None + class VesselFullOwnershipSerializer(serializers.ModelSerializer): # company_ownership = CompanyOwnershipSerializer() company_ownership = serializers.SerializerMethodField() diff --git a/mooringlicensing/frontend/mooringlicensing/src/components/common/vessels.vue b/mooringlicensing/frontend/mooringlicensing/src/components/common/vessels.vue index d2fc8ddf6..a9736acc2 100755 --- a/mooringlicensing/frontend/mooringlicensing/src/components/common/vessels.vue +++ b/mooringlicensing/frontend/mooringlicensing/src/components/common/vessels.vue @@ -399,10 +399,13 @@ export default { }, vesselRegoDocumentUrl: function () { let url = '' - if (this.proposal){ + if (this.proposal && this.proposal.id){ // Call a function defined in the ProposalViewSet url = '/api/proposal/' + this.proposal.id + '/vessel_rego_document/' } + else if (this.vesselOwnership.proposal_id){ + url = '/api/proposal/' + this.vesselOwnership.proposal_id + '/vessel_rego_document/' + } return url }, // vesselRegistrationDocumentUrl: function () { @@ -427,6 +430,10 @@ export default { // Call a function defined in the ProposalViewSet url = '/api/proposal/' + this.proposal.id + '/hull_identification_number_document/' } + else if (this.vesselOwnership.proposal_id){ + url = '/api/proposal/' + this.vesselOwnership.proposal_id + '/hull_identification_number_document/' + console.log(url) + } return url }, companyName: function () { diff --git a/mooringlicensing/frontend/mooringlicensing/src/components/forms/filefield_immediate.vue b/mooringlicensing/frontend/mooringlicensing/src/components/forms/filefield_immediate.vue index f5397841b..821366a57 100644 --- a/mooringlicensing/frontend/mooringlicensing/src/components/forms/filefield_immediate.vue +++ b/mooringlicensing/frontend/mooringlicensing/src/components/forms/filefield_immediate.vue @@ -209,7 +209,6 @@ export default { }, delete_all_documents: function(){ - console.log('aho') for (let item of this.documents){ this.delete_document(item) }