From 908f7871bbe114ac20eecbeb672efa87a5614eaa Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 11 Jun 2014 10:33:59 +1000 Subject: [PATCH] Orders and fulfilment report handles order cycles with nil opening or closing times --- app/helpers/spree/reports_helper.rb | 11 +++ .../reports/orders_and_fulfillment.html.haml | 3 +- spec/features/admin/reports_spec.rb | 74 +++++++++++-------- 3 files changed, 56 insertions(+), 32 deletions(-) create mode 100644 app/helpers/spree/reports_helper.rb diff --git a/app/helpers/spree/reports_helper.rb b/app/helpers/spree/reports_helper.rb new file mode 100644 index 0000000000..573b790051 --- /dev/null +++ b/app/helpers/spree/reports_helper.rb @@ -0,0 +1,11 @@ +module Spree + module ReportsHelper + def report_order_cycle_options(order_cycles) + order_cycles.map do |oc| + orders_open_at = oc.orders_open_at.andand.to_s(:short) || 'NA' + orders_close_at = oc.orders_close_at.andand.to_s(:short) || 'NA' + [ "#{oc.name}   (#{orders_open_at} - #{orders_close_at})".html_safe, oc.id ] + end + end + end +end diff --git a/app/views/spree/admin/reports/orders_and_fulfillment.html.haml b/app/views/spree/admin/reports/orders_and_fulfillment.html.haml index 0935c24cc7..522fdfdf39 100644 --- a/app/views/spree/admin/reports/orders_and_fulfillment.html.haml +++ b/app/views/spree/admin/reports/orders_and_fulfillment.html.haml @@ -20,8 +20,7 @@ .row .alpha.two.columns= label_tag nil, "Order Cycles: " .omega.fourteen.columns - - order_cycles_select = @order_cycles.collect {|oc| [ "#{oc.name}   (#{oc.orders_open_at.to_s(:short)} - #{oc.orders_close_at.to_s(:short)})".html_safe, oc.id ] } - = f.select(:order_cycle_id_in, order_cycles_select, {selected: params[:q][:order_cycle_id_in]}, {class: "select2 fullwidth", multiple: true}) + = f.select(:order_cycle_id_in, report_order_cycle_options(@order_cycles), {selected: params[:q][:order_cycle_id_in]}, {class: "select2 fullwidth", multiple: true}) .row .alpha.two.columns= label_tag nil, "Report Type: " diff --git a/spec/features/admin/reports_spec.rb b/spec/features/admin/reports_spec.rb index 51c9f83e07..e880f25d23 100644 --- a/spec/features/admin/reports_spec.rb +++ b/spec/features/admin/reports_spec.rb @@ -81,43 +81,57 @@ feature %q{ page.should have_content 'Payment State' end - scenario "orders & fulfillment reports" do - login_to_admin_section - click_link 'Reports' - click_link 'Orders & Fulfillment Reports' + describe "orders & fulfilment reports" do + it "loads the report page" do + login_to_admin_section + click_link 'Reports' + click_link 'Orders & Fulfillment Reports' - page.should have_content 'Supplier' - end + page.should have_content 'Supplier' + end - scenario "orders & fulfillment reports are precise to time of day, not just date" do - # Given two orders on the same day at different times - @bill_address = create(:address) - @distributor_address = create(:address, :address1 => "distributor address", :city => 'The Shire', :zipcode => "1234") - @distributor = create(:distributor_enterprise, :address => @distributor_address) - product = create(:product) - product_distribution = create(:product_distribution, :product => product, :distributor => @distributor) - @shipping_instructions = "pick up on thursday please!" - @order1 = create(:order, :distributor => @distributor, :bill_address => @bill_address, :special_instructions => @shipping_instructions) - @order2 = create(:order, :distributor => @distributor, :bill_address => @bill_address, :special_instructions => @shipping_instructions) + context "with two orders on the same day at different times" do + let(:bill_address) { create(:address) } + let(:distributor_address) { create(:address, :address1 => "distributor address", :city => 'The Shire', :zipcode => "1234") } + let(:distributor) { create(:distributor_enterprise, :address => distributor_address) } + let(:product) { create(:product) } + let(:product_distribution) { create(:product_distribution, :product => product, :distributor => distributor) } + let(:shipping_instructions) { "pick up on thursday please!" } + let(:order1) { create(:order, :distributor => distributor, :bill_address => bill_address, :special_instructions => shipping_instructions) } + let(:order2) { create(:order, :distributor => distributor, :bill_address => bill_address, :special_instructions => shipping_instructions) } + + before do + Timecop.travel(Time.zone.local(2013, 4, 25, 14, 0, 0)) { order1.finalize! } + Timecop.travel(Time.zone.local(2013, 4, 25, 16, 0, 0)) { order2.finalize! } - Timecop.travel(Time.zone.local(2013, 4, 25, 14, 0, 0)) { @order1.finalize! } - Timecop.travel(Time.zone.local(2013, 4, 25, 16, 0, 0)) { @order2.finalize! } + create(:line_item, :product => product, :order => order1) + create(:line_item, :product => product, :order => order2) + end - create(:line_item, :product => product, :order => @order1) - create(:line_item, :product => product, :order => @order2) + it "is precise to time of day, not just date" do + # When I generate a customer report with a timeframe that includes one order but not the other + login_to_admin_section + visit spree.orders_and_fulfillment_admin_reports_path - # When I generate a customer report with a timeframe that includes one order but not the other - login_to_admin_section - click_link 'Reports' - click_link 'Orders & Fulfillment Reports' + fill_in 'q_completed_at_gt', with: '2013-04-25 13:00:00' + fill_in 'q_completed_at_lt', with: '2013-04-25 15:00:00' + select 'Order Cycle Customer Totals', from: 'report_type' + click_button 'Search' - fill_in 'q_completed_at_gt', with: '2013-04-25 13:00:00' - fill_in 'q_completed_at_lt', with: '2013-04-25 15:00:00' - select 'Order Cycle Customer Totals', from: 'report_type' - click_button 'Search' + # Then I should see the rows for the first order but not the second + all('table#listing_orders tbody tr').count.should == 2 # Two rows per order + end + end - # Then I should see the rows for the first order but not the second - all('table#listing_orders tbody tr').count.should == 2 # Two rows per order + it "handles order cycles with nil opening or closing times" do + oc = create(:simple_order_cycle, name: "My Order Cycle", orders_open_at: Time.now, orders_close_at: nil) + o = create(:order, order_cycle: oc) + + login_to_admin_section + visit spree.orders_and_fulfillment_admin_reports_path + + page.should have_content "My Order Cycle" + end end describe "products and inventory report" do