Skip to content

Commit

Permalink
Merge pull request #5429 from mkllnk/5400-orders-distributors-report
Browse files Browse the repository at this point in the history
5400 List each order only once in Orders And Distributors report
  • Loading branch information
luisramos0 authored May 20, 2020
2 parents 76b721b + 2d95e9e commit e287680
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
1 change: 0 additions & 1 deletion .rubocop_manual_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ Layout/LineLength:
- spec/lib/open_food_network/group_buy_report_spec.rb
- spec/lib/open_food_network/lettuce_share_report_spec.rb
- spec/lib/open_food_network/option_value_namer_spec.rb
- spec/lib/open_food_network/order_and_distributor_report_spec.rb
- spec/lib/open_food_network/order_cycle_form_applicator_spec.rb
- spec/lib/open_food_network/order_cycle_permissions_spec.rb
- spec/lib/open_food_network/order_grouper_spec.rb
Expand Down
4 changes: 3 additions & 1 deletion lib/open_food_network/order_and_distributor_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ def header
end

def search
@permissions.visible_orders.complete.not_state(:canceled).search(@params[:q])
@permissions.visible_orders.select("DISTINCT spree_orders.*").
complete.not_state(:canceled).
search(@params[:q])
end

def table
Expand Down
32 changes: 26 additions & 6 deletions spec/lib/open_food_network/order_and_distributor_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ module OpenFoodNetwork
subject = OrderAndDistributorReport.new nil

header = subject.header
expect(header).to eq(['Order date', 'Order Id',
'Customer Name', 'Customer Email', 'Customer Phone', 'Customer City',
'SKU', 'Item name', 'Variant', 'Quantity', 'Max Quantity', 'Cost', 'Shipping Cost',
'Payment Method',
'Distributor', 'Distributor address', 'Distributor city', 'Distributor postcode', 'Shipping Method', 'Shipping instructions'])
expect(header).to eq(
[
'Order date', 'Order Id',
'Customer Name', 'Customer Email', 'Customer Phone', 'Customer City',
'SKU', 'Item name', 'Variant', 'Quantity', 'Max Quantity', 'Cost', 'Shipping Cost',
'Payment Method',
'Distributor', 'Distributor address', 'Distributor city', 'Distributor postcode',
'Shipping Method', 'Shipping instructions'
]
)
end

context 'with completed order' do
Expand All @@ -21,7 +26,12 @@ module OpenFoodNetwork
let(:product) { create(:product) }
let(:shipping_method) { create(:shipping_method) }
let(:shipping_instructions) { 'pick up on thursday please!' }
let(:order) { create(:order, state: 'complete', completed_at: Time.zone.now, distributor: distributor, bill_address: bill_address, special_instructions: shipping_instructions) }
let(:order) {
create(:order,
state: 'complete', completed_at: Time.zone.now,
distributor: distributor, bill_address: bill_address,
special_instructions: shipping_instructions)
}
let(:payment_method) { create(:payment_method, distributors: [distributor]) }
let(:payment) { create(:payment, payment_method: payment_method, order: order) }
let(:line_item) { create(:line_item_with_shipment, product: product, order: order) }
Expand All @@ -37,6 +47,7 @@ module OpenFoodNetwork

table = subject.table

expect(table.size).to eq 1
expect(table[0]).to eq([
order.reload.completed_at.strftime("%F %T"),
order.id,
Expand All @@ -60,6 +71,15 @@ module OpenFoodNetwork
shipping_instructions
])
end

it "prints one row per line item" do
create(:line_item_with_shipment, order: order)

subject = OrderAndDistributorReport.new(create(:admin_user), {}, true)

table = subject.table
expect(table.size).to eq 2
end
end
end
end
Expand Down

0 comments on commit e287680

Please sign in to comment.