diff --git a/app/services/variant_overrides_indexed.rb b/app/services/variant_overrides_indexed.rb index 1264f0bddd..587699a519 100644 --- a/app/services/variant_overrides_indexed.rb +++ b/app/services/variant_overrides_indexed.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true class VariantOverridesIndexed - def initialize(line_items:, distributor_ids:) - @line_items = line_items + def initialize(variant_ids, distributor_ids) + @variant_ids = variant_ids @distributor_ids = distributor_ids end @@ -14,7 +14,7 @@ class VariantOverridesIndexed private - attr_reader :line_items, :distributor_ids + attr_reader :variant_ids, :distributor_ids def variant_overrides VariantOverride @@ -22,7 +22,7 @@ class VariantOverridesIndexed .preload(:variant) .where( hub_id: distributor_ids, - variant_id: line_items.select(:variant_id) + variant_id: variant_ids, ) end diff --git a/lib/open_food_network/orders_and_fulfillments_report.rb b/lib/open_food_network/orders_and_fulfillments_report.rb index db039b515d..ae359aba19 100644 --- a/lib/open_food_network/orders_and_fulfillments_report.rb +++ b/lib/open_food_network/orders_and_fulfillments_report.rb @@ -102,8 +102,8 @@ module OpenFoodNetwork def report_variant_overrides @report_variant_overrides ||= VariantOverridesIndexed.new( - line_items: order_permissions.visible_line_items, - distributor_ids: report_line_items.orders.result.select('DISTINCT distributor_id'), + order_permissions.visible_line_items.select('DISTINCT variant_id'), + report_line_items.orders.result.select('DISTINCT distributor_id'), ).indexed end end diff --git a/spec/services/variant_overrides_indexed_spec.rb b/spec/services/variant_overrides_indexed_spec.rb index fab68a0957..15af405683 100644 --- a/spec/services/variant_overrides_indexed_spec.rb +++ b/spec/services/variant_overrides_indexed_spec.rb @@ -1,19 +1,10 @@ require 'spec_helper' describe VariantOverridesIndexed do - subject(:variant_overrides) do - described_class.new( - line_items: order.line_items, - distributor_ids: [distributor.id], - ) - end + subject(:variant_overrides) { described_class.new([variant.id],[distributor.id]) } let(:distributor) { create(:distributor_enterprise) } - let(:order) do - create(:completed_order_with_totals, line_items_count: 1, - distributor: distributor) - end - let(:line_item) { order.line_items.first } + let(:variant) { create(:variant) } let!(:variant_override) do create( :variant_override, @@ -25,15 +16,15 @@ describe VariantOverridesIndexed do describe '#indexed' do let(:result) { variant_overrides.indexed } - context 'when variant overrides exist for variants of specified line items' do - let(:vo_variant) { line_item.variant } + context 'when variant overrides exist for variants of specified variants' do + let(:vo_variant) { variant } context 'when variant overrides apply to one of the specified distributors' do let(:vo_distributor) { distributor } it 'they are included in the mapping' do expect(result).to eq( - distributor.id => { line_item.variant => variant_override } + distributor.id => { variant => variant_override } ) end end