diff --git a/app/controllers/spree/admin/reports_controller_decorator.rb b/app/controllers/spree/admin/reports_controller_decorator.rb index 0da4a37ace..3904759584 100644 --- a/app/controllers/spree/admin/reports_controller_decorator.rb +++ b/app/controllers/spree/admin/reports_controller_decorator.rb @@ -545,7 +545,9 @@ Spree::Admin::ReportsController.class_eval do @order_cycles = OrderCycle.active_or_complete.accessible_by(spree_current_user).order('orders_close_at DESC') @report_types = REPORT_TYPES[:products_and_inventory] - @report = OpenFoodNetwork::ProductsAndInventoryReport.new params + @report = OpenFoodNetwork::ProductsAndInventoryReport.new spree_current_user, params + @table = @report.table + @header = @report.header end def render_report (header, table, create_csv, csv_file_name) diff --git a/app/views/spree/admin/reports/products_and_inventory.html.haml b/app/views/spree/admin/reports/products_and_inventory.html.haml index 3fdef7127e..57cfaf4b65 100644 --- a/app/views/spree/admin/reports/products_and_inventory.html.haml +++ b/app/views/spree/admin/reports/products_and_inventory.html.haml @@ -1,4 +1,4 @@ -= form_for @search, :url => spree.products_and_inventory_admin_reports_url do |f| += form_tag spree.products_and_inventory_admin_reports_url do |f| %br = label_tag nil, "Distributor: " = select_tag(:distributor_id, diff --git a/spec/controllers/spree/admin/reports_controller_spec.rb b/spec/controllers/spree/admin/reports_controller_spec.rb index 1a03ea386b..3ef8d1760f 100644 --- a/spec/controllers/spree/admin/reports_controller_spec.rb +++ b/spec/controllers/spree/admin/reports_controller_spec.rb @@ -198,10 +198,12 @@ describe Spree::Admin::ReportsController do it "creates a ProductAndInventoryReport" do OpenFoodNetwork::ProductsAndInventoryReport.should_receive(:new) - .with({"test"=>"foo", "controller"=>"spree/admin/reports", "action"=>"products_and_inventory"}) - .and_return({}) + .with(user, {"test"=>"foo", "controller"=>"spree/admin/reports", "action"=>"products_and_inventory"}) + .and_return(report = double(:report)) + report.stub(:table).and_return {} + report.stub(:header).and_return [] spree_get :products_and_inventory, :test => "foo" - assigns(:report).should == {} + assigns(:report).should == report end end end diff --git a/spec/features/admin/reports_spec.rb b/spec/features/admin/reports_spec.rb index 5b6ff84427..f29b09c5a3 100644 --- a/spec/features/admin/reports_spec.rb +++ b/spec/features/admin/reports_spec.rb @@ -73,6 +73,15 @@ feature %q{ describe "products and inventory report" do it "shows products and inventory report" do + product_1 = create(:simple_product, name: "Product Name") + variant_1 = create(:variant, product: product_1, price: 100.0) + variant_2 = create(:variant, product: product_1, price: 80.0) + product_2 = create(:simple_product, name: "Product 2", price: 99.0) + variant_1.update_column(:count_on_hand, 10) + variant_2.update_column(:count_on_hand, 20) + product_2.master.update_column(:count_on_hand, 9) + variant_1.option_values = [create(:option_value, :presentation => "Test")] + login_to_admin_section click_link 'Reports' @@ -80,6 +89,16 @@ feature %q{ page.should have_content "Inventory (on hand)" click_link 'Products & Inventory' page.should have_content "Supplier" + + rows = find("table#listing_products").all("tr") + table = rows.map { |r| r.all("th,td").map { |c| c.text.strip } } + + table.should == [ + ["Supplier", "Product", "SKU", "Variant", "On Hand", "Price"], + [product_1.supplier.name, "Product Name", variant_1.sku, "Size: Test", "10", "100.0"], + [product_1.supplier.name, "Product Name", variant_2.sku, "Size: S", "20", "80.0"], + [product_2.supplier.name, "Product 2", product_2.master.sku, "", "9", "99.0"] + ] end end diff --git a/spec/lib/open_food_network/products_and_inventory_report_spec.rb b/spec/lib/open_food_network/products_and_inventory_report_spec.rb index 19db77cad8..1f98db0604 100644 --- a/spec/lib/open_food_network/products_and_inventory_report_spec.rb +++ b/spec/lib/open_food_network/products_and_inventory_report_spec.rb @@ -132,10 +132,5 @@ module OpenFoodNetwork end end end - - it "should fetch variants" - it "should should fetch products without variants" - - it "should merge variants and products" end end