Skip to content

Commit

Permalink
Merge pull request #146 from shibaken/working
Browse files Browse the repository at this point in the history
working to main
  • Loading branch information
shibaken authored Nov 3, 2023
2 parents cc1a400 + 18261e0 commit f0aa6f3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
16 changes: 16 additions & 0 deletions mooringlicensing/components/proposals/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,22 @@ class Meta:
app_label = 'mooringlicensing'
verbose_name = "Application"
verbose_name_plural = "Applications"

def get_latest_vessel_ownership_by_vessel(self, vessel):
if self.previous_application:
if self.previous_application.vessel_ownership:
if self.previous_application.vessel_ownership.vessel == vessel:
# Same vessel is found.
return self.previous_application.vessel_ownership
else:
# vessel of the previous application is differenct vessel. Search further back.
return self.previous_application.get_latest_vessel_ownership_by_vessel(vessel)
else:
# vessel_ownership is None or so (Null vessel case). Search further back.
return self.previous_application.get_latest_vessel_ownership_by_vessel(vessel)
else:
# No previous application exists
return None

def copy_proof_of_identity_documents(self, proposal):
for doc in self.proof_of_identity_documents.all():
Expand Down
12 changes: 7 additions & 5 deletions mooringlicensing/components/proposals/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,6 @@ def save_vessel_data(instance, request, vessel_data):
else:
serializer = SaveDraftProposalVesselSerializer(instance, vessel_data)
serializer.is_valid(raise_exception=True)
print(serializer.validated_data)
serializer.save()
logger.info(f'Proposal: [{instance}] has been updated with the vessel data: [{vessel_data}]')

Expand Down Expand Up @@ -604,11 +603,13 @@ def submit_vessel_data(instance, request, vessel_data):
else:
raise serializers.ValidationError("Application cannot be submitted without a vessel listed")

# save vessel data into proposal first
# Handle fields of the Proposal obj
save_vessel_data(instance, request, vessel_data)

# Handle VesselDetails obj
vessel, vessel_details = store_vessel_data(request, vessel_data)

# associate vessel_details with proposal
# Associate the vessel_details with the proposal
instance.vessel_details = vessel_details
instance.save()

Expand Down Expand Up @@ -783,10 +784,11 @@ def store_vessel_ownership(request, vessel, instance=None):
vo_created = True
elif instance.proposal_type.code in [PROPOSAL_TYPE_AMENDMENT, PROPOSAL_TYPE_RENEWAL,]:
# Retrieve a vessel_ownership from the previous proposal
vessel_ownership = instance.previous_application.vessel_ownership
# vessel_ownership = instance.previous_application.vessel_ownership # !!! This is not always true when ML !!!
vessel_ownership = instance.get_latest_vessel_ownership_by_vessel(vessel)

vessel_ownership_to_be_created = False
if vessel_ownership.end_date:
if vessel_ownership and vessel_ownership.end_date:
logger.info(f'Existing VesselOwnership: [{vessel_ownership}] has been retrieved, but the vessel is sold. This vessel ownership cannot be used.')
vessel_ownership_to_be_created = True

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ from '@/utils/hooks'
name:'current_vessels',
data:function () {
return {
keep_current_vessel: null,
keep_current_vessel: null, // Force the user to select one of the radio buttons
}
},
components:{
Expand Down Expand Up @@ -145,13 +145,15 @@ from '@/utils/hooks'
},
},
mounted: function () {
// this.resetCurrentVessel();
if (this.proposal && this.proposal.proposal_type.code == 'new' && this.proposal.processing_status != 'Draft'){
this.keep_current_vessel = true
this.resetCurrentVessel()
} else if (this.proposal && !this.proposal.keep_existing_vessel) {
this.keep_current_vessel = false
this.resetCurrentVessel()
}
},
created: function() {
if (this.proposal && !this.proposal.keep_existing_vessel) {
this.keep_current_vessel = false;
this.resetCurrentVessel();
}
},
}
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,12 @@
</div>
<div class="tab-pane fade" id="pills-vessels" role="tabpanel" aria-labelledby="pills-vessels-tab">
<div v-if="proposal">
<CurrentVessels :proposal=proposal :readonly=readonly :is_internal=is_internal
@resetCurrentVessel=resetCurrentVessel />
<CurrentVessels
:proposal=proposal
:readonly=readonly
:is_internal=is_internal
@resetCurrentVessel=resetCurrentVessel
/>
</div>
<Vessels
:proposal="proposal"
Expand Down Expand Up @@ -296,6 +300,7 @@ export default {
this.$emit("updateVesselOwnershipChanged", changed);
},
resetCurrentVessel: function (keep) {
console.log({keep})
this.keepCurrentVessel = keep;
this.uuid++
this.updateAmendmentRenewalProperties();
Expand Down

0 comments on commit f0aa6f3

Please sign in to comment.