generated from dxw/rails-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Export a CSV of all continuing activities
The first step in updating activities with the new transparency identifier: producing a list of activities that fulfill the conditions to continue, from the old GB-GOV-13 identifier corresponding to BEIS, to the new GB-GOV-26 identifier corresponding to DSIT. The list will need to be signed off by DSIT. Usually we would have implemented this as a rake task to be run in the server console, but we no longer have this level of access. This ad-hoc export is temporary, and will be removed after all the relevant activities are switched to the new identifier.
- Loading branch information
1 parent
e5c6356
commit 5ed9d0a
Showing
6 changed files
with
228 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
class Export::ContinuingActivities | ||
def filename | ||
"continuing_activities.csv" | ||
end | ||
|
||
def headers | ||
[ | ||
"Partner Organisation name", | ||
"Activity name", | ||
"RODA ID", | ||
"Transparency identifier", | ||
"Partner Organisation ID", | ||
"Status", | ||
"Level" | ||
] | ||
end | ||
|
||
def rows | ||
activities.map do |activity| | ||
partner_organisation_name = activity.organisation.name | ||
activity_title = activity.title | ||
roda_identifier = activity.roda_identifier | ||
transparency_identifier = activity.transparency_identifier | ||
partner_organisation_identifier = activity.partner_organisation_identifier | ||
status = I18n.t("activity.programme_status.#{activity.programme_status}") | ||
level = I18n.t("table.body.activity.level.#{activity.level}") | ||
|
||
[partner_organisation_name, activity_title, roda_identifier, transparency_identifier, partner_organisation_identifier, status, level] | ||
end | ||
end | ||
|
||
def activities | ||
# active statuses, regardless of any associated actual spend | ||
definitely_active = Activity | ||
.joins(:organisation) | ||
.includes(:organisation) | ||
.where.not(level: "fund") | ||
.where(is_oda: [nil, true]) | ||
.where.not(programme_status: ["completed", "stopped", "cancelled", "finalisation", "paused"]) | ||
.order("organisations.name, programme_status") | ||
|
||
cut_off_quarter = FinancialQuarter.new(2022, 4) | ||
|
||
# activities that MAY need to continue, IF they have actual spend more recent than FQ4 2022-2023 | ||
potentially_active_due_to_actuals = Activity | ||
.joins(:organisation, :actuals) | ||
.includes(:organisation) | ||
.where.not(level: "fund") | ||
.where(is_oda: [nil, true]) | ||
.where(programme_status: ["completed", "stopped", "cancelled", "finalisation", "paused"]) | ||
.where("transactions.date > ?", cut_off_quarter.end_date) | ||
.order("organisations.name, programme_status") | ||
|
||
# activities that MAY need to continue, IF they have forecasts for quarters after FQ4 2022-2023 | ||
potentially_active_due_to_forecasts = Activity | ||
.joins(:organisation) | ||
.includes(:organisation) | ||
.where.not(level: "fund") | ||
.where(is_oda: [nil, true]) | ||
.where(programme_status: "paused") | ||
.order("organisations.name, programme_status") | ||
potentially_active_due_to_forecasts = potentially_active_due_to_forecasts.select do |activity| | ||
Forecast.unscoped.where(parent_activity_id: activity.id).where("period_start_date > ?", cut_off_quarter.end_date).any? | ||
end | ||
|
||
(definitely_active + potentially_active_due_to_actuals + potentially_active_due_to_forecasts).uniq | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
RSpec.describe Export::ContinuingActivities do | ||
let(:export) { Export::ContinuingActivities.new } | ||
|
||
describe "#activities" do | ||
context "a completed activity" do | ||
let!(:project) { create(:project_activity, programme_status: "completed") } | ||
|
||
context "without actual spend" do | ||
it "is not included" do | ||
expect(export.activities).to_not include(project) | ||
end | ||
end | ||
|
||
context "with actual spend before or including in FQ4 2022-2023" do | ||
before { create(:actual, parent_activity: project, date: FinancialQuarter.new(2022, 4).end_date) } | ||
|
||
it "is not included" do | ||
expect(export.activities).to_not include(project) | ||
end | ||
end | ||
|
||
context "with actual spend after FQ4 2022-2023" do | ||
before { create(:actual, parent_activity: project, date: FinancialQuarter.new(2023, 1).start_date) } | ||
|
||
it "is included" do | ||
expect(export.activities).to include(project) | ||
end | ||
end | ||
end | ||
|
||
context "a spend_in_progress activity" do | ||
let!(:project) { create(:project_activity, programme_status: "spend_in_progress") } | ||
|
||
context "without actual spend" do | ||
it "is included" do | ||
expect(export.activities).to include(project) | ||
end | ||
end | ||
|
||
context "with actual spend before or including in FQ4 2022-2023" do | ||
before { create(:actual, parent_activity: project, date: FinancialQuarter.new(2022, 4).end_date) } | ||
|
||
it "is included" do | ||
expect(export.activities).to include(project) | ||
end | ||
end | ||
|
||
context "with actual spend after FQ4 2022-2023" do | ||
before { create(:actual, parent_activity: project, date: FinancialQuarter.new(2023, 1).start_date) } | ||
|
||
it "is included" do | ||
expect(export.activities).to include(project) | ||
end | ||
end | ||
|
||
context "for ISPF non-ODA" do | ||
before { project.update(is_oda: false) } | ||
|
||
it "is not included" do | ||
expect(export.activities).to_not include(project) | ||
end | ||
end | ||
end | ||
|
||
context "a paused activity" do | ||
let!(:project) { create(:project_activity, programme_status: "paused") } | ||
|
||
context "with neither actual spend nor forecasts" do | ||
it "is not included" do | ||
expect(export.activities).to_not include(project) | ||
end | ||
end | ||
|
||
context "with actual spend before or including in FQ4 2022-2023 and no forecasts" do | ||
before { create(:actual, parent_activity: project, date: FinancialQuarter.new(2022, 4).end_date) } | ||
|
||
it "is not included" do | ||
expect(export.activities).to_not include(project) | ||
end | ||
end | ||
|
||
context "with actual spend after FQ4 2022-2023 and no forecasts" do | ||
before { create(:actual, parent_activity: project, date: FinancialQuarter.new(2023, 1).start_date) } | ||
|
||
it "is included" do | ||
expect(export.activities).to include(project) | ||
end | ||
end | ||
|
||
context "with forecasts before or including in FQ4 2022-2023 and no actual spend" do | ||
before do | ||
ReportingCycle.new(project, 2, 2022).tick | ||
# initialising a reporting cycle like that and "tick"ing over the report cycle | ||
# gives us a report for FQ3 2022-2023, in which we can report a forecast for FQ4 2022-2023 | ||
forecast_history = ForecastHistory.new(project, financial_quarter: 4, financial_year: 2022) | ||
forecast_history.set_value(1000) | ||
end | ||
|
||
it "is not included" do | ||
expect(export.activities).to_not include(project) | ||
end | ||
end | ||
|
||
context "with forecasts after FQ4 2022-2023 and no actual spend" do | ||
before do | ||
ReportingCycle.new(project, 3, 2022).tick | ||
# initialising a reporting cycle like that and "tick"ing over the report cycle | ||
# gives us a report for FQ4 2022-2023, in which we can report a forecast for FQ1 2023-2024 | ||
forecast_history = ForecastHistory.new(project, financial_quarter: 1, financial_year: 2023) | ||
forecast_history.set_value(1000) | ||
end | ||
|
||
it "is included" do | ||
expect(export.activities).to include(project) | ||
end | ||
end | ||
end | ||
end | ||
end |