diff --git a/app/forms/journeys/early_years_payment/practitioner/claim_submission_form.rb b/app/forms/journeys/early_years_payment/practitioner/claim_submission_form.rb index 2c5eb6622d..72cdaf709d 100644 --- a/app/forms/journeys/early_years_payment/practitioner/claim_submission_form.rb +++ b/app/forms/journeys/early_years_payment/practitioner/claim_submission_form.rb @@ -19,11 +19,14 @@ def generate_policy_options_provided end def new_or_find_claim - Claim.find_by(reference: journey_session.answers.reference_number) || Claim.new + (Claim.find_by(reference: journey_session.answers.reference_number) || Claim.new).tap do |c| + if c.eligibility + c.eligibility.practitioner_claim_started_at = journey_session.answers.practitioner_claim_started_at + end + end end def set_submitted_at_attributes - claim.eligibility.practitioner_claim_started_at = journey_session.created_at claim.submitted_at = Time.zone.now end end diff --git a/app/forms/journeys/early_years_payment/practitioner/find_reference_form.rb b/app/forms/journeys/early_years_payment/practitioner/find_reference_form.rb index 02d60c8c4e..19a4667f0d 100644 --- a/app/forms/journeys/early_years_payment/practitioner/find_reference_form.rb +++ b/app/forms/journeys/early_years_payment/practitioner/find_reference_form.rb @@ -19,7 +19,8 @@ def save start_email: email, reference_number_found: existing_claim.present?, claim_already_submitted: existing_claim&.submitted?, - nursery_name: existing_claim&.eligibility&.eligible_ey_provider&.nursery_name + nursery_name: existing_claim&.eligibility&.eligible_ey_provider&.nursery_name, + practitioner_claim_started_at: Time.now ) journey_session.save! end diff --git a/app/models/journeys/early_years_payment/practitioner/session_answers.rb b/app/models/journeys/early_years_payment/practitioner/session_answers.rb index 45963da9de..c5cead1164 100644 --- a/app/models/journeys/early_years_payment/practitioner/session_answers.rb +++ b/app/models/journeys/early_years_payment/practitioner/session_answers.rb @@ -7,6 +7,7 @@ class SessionAnswers < Journeys::SessionAnswers attribute :claim_already_submitted, :boolean, default: nil attribute :nursery_name attribute :start_email, :string + attribute :practitioner_claim_started_at, :datetime def policy Policies::EarlyYearsPayments diff --git a/spec/factories/journeys/early_years_payment/practitioner/answers.rb b/spec/factories/journeys/early_years_payment/practitioner/answers.rb index 44788ac043..f77bb9745f 100644 --- a/spec/factories/journeys/early_years_payment/practitioner/answers.rb +++ b/spec/factories/journeys/early_years_payment/practitioner/answers.rb @@ -12,6 +12,7 @@ banking_name { "John Doe" } bank_sort_code { rand(100000..999999) } bank_account_number { rand(10000000..99999999) } + practitioner_claim_started_at { 30.minutes.ago } end trait :submittable do diff --git a/spec/forms/journeys/early_years_payment/practitioner/find_reference_form_spec.rb b/spec/forms/journeys/early_years_payment/practitioner/find_reference_form_spec.rb index 86d0be3040..4a723a0a58 100644 --- a/spec/forms/journeys/early_years_payment/practitioner/find_reference_form_spec.rb +++ b/spec/forms/journeys/early_years_payment/practitioner/find_reference_form_spec.rb @@ -73,6 +73,12 @@ }.to change { journey_session.reload.answers.nursery_name }.from(nil).to(eligible_ey_provider.nursery_name) end + it "sets practitioner_claim_started_at" do + expect { + subject.save + }.to change { journey_session.reload.answers.practitioner_claim_started_at }.from(nil) + end + context "when the claim has only been submitted by the provider, not the practitioner" do let(:claim) do create(