Skip to content

Commit

Permalink
fix: Update calculate_last_year method to use most_recent_financial_y…
Browse files Browse the repository at this point in the history
…ear if available

The code changes in `latest_year_generator.rb` modify the `calculate_last_year` method to check if the `form_answer` has a `most_recent_financial_year` value in its document. If it does, the method uses that value as the `@form_answer_award_year`. Otherwise, it falls back to the previous logic of calculating the award year based on the month and day.

This change improves the accuracy of determining the award year and ensures that the most recent financial year is used when available.

Signed-off-by: Louis Kirkham <[email protected]>
  • Loading branch information
TheDancingClown committed Aug 19, 2024
1 parent 9deb671 commit 5270665
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions app/form_pointers/latest_year_generator.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
module LatestYearGenerator
def calculate_last_year(form_answer, day, month)
# Conditional latest year
# If from 7th of September to December -> then previous year
# If from January to 6th of September -> then current year
#

@form_answer_award_year = form_answer.award_year.year if @form_answer_award_year.blank?

if form_answer.financial_year_changeable? || (month.to_i == 9 && day.to_i > 6) || month.to_i > 9
@form_answer_award_year - 2
if form_answer.document["most_recent_financial_year"]
@form_answer_award_year = form_answer.document["most_recent_financial_year"].to_i
else
@form_answer_award_year - 1
# Conditional latest year
# If from 7th of September to December -> then previous year
# If from January to 6th of September -> then current year
#
@form_answer_award_year = form_answer.award_year.year if @form_answer_award_year.blank?

if form_answer.financial_year_changeable? || (month.to_i == 9 && day.to_i > 6) || month.to_i > 9
@form_answer_award_year - 2
else
@form_answer_award_year - 1
end
end
end
end

0 comments on commit 5270665

Please sign in to comment.