Orders and fulfilment report handles order cycles with nil opening or closing times

This commit is contained in:
Rohan Mitchell
2014-06-11 10:33:59 +10:00
committed by Will Marshall
parent 5f8ed01475
commit 908f7871bb
3 changed files with 56 additions and 32 deletions

View File

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

View File

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

View File

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