From 6fdc90c32fe08b16599b5ef7e11d65d39e282aa9 Mon Sep 17 00:00:00 2001 From: katsufumi shibata Date: Fri, 3 Nov 2023 12:41:23 +0800 Subject: [PATCH 1/2] Customer can apply for the ML amendment application in order to change the details of the vessels other than the most recently added one --- mooringlicensing/components/proposals/models.py | 11 +++++++++++ mooringlicensing/components/proposals/utils.py | 12 +++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/mooringlicensing/components/proposals/models.py b/mooringlicensing/components/proposals/models.py index 089a29938..9f8acccff 100644 --- a/mooringlicensing/components/proposals/models.py +++ b/mooringlicensing/components/proposals/models.py @@ -409,6 +409,17 @@ 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: + return self.previous_application.vessel_ownership + else: + return self.previous_application.get_latest_vessel_ownership_by_vessel(vessel) + else: + return self.previous_application.get_latest_vessel_ownership_by_vessel(vessel) + return None def copy_proof_of_identity_documents(self, proposal): for doc in self.proof_of_identity_documents.all(): diff --git a/mooringlicensing/components/proposals/utils.py b/mooringlicensing/components/proposals/utils.py index a9eb60260..e8cd65d11 100644 --- a/mooringlicensing/components/proposals/utils.py +++ b/mooringlicensing/components/proposals/utils.py @@ -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}]') @@ -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() @@ -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 From 18261e06dec970d6074575b23bae4fa61d4f5c2b Mon Sep 17 00:00:00 2001 From: katsufumi shibata Date: Fri, 3 Nov 2023 15:56:59 +0800 Subject: [PATCH 2/2] Fix a bug where vessel details are not shown on the application in some case. Customer can apply for the ML amendment application in order to change the details of the vessels other than the most recently added one --- mooringlicensing/components/proposals/models.py | 7 ++++++- .../src/components/common/current_vessels.vue | 14 ++++++++------ .../mooringlicensing/src/components/form_wla.vue | 9 +++++++-- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/mooringlicensing/components/proposals/models.py b/mooringlicensing/components/proposals/models.py index 9f8acccff..d513d48a2 100644 --- a/mooringlicensing/components/proposals/models.py +++ b/mooringlicensing/components/proposals/models.py @@ -414,12 +414,17 @@ 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) - return None + else: + # No previous application exists + return None def copy_proof_of_identity_documents(self, proposal): for doc in self.proof_of_identity_documents.all(): diff --git a/mooringlicensing/frontend/mooringlicensing/src/components/common/current_vessels.vue b/mooringlicensing/frontend/mooringlicensing/src/components/common/current_vessels.vue index dfd6e049c..f62b8f958 100755 --- a/mooringlicensing/frontend/mooringlicensing/src/components/common/current_vessels.vue +++ b/mooringlicensing/frontend/mooringlicensing/src/components/common/current_vessels.vue @@ -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:{ @@ -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(); - } }, } diff --git a/mooringlicensing/frontend/mooringlicensing/src/components/form_wla.vue b/mooringlicensing/frontend/mooringlicensing/src/components/form_wla.vue index 798e849a3..f58c06a6d 100755 --- a/mooringlicensing/frontend/mooringlicensing/src/components/form_wla.vue +++ b/mooringlicensing/frontend/mooringlicensing/src/components/form_wla.vue @@ -67,8 +67,12 @@
- +