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

Reduce distribution value totals by item category filter on distribution index page #4924

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Make export csv service functionality match web view
coalest committed Jan 15, 2025
commit 0c6c440da5a14acf8bf4ecc9bb869f85535d0e06
15 changes: 14 additions & 1 deletion app/services/exports/export_distributions_csv_service.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module Exports
class ExportDistributionsCSVService
include DistributionHelper
include ItemsHelper

def initialize(distributions:, organization:, filters: [])
# Currently, the @distributions are already loaded by the controllers that are delegating exporting
# to this service object; this is happening within the same request/response cycle, so it's already
@@ -82,7 +84,18 @@ def base_table
end
},
"Total Value" => ->(distribution) {
distribution.cents_to_dollar(distribution.line_items.total_value)
# filter the items by item category id (for selected item category filter) to
# get the number of items
value_in_cents = if @filters[:by_item_category_id].present?
distribution
.line_items
.left_joins(:item)
.where(item: {item_category_id: @filters[:by_item_category_id].to_i})
.total_value
else
distribution.line_items.total_value
end
cents_to_dollar(value_in_cents)
},
"Delivery Method" => ->(distribution) {
distribution.delivery_method