refator reports controller a little

This commit is contained in:
Rafael Schouten
2014-10-12 14:13:52 +11:00
parent e44fed2ff0
commit 46df14c0d9

View File

@@ -6,24 +6,6 @@ require 'open_food_network/order_grouper'
require 'open_food_network/customers_report'
Spree::Admin::ReportsController.class_eval do
# Fetches user's distributors, suppliers and order_cycles
before_filter :load_data, only: [:customers, :products_and_inventory]
# Render a partial for orders and fulfillment description
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
@reports[:customers][:description] =
render_to_string(partial: 'customers_description', layout: false, locals: {report_types: REPORT_TYPES[:customers]}).html_safe
} } }
# OVERRIDING THIS so we use a method not a constant for available reports
def index
@reports = available_reports
respond_with(@reports)
end
REPORT_TYPES = {
orders_and_fulfillment: [
@@ -42,6 +24,26 @@ Spree::Admin::ReportsController.class_eval do
]
}
# Fetches user's distributors, suppliers and order_cycles
before_filter :load_data, only: [:customers, :products_and_inventory]
# Render a partial for orders and fulfillment description
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
@reports[:customers][:description] =
render_to_string(partial: 'customers_description', layout: false, locals: {report_types: REPORT_TYPES[:customers]}).html_safe
} } }
# Overide spree reports list.
def index
@reports = authorized_reports
respond_with(@reports)
end
# This action is short because we refactored it like bosses
def customers
@report_types = REPORT_TYPES[:customers]
@@ -601,7 +603,7 @@ Spree::Admin::ReportsController.class_eval do
@order_cycles = OrderCycle.active_or_complete.accessible_by(spree_current_user).order('orders_close_at DESC')
end
def available_reports
def authorized_reports
reports = {
:orders_and_distributors => {:name => "Orders And Distributors", :description => "Orders with distributor details"},
:bulk_coop => {:name => "Bulk Co-Op", :description => "Reports for Bulk Co-Op orders"},
@@ -611,7 +613,8 @@ Spree::Admin::ReportsController.class_eval do
:products_and_inventory => {:name => "Products & Inventory", :description => ''},
:sales_total => { :name => "Sales Total", :description => "Sales Total For All Orders" }
}
reports.select { |action, details| can? action, :report }
# Return only reports the user is authorized to view.
reports.select { |action| can? action, :report }
end
def total_units(line_items)