mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-28 21:07:16 +00:00
Eager-load option_values in various reports
This commit is contained in:
@@ -51,8 +51,7 @@ module OpenFoodNetwork
|
||||
|
||||
def table_items
|
||||
return [] unless @render_table
|
||||
|
||||
Reports::LineItems.list(permissions, params)
|
||||
Reports::LineItems.list(permissions, report_options)
|
||||
end
|
||||
|
||||
def rules
|
||||
@@ -122,9 +121,17 @@ module OpenFoodNetwork
|
||||
|
||||
private
|
||||
|
||||
def report_options
|
||||
@params.merge(line_item_includes: line_item_includes)
|
||||
end
|
||||
|
||||
def line_item_includes
|
||||
[{ order: [:bill_address],
|
||||
variant: [{ option_values: :option_type }, { product: :supplier }] }]
|
||||
end
|
||||
|
||||
def permissions
|
||||
return @permissions unless @permissions.nil?
|
||||
|
||||
@permissions = OpenFoodNetwork::Permissions.new(@user)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -190,7 +190,7 @@ module OpenFoodNetwork
|
||||
# rubocop:enable Metrics/PerceivedComplexity
|
||||
|
||||
def line_item_includes
|
||||
[{ variant: { product: :supplier },
|
||||
[{ variant: [{ option_values: :option_type }, { product: :supplier }],
|
||||
order: [:bill_address, :ship_address, :order_cycle, :adjustments, :payments,
|
||||
:user, :distributor, shipments: { shipping_rates: :shipping_method }] }]
|
||||
end
|
||||
|
||||
@@ -69,7 +69,7 @@ module OpenFoodNetwork
|
||||
|
||||
def line_item_includes
|
||||
[{ order: [:distributor, :adjustments, shipments: { shipping_rates: :shipping_method }],
|
||||
variant: { product: :supplier } }]
|
||||
variant: [{ option_values: :option_type }, { product: :supplier }] }]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -69,7 +69,8 @@ module OpenFoodNetwork
|
||||
# rubocop:enable Metrics/AbcSize
|
||||
|
||||
def line_item_includes
|
||||
[{ order: :distributor, variant: { product: :supplier } }]
|
||||
[{ order: :distributor,
|
||||
variant: [{ option_values: :option_type }, { product: :supplier }] }]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -55,7 +55,7 @@ module OpenFoodNetwork
|
||||
# rubocop:enable Metrics/MethodLength
|
||||
|
||||
def line_item_includes
|
||||
[{ variant: { product: :supplier } }]
|
||||
[{ variant: [{ option_values: :option_type }, { product: :supplier }] }]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -43,8 +43,7 @@ module OpenFoodNetwork
|
||||
|
||||
def table_items
|
||||
return [] unless @render_table
|
||||
|
||||
Reports::LineItems.list(permissions, params)
|
||||
Reports::LineItems.list(permissions, report_options)
|
||||
end
|
||||
|
||||
def rules
|
||||
@@ -121,9 +120,17 @@ module OpenFoodNetwork
|
||||
|
||||
private
|
||||
|
||||
def report_options
|
||||
@params.merge(line_item_includes: line_item_includes)
|
||||
end
|
||||
|
||||
def line_item_includes
|
||||
[{ order: [:bill_address, :distributor],
|
||||
variant: [{ option_values: :option_type }, { product: :supplier }] }]
|
||||
end
|
||||
|
||||
def permissions
|
||||
return @permissions unless @permissions.nil?
|
||||
|
||||
@permissions = OpenFoodNetwork::Permissions.new(@user)
|
||||
end
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ module OpenFoodNetwork
|
||||
def child_variants
|
||||
Spree::Variant.
|
||||
where(is_master: false).
|
||||
includes(option_values: :option_type).
|
||||
joins(:product).
|
||||
merge(visible_products).
|
||||
order('spree_products.name')
|
||||
|
||||
@@ -43,6 +43,15 @@ module OpenFoodNetwork
|
||||
|
||||
private
|
||||
|
||||
def report_options
|
||||
@opts.merge(line_item_includes: line_item_includes)
|
||||
end
|
||||
|
||||
def line_item_includes
|
||||
[:bill_address, :adjustments,
|
||||
line_items: { variant: [{ option_values: :option_type }, { product: :supplier }] }]
|
||||
end
|
||||
|
||||
def detail_rows_for_order(order, invoice_number, opts)
|
||||
rows = []
|
||||
|
||||
|
||||
Reference in New Issue
Block a user