Skip to content
Merged
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
7 changes: 6 additions & 1 deletion app/services/exports/export_distributions_csv_service.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Don't technically need to pull in csv for the code itself,
# but this ensures that the unit test can run in isolation
require 'csv'

module Exports
class ExportDistributionsCSVService
include DistributionHelper
Expand Down Expand Up @@ -135,7 +139,8 @@ def build_row_data(distribution)
row = base_table.values.map { |closure| closure.call(distribution) }

item_names.each do |item_name|
line_items = distribution.line_items.where(item: @organization.items.find_by(name: item_name))
# We are doing this in-memory so that we can use the already-loaded line item records
line_items = distribution.line_items.select { |item| item.name == item_name }

row << line_items.sum(&:quantity)
row << Money.new(line_items.sum(&:value_per_line_item)) if @organization.include_in_kind_values_in_exported_files
Expand Down