mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-04 02:31:33 +00:00
Working build of P&I report
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user