diff --git a/app/controllers/spree/admin/reports_controller_decorator.rb b/app/controllers/spree/admin/reports_controller_decorator.rb index 89f2a420b4..06ba786101 100644 --- a/app/controllers/spree/admin/reports_controller_decorator.rb +++ b/app/controllers/spree/admin/reports_controller_decorator.rb @@ -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 diff --git a/app/models/spree/ability_decorator.rb b/app/models/spree/ability_decorator.rb index 4f05e9e1ad..44242b5909 100644 --- a/app/models/spree/ability_decorator.rb +++ b/app/models/spree/ability_decorator.rb @@ -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 diff --git a/app/views/spree/admin/reports/group_buys.html.haml b/app/views/spree/admin/reports/group_buys.html.haml deleted file mode 100644 index bdda9a043d..0000000000 --- a/app/views/spree/admin/reports/group_buys.html.haml +++ /dev/null @@ -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) - diff --git a/config/routes.rb b/config/routes.rb index 8de04e4519..269afec0a9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/spec/features/admin/reports_spec.rb b/spec/features/admin/reports_spec.rb index 1abd0636ea..5b6ff84427 100644 --- a/spec/features/admin/reports_spec.rb +++ b/spec/features/admin/reports_spec.rb @@ -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