Skip to content

Commit

Permalink
Add fund and programme info to export
Browse files Browse the repository at this point in the history
Also, order by RODA ID instead of status.
  • Loading branch information
CristinaRO committed Jan 11, 2024
1 parent 7678928 commit 1f83cff
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions app/services/export/continuing_activities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ def filename
def headers
[
"Partner Organisation name",
"Activity name",
"RODA ID",
"Activity title",
"Activity RODA ID",
"Fund (level A)",
"Parent level B RODA ID",
"Parent level B title",
"Current Transparency identifier",
"Future Transparency identifier",
"Current Previous identifier",
Expand All @@ -23,6 +26,23 @@ def rows
partner_organisation_name = activity.organisation.name
activity_title = activity.title
roda_identifier = activity.roda_identifier
fund = activity.associated_fund.roda_identifier
parent_level_b_roda_id = case activity.level
when "programme"
""
when "project"
activity.parent.roda_identifier
else
activity.parent.parent.roda_identifier
end
parent_level_b_title = case activity.level
when "programme"
""
when "project"
activity.parent.title
else
activity.parent.parent.title
end
current_transparency_identifier = activity.transparency_identifier
future_transparency_identifier = current_transparency_identifier&.sub(/\AGB-GOV-13/, "GB-GOV-26")
current_previous_identifier = activity.previous_identifier
Expand All @@ -35,6 +55,9 @@ def rows
partner_organisation_name,
activity_title,
roda_identifier,
fund,
parent_level_b_roda_id,
parent_level_b_title,
current_transparency_identifier,
future_transparency_identifier,
current_previous_identifier,
Expand All @@ -50,32 +73,32 @@ def activities
# active statuses, regardless of any associated actual spend
definitely_active = Activity
.joins(:organisation)
.includes(:organisation)
.includes(:organisation, :parent)
.where.not(level: "fund")
.where(is_oda: [nil, true])
.where.not(programme_status: ["completed", "stopped", "cancelled", "finalisation", "paused"])
.order("organisations.name, programme_status")
.order("organisations.name, activities.roda_identifier")

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)
.includes(:organisation, :parent)
.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")
.order("organisations.name, activities.roda_identifier")

# 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)
.includes(:organisation, :parent)
.where.not(level: "fund")
.where(is_oda: [nil, true])
.where(programme_status: "paused")
.order("organisations.name, programme_status")
.order("organisations.name, activities.roda_identifier")
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
Expand Down

0 comments on commit 1f83cff

Please sign in to comment.