mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Merge pull request #4365 from kristinalim/fix/4308-eager_load_associations_in_orders_and_fulfillment_reports
4308 Eager-load associations in Orders and Fulfillment reports
This commit is contained in:
@@ -26,7 +26,9 @@ module OpenFoodNetwork
|
||||
|
||||
def table_items
|
||||
return [] unless @render_table
|
||||
Reports::LineItems.list(permissions, options)
|
||||
|
||||
list_options = options.merge(line_item_includes: report.line_item_includes)
|
||||
Reports::LineItems.list(permissions, list_options)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -188,6 +188,10 @@ module OpenFoodNetwork
|
||||
# rubocop:enable Metrics/CyclomaticComplexity
|
||||
# rubocop:enable Metrics/MethodLength
|
||||
# rubocop:enable Metrics/PerceivedComplexity
|
||||
|
||||
def line_item_includes
|
||||
[{ variant: :product, order: [:bill_address, :shipments] }]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -54,6 +54,10 @@ module OpenFoodNetwork
|
||||
end
|
||||
# rubocop:enable Metrics/AbcSize
|
||||
|
||||
def line_item_includes
|
||||
[]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
attr_reader :context
|
||||
|
||||
@@ -66,6 +66,10 @@ module OpenFoodNetwork
|
||||
proc { |_line_items| I18n.t(:report_header_shipping_method) }]
|
||||
end
|
||||
# rubocop:enable Metrics/AbcSize
|
||||
|
||||
def line_item_includes
|
||||
[:order, { variant: :product }]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -67,6 +67,10 @@ module OpenFoodNetwork
|
||||
]
|
||||
end
|
||||
# rubocop:enable Metrics/AbcSize
|
||||
|
||||
def line_item_includes
|
||||
[:order, { variant: :product }]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -53,6 +53,10 @@ module OpenFoodNetwork
|
||||
]
|
||||
end
|
||||
# rubocop:enable Metrics/MethodLength
|
||||
|
||||
def line_item_includes
|
||||
[{ variant: { product: :supplier } }]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -12,6 +12,10 @@ module OpenFoodNetwork
|
||||
line_items = permissions.visible_line_items.merge(Spree::LineItem.where(order_id: orders))
|
||||
line_items = line_items.supplied_by_any(params[:supplier_id_in]) if params[:supplier_id_in].present?
|
||||
|
||||
if params[:line_item_includes].present?
|
||||
line_items = line_items.includes(*params[:line_item_includes])
|
||||
end
|
||||
|
||||
hidden_line_items = line_items_with_hidden_details(permissions, line_items)
|
||||
|
||||
line_items.select{ |li|
|
||||
|
||||
Reference in New Issue
Block a user