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:
Luis Ramos
2019-10-16 21:39:30 +01:00
committed by GitHub
7 changed files with 27 additions and 1 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -54,6 +54,10 @@ module OpenFoodNetwork
end
# rubocop:enable Metrics/AbcSize
def line_item_includes
[]
end
private
attr_reader :context

View File

@@ -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

View File

@@ -67,6 +67,10 @@ module OpenFoodNetwork
]
end
# rubocop:enable Metrics/AbcSize
def line_item_includes
[:order, { variant: :product }]
end
end
end
end

View File

@@ -53,6 +53,10 @@ module OpenFoodNetwork
]
end
# rubocop:enable Metrics/MethodLength
def line_item_includes
[{ variant: { product: :supplier } }]
end
end
end
end

View File

@@ -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|