Adding the plumbing for Customers reports, and one tiny refactor to products

This commit is contained in:
Will Marshall
2013-11-22 14:54:50 +11:00
parent 5e170a843e
commit b3bf3a8378
5 changed files with 74 additions and 8 deletions

View File

@@ -3,13 +3,14 @@ require 'open_food_network/order_and_distributor_report'
require 'open_food_network/products_and_inventory_report'
require 'open_food_network/group_buy_report'
require 'open_food_network/order_grouper'
require 'open_food_network/customers_report'
require 'open_food_network/model_class_from_controller_name'
Spree::Admin::ReportsController.class_eval do
include OpenFoodNetwork::ModelClassFromControllerName
# Fetches user's distributors, suppliers and order_cycles
before_filter :load_data, only: :products_and_inventory
before_filter :load_data, only: [:customers, :products_and_inventory]
# Render a partial for orders and fulfillment description
respond_override :index => { :html => { :success => lambda {
@@ -35,9 +36,19 @@ Spree::Admin::ReportsController.class_eval do
products_and_inventory: [
['All products', :all_products],
['Inventory (on hand)', :inventory]
],
customers: [
["Mailing List", :mailing_list],
["Addresses", :addresses]
]
}
def customers
@search = Spree::Order.search
@report_types = REPORT_TYPES[:customers]
@report = OpenFoodNetwork::CustomersReport.new spree_current_user, params
end
def orders_and_distributors
params[:q] = {} unless params[:q]
@@ -541,8 +552,8 @@ Spree::Admin::ReportsController.class_eval do
@report_types = REPORT_TYPES[:products_and_inventory]
@report = OpenFoodNetwork::ProductsAndInventoryReport.new spree_current_user, params
@table = @report.table
@header = @report.header
#@table = @report.table
#@header = @report.header
end
def render_report (header, table, create_csv, csv_file_name)
@@ -575,6 +586,7 @@ Spree::Admin::ReportsController.class_eval do
:bulk_coop => {:name => "Bulk Co-Op", :description => "Reports for Bulk Co-Op orders"},
:payments => {:name => "Payment Reports", :description => "Reports for Payments"},
:orders_and_fulfillment => {:name => "Orders & Fulfillment Reports", :description => ''},
:customers => {:name => "Customers", :description => 'Customer details'},
:products_and_inventory => {:name => "Products & Inventory", :description => ''}
}
if spree_current_user.has_spree_role? 'admin'

View File

@@ -0,0 +1,8 @@
= form_for @search, :url => spree.customers_admin_reports_path do |s|
%br
= button t(:search)
%br
%br
%table#listing_customers.index

View File

@@ -33,13 +33,13 @@
%table#listing_products.index
%thead
%tr{'data-hook' => "products_header"}
- @header.each do |heading|
- @report.header.each do |heading|
%th=heading
%tbody
- @table.each do |row|
- @report.table.each do |row|
%tr
- row.each do |column|
%td= column
- if @table.empty?
- if @report.table.empty?
%tr
%td{:colspan => "2"}= t(:none)

View File

@@ -58,6 +58,7 @@ Spree::Core::Engine.routes.prepend do
match '/admin/reports/orders_and_fulfillment' => 'admin/reports#orders_and_fulfillment', :as => "orders_and_fulfillment_admin_reports", :via => [:get, :post]
match '/admin/products/bulk_edit' => 'admin/products#bulk_edit', :as => "bulk_edit_admin_products"
match '/admin/reports/products_and_inventory' => 'admin/reports#products_and_inventory', :as => "products_and_inventory_admin_reports", :via => [:get, :post]
match '/admin/reports/customers' => 'admin/reports#customers', :as => "customers_admin_reports", :via => [:get, :post]
namespace :api, :defaults => { :format => 'json' } do

View File

@@ -190,10 +190,55 @@ describe Spree::Admin::ReportsController do
OpenFoodNetwork::ProductsAndInventoryReport.should_receive(:new)
.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 == report
end
end
context "My Customers" do
let(:user) do
user = create(:user)
user.spree_roles << Spree::Role.find_or_create_by_name!('admin')
user
end
before do
controller.stub spree_current_user: user
end
it "should have report types for customers" do
Spree::Admin::ReportsController::REPORT_TYPES[:customers].should == [
["Mailing List", :mailing_list],
["Addresses", :addresses]
]
end
it "should build distributors for the current user" do
spree_get :customers
assigns(:distributors).should == [d1, d2, d3]
end
it "builds suppliers for the current user" do
spree_get :customers
assigns(:suppliers).should == [s1, s2, s3]
end
it "builds order cycles for the current user" do
spree_get :customers
assigns(:order_cycles).should == [ocB, ocA]
end
it "assigns report types" do
spree_get :customers
assigns(:report_types).should == Spree::Admin::ReportsController::REPORT_TYPES[:customers]
end
it "creates a CustomersReport" do
OpenFoodNetwork::CustomersReport.should_receive(:new)
.with(user, {"test"=>"foo", "controller"=>"spree/admin/reports", "action"=>"customers"})
.and_return(report = double(:report))
spree_get :customers, :test => "foo"
assigns(:report).should == report
end
end
end