Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(2960) Amend pre-existing report check #2207

Merged
merged 2 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Remove ispf_fund_in_stealth_mode that hides ISPF funds from users
- Add `is_oda` attribute to reports and populate it to `false` for all existing ISPF reports
- Amend report validation to permit two editable reports per fund and organisation, as long as they have different ODA types
- Amend the check for a pre-existing later report to take ODA type into account

## Release 138 - 2023-10-27

Expand Down
2 changes: 1 addition & 1 deletion app/models/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def financial_quarter_is_not_in_the_future?
def no_prexisting_later_report?
return false unless financial_quarter && financial_year

latest_report = organisation.reports.in_historical_order.where(fund_id: fund_id).first
latest_report = organisation.reports.in_historical_order.where(fund_id: fund_id, is_oda: is_oda).first
if latest_report && latest_report.financial_period.last > financial_period.last
errors.add(:financial_period, "A report already exists for a later period.")
end
Expand Down
16 changes: 14 additions & 2 deletions spec/models/report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@
end

context "validates that the financial quarter is previous to the current quarter" do
it "when creating a report for the next finanical quarter in the same financial year" do
it "when creating a report for the next financial quarter in the same financial year" do
travel_to(Date.parse("01-04-2020")) do
new_report = build(:report, financial_quarter: 2, financial_year: 2020)
expect(new_report.valid?(:new)).to be(false)
end
end
it "when creating a report for the next finanical quarter in the next financial year" do
it "when creating a report for the next financial quarter in the next financial year" do
travel_to(Date.parse("01-02-2020")) do
new_report = build(:report, financial_quarter: 1, financial_year: 2020)
expect(new_report.valid?(:new)).to be(false)
Expand All @@ -78,6 +78,7 @@
describe "Ensuring that a new report does not attempt to rewrite history" do
let(:organisation) { create(:partner_organisation) }
let(:fund) { create(:fund_activity) }

context "where a report already exists for a period later than that of the new report" do
it "is not valid" do
create(:report, :approved, organisation: organisation, fund: fund, financial_quarter: 4, financial_year: 2018)
Expand All @@ -86,7 +87,18 @@
expect(new_report.valid?(:new)).to be(false)
end
end

context "and the existing report has a different ODA type than the new report" do
it "is valid" do
create(:report, :for_ispf, :approved, is_oda: false, organisation: organisation, financial_quarter: 4, financial_year: 2018)
travel_to(Date.parse("01-04-2020")) do
new_report = build(:report, :for_ispf, is_oda: true, organisation: organisation, financial_quarter: 3, financial_year: 2018)
expect(new_report.valid?(:new)).to be(true)
end
end
end
end

context "where a report does not exist for a period later than that of the new report" do
it "is valid" do
create(:report, :approved, organisation: organisation, fund: fund, financial_quarter: 4, financial_year: 2018)
Expand Down