Boilerplate for the new Product and Inventory report, sans any functionality

This commit is contained in:
Will Marshall
2013-11-20 10:34:18 +11:00
parent 306eaab262
commit 5772fa9589
5 changed files with 26 additions and 79 deletions

View File

@@ -11,13 +11,16 @@ Spree::Admin::ReportsController.class_eval do
respond_override :index => { :html => { :success => lambda {
@reports[:orders_and_fulfillment][:description] =
render_to_string(partial: 'orders_and_fulfillment_description', layout: false, locals: {report_types: REPORT_TYPES[:orders_and_fulfillment]}).html_safe
@reports[:products_and_inventory][:description] =
render_to_string(partial: 'products_and_inventory_description', layout: false, locals: {report_types: REPORT_TYPES[:products_and_inventory]}).html_safe
} } }
Spree::Admin::ReportsController::AVAILABLE_REPORTS.merge!({:orders_and_distributors => {:name => "Orders And Distributors", :description => "Orders with distributor details"}})
Spree::Admin::ReportsController::AVAILABLE_REPORTS.merge!({:group_buys => {:name => "Group Buys", :description => "Orders by supplier and variant"}})
Spree::Admin::ReportsController::AVAILABLE_REPORTS.merge!({:bulk_coop => {:name => "Bulk Co-Op", :description => "Reports for Bulk Co-Op orders"}})
Spree::Admin::ReportsController::AVAILABLE_REPORTS.merge!({:payments => {:name => "Payment Reports", :description => "Reports for Payments"}})
Spree::Admin::ReportsController::AVAILABLE_REPORTS.merge!({:orders_and_fulfillment => {:name => "Orders & Fulfillment Reports", :description => ''}})
Spree::Admin::ReportsController::AVAILABLE_REPORTS.merge!({:products_and_inventory => {:name => "Products & Inventory", :description => ''}})
REPORT_TYPES = {
orders_and_fulfillment: [
@@ -25,6 +28,10 @@ Spree::Admin::ReportsController.class_eval do
['Order Cycle Supplier Totals by Distributor',:order_cycle_supplier_totals_by_distributor],
['Order Cycle Distributor Totals by Supplier',:order_cycle_distributor_totals_by_supplier],
['Order Cycle Customer Totals',:order_cycle_customer_totals]
],
products_and_inventory: [
['All products', :all_products],
['Inventory (on hand)', :inventory]
]
}
@@ -57,38 +64,6 @@ Spree::Admin::ReportsController.class_eval do
end
end
def group_buys
params[:q] = {} unless params[:q]
if params[:q][:completed_at_gt].blank?
params[:q][:completed_at_gt] = Time.zone.now.beginning_of_month
else
params[:q][:completed_at_gt] = Time.zone.parse(params[:q][:completed_at_gt]).beginning_of_day rescue Time.zone.now.beginning_of_month
end
if params[:q] && !params[:q][:completed_at_lt].blank?
params[:q][:completed_at_lt] = Time.zone.parse(params[:q][:completed_at_lt]).end_of_day rescue ""
end
params[:q][:meta_sort] ||= "completed_at.desc"
@search = Spree::Order.complete.not_state(:canceled).managed_by(spree_current_user).search(params[:q])
orders = @search.result
@distributors = Enterprise.is_distributor.managed_by(spree_current_user)
@report = OpenFoodNetwork::GroupBuyReport.new orders
unless params[:csv]
render :html => @report
else
csv_string = CSV.generate do |csv|
csv << @report.header
@report.table.each { |row| csv << row }
end
send_data csv_string, :filename => "group_buy.csv"
end
end
def bulk_coop
params[:q] = {} unless params[:q]
@@ -559,6 +534,10 @@ Spree::Admin::ReportsController.class_eval do
end
def products_and_inventory
end
def render_report (header, table, create_csv, csv_file_name)
unless create_csv
render :html => table

View File

@@ -66,7 +66,7 @@ class AbilityDecorator
end
# Enterprise User can access reports page
can [:admin, :index, :orders_and_distributors, :group_buys, :bulk_coop, :payments, :orders_and_fulfillment], :report
can [:admin, :index, :orders_and_distributors, :group_buys, :bulk_coop, :payments, :orders_and_fulfillment, :products_and_inventory], :report
end
end
end

View File

@@ -1,37 +0,0 @@
= form_for @search, :url => spree.group_buys_admin_reports_path do |f|
= label_tag nil, t(:date_range)
%br
.date-range-filter
%div{"class" => "left sub-field"}
= f.text_field :completed_at_gt, :class => 'datepicker'
%br
= label_tag nil, t(:start), :class => 'sub'
%div{"class" => "right sub-field"}
= f.text_field :completed_at_lt, :class => 'datepicker'
%br
= label_tag nil, t(:stop)
%br
= label_tag nil, "Distributor: "
= f.collection_select(:distributor_id_eq, @distributors, :id, :name)
%br
%br
= check_box_tag :csv
= label_tag :csv, "Download as csv"
%br
= button t(:search)
%br
%br
%table#listing_orders.index
%thead
%tr{'data-hook' => "orders_header"}
- @report.header.each do |heading|
%th=heading
%tbody
- @report.table.each do |row|
%tr
- row.each do |column|
%td= column
- if @report.table.empty?
%tr
%td{:colspan => "2"}= t(:none)

View File

@@ -57,6 +57,7 @@ Spree::Core::Engine.routes.prepend do
match '/admin/reports/payments' => 'admin/reports#payments', :as => "payments_admin_reports", :via => [:get, :post]
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]
namespace :api, :defaults => { :format => 'json' } do

View File

@@ -16,14 +16,6 @@ feature %q{
page.should have_content 'Order date'
end
scenario "group buys report" do
login_to_admin_section
click_link 'Reports'
click_link 'Group Buys'
page.should have_content 'Supplier'
end
scenario "bulk co-op report" do
login_to_admin_section
click_link 'Reports'
@@ -79,4 +71,16 @@ feature %q{
all('table#listing_orders tbody tr').count.should == 2 # Two rows per order
end
describe "products and inventory report" do
it "shows products and inventory report" do
login_to_admin_section
click_link 'Reports'
page.should have_content "All products"
page.should have_content "Inventory (on hand)"
click_link 'Products & Inventory'
page.should have_content "Supplier"
end
end
end