diff --git a/app/views/spree/admin/reports/_orders_and_fulfillment_description.html.haml b/app/views/spree/admin/reports/_orders_and_fulfillment_description.html.haml index a813492cac..d17874cd38 100644 --- a/app/views/spree/admin/reports/_orders_and_fulfillment_description.html.haml +++ b/app/views/spree/admin/reports/_orders_and_fulfillment_description.html.haml @@ -1,5 +1,4 @@ %ul{style: "margin-left: 12pt"} - report_types.each do |report_type| - %li - = link_to report_type[0], "#{orders_and_fulfillment_admin_reports_url}?report_type=#{report_type[1]}" - \ No newline at end of file + %li + = link_to report_type[0], "#{orders_and_fulfillment_admin_reports_url}?report_subtype=#{report_type[1]}" diff --git a/app/views/spree/admin/reports/filters/_orders_and_fulfillment.html.haml b/app/views/spree/admin/reports/filters/_orders_and_fulfillment.html.haml new file mode 100755 index 0000000000..e43204e60d --- /dev/null +++ b/app/views/spree/admin/reports/filters/_orders_and_fulfillment.html.haml @@ -0,0 +1,14 @@ += render 'spree/admin/reports/date_range_form', f: f + +.row + .alpha.two.columns= label_tag nil, t(:report_hubs) + .omega.fourteen.columns= f.collection_select(:distributor_id_in, @distributors, :id, :name, {}, {class: "select2 fullwidth", multiple: true}) + +.row + .alpha.two.columns= label_tag nil, t(:report_producers) + .omega.fourteen.columns= select_tag(:supplier_id_in, options_from_collection_for_select(@suppliers, :id, :name, params[:supplier_id_in]), {class: "select2 fullwidth", multiple: true}) + +.row + .alpha.two.columns= label_tag nil, t(:report_customers_cycle) + .omega.fourteen.columns + = f.select(:order_cycle_id_in, report_order_cycle_options(@order_cycles), {selected: params.dig(:q, :order_cycle_id_in)}, {class: "select2 fullwidth", multiple: true}) diff --git a/app/views/spree/admin/reports/orders_and_fulfillment.html.haml b/app/views/spree/admin/reports/orders_and_fulfillment.html.haml deleted file mode 100644 index 1a880f2dd5..0000000000 --- a/app/views/spree/admin/reports/orders_and_fulfillment.html.haml +++ /dev/null @@ -1,31 +0,0 @@ -= form_for @report.search, :url => spree.orders_and_fulfillment_admin_reports_path do |f| - = render 'date_range_form', f: f - - .row - .alpha.two.columns= label_tag nil, t(:report_hubs) - .omega.fourteen.columns= f.collection_select(:distributor_id_in, @distributors, :id, :name, {}, {class: "select2 fullwidth", multiple: true}) - - .row - .alpha.two.columns= label_tag nil, t(:report_producers) - .omega.fourteen.columns= select_tag(:supplier_id_in, options_from_collection_for_select(@suppliers, :id, :name, params[:supplier_id_in]), {class: "select2 fullwidth", multiple: true}) - - .row - .alpha.two.columns= label_tag nil, t(:report_customers_cycle) - .omega.fourteen.columns - = f.select(:order_cycle_id_in, report_order_cycle_options(@order_cycles), {selected: params.dig(:q, :order_cycle_id_in)}, {class: "select2 fullwidth", multiple: true}) - - .row - .alpha.two.columns= label_tag nil, t(:report_type) - .omega.fourteen.columns= select_tag(:report_type, options_for_select(@report_types, @report_type)) - - .row - = check_box_tag :csv - = label_tag :csv, t(:report_customers_csv) - - .row - = button t(:search) - -- if render_content? - = render partial: "customer_names_message" - -= render "table", id: "listing_orders", msg_option: t(:search) diff --git a/lib/open_food_network/orders_and_fulfillments_report.rb b/lib/open_food_network/orders_and_fulfillment_report.rb similarity index 78% rename from lib/open_food_network/orders_and_fulfillments_report.rb rename to lib/open_food_network/orders_and_fulfillment_report.rb index d6bd7487d6..ac62fa09d2 100644 --- a/lib/open_food_network/orders_and_fulfillments_report.rb +++ b/lib/open_food_network/orders_and_fulfillment_report.rb @@ -1,24 +1,25 @@ # frozen_string_literal: true require "open_food_network/reports/line_items" -require "open_food_network/orders_and_fulfillments_report/supplier_totals_report" -require "open_food_network/orders_and_fulfillments_report/supplier_totals_by_distributor_report" -require "open_food_network/orders_and_fulfillments_report/distributor_totals_by_supplier_report" -require "open_food_network/orders_and_fulfillments_report/customer_totals_report" -require 'open_food_network/orders_and_fulfillments_report/default_report' +require "open_food_network/orders_and_fulfillment_report/supplier_totals_report" +require "open_food_network/orders_and_fulfillment_report/supplier_totals_by_distributor_report" +require "open_food_network/orders_and_fulfillment_report/distributor_totals_by_supplier_report" +require "open_food_network/orders_and_fulfillment_report/customer_totals_report" +require 'open_food_network/orders_and_fulfillment_report/default_report' +require 'open_food_network/order_grouper' include Spree::ReportsHelper module OpenFoodNetwork - class OrdersAndFulfillmentsReport + class OrdersAndFulfillmentReport attr_reader :options, :report_type - delegate :header, :rules, :columns, to: :report + delegate :table_headers, :rules, :columns, to: :report def initialize(user, options = {}, render_table = false) @user = user @options = options - @report_type = options[:report_type] + @report_type = options[:report_subtype] @render_table = render_table @variant_scopers_by_distributor_id = {} end @@ -33,6 +34,11 @@ module OpenFoodNetwork report_line_items.list(report.line_item_includes) end + def table_rows + order_grouper = OpenFoodNetwork::OrderGrouper.new report.rules, report.columns, report + order_grouper.table(table_items) + end + def line_item_name proc { |line_item| line_item.variant.full_name } end diff --git a/lib/open_food_network/orders_and_fulfillments_report/customer_totals_report.rb b/lib/open_food_network/orders_and_fulfillment_report/customer_totals_report.rb similarity index 99% rename from lib/open_food_network/orders_and_fulfillments_report/customer_totals_report.rb rename to lib/open_food_network/orders_and_fulfillment_report/customer_totals_report.rb index f65ad3a16f..8ec81136a4 100644 --- a/lib/open_food_network/orders_and_fulfillments_report/customer_totals_report.rb +++ b/lib/open_food_network/orders_and_fulfillment_report/customer_totals_report.rb @@ -2,7 +2,7 @@ # rubocop:disable Metrics/ClassLength module OpenFoodNetwork - class OrdersAndFulfillmentsReport + class OrdersAndFulfillmentReport class CustomerTotalsReport REPORT_TYPE = "order_cycle_customer_totals" @@ -17,7 +17,7 @@ module OpenFoodNetwork end # rubocop:disable Metrics/AbcSize - def header + def table_headers [I18n.t(:report_header_hub), I18n.t(:report_header_customer), I18n.t(:report_header_email), I18n.t(:report_header_phone), I18n.t(:report_header_producer), I18n.t(:report_header_product), I18n.t(:report_header_variant), diff --git a/lib/open_food_network/orders_and_fulfillments_report/default_report.rb b/lib/open_food_network/orders_and_fulfillment_report/default_report.rb similarity index 96% rename from lib/open_food_network/orders_and_fulfillments_report/default_report.rb rename to lib/open_food_network/orders_and_fulfillment_report/default_report.rb index 3d10c9d7c4..2ec3c20a4e 100644 --- a/lib/open_food_network/orders_and_fulfillments_report/default_report.rb +++ b/lib/open_food_network/orders_and_fulfillment_report/default_report.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module OpenFoodNetwork - class OrdersAndFulfillmentsReport + class OrdersAndFulfillmentReport class DefaultReport delegate :line_item_name, :supplier_name, :product_name, :line_items_name, to: :context @@ -9,7 +9,7 @@ module OpenFoodNetwork @context = context end - def header + def table_headers [ I18n.t(:report_header_producer), I18n.t(:report_header_product), diff --git a/lib/open_food_network/orders_and_fulfillments_report/distributor_totals_by_supplier_report.rb b/lib/open_food_network/orders_and_fulfillment_report/distributor_totals_by_supplier_report.rb similarity index 97% rename from lib/open_food_network/orders_and_fulfillments_report/distributor_totals_by_supplier_report.rb rename to lib/open_food_network/orders_and_fulfillment_report/distributor_totals_by_supplier_report.rb index 5ce88bdab6..472aadf38d 100644 --- a/lib/open_food_network/orders_and_fulfillments_report/distributor_totals_by_supplier_report.rb +++ b/lib/open_food_network/orders_and_fulfillment_report/distributor_totals_by_supplier_report.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module OpenFoodNetwork - class OrdersAndFulfillmentsReport + class OrdersAndFulfillmentReport class DistributorTotalsBySupplierReport REPORT_TYPE = "order_cycle_distributor_totals_by_supplier" @@ -11,7 +11,7 @@ module OpenFoodNetwork @context = context end - def header + def table_headers [I18n.t(:report_header_hub), I18n.t(:report_header_producer), I18n.t(:report_header_product), I18n.t(:report_header_variant), I18n.t(:report_header_quantity), I18n.t(:report_header_curr_cost_per_unit), diff --git a/lib/open_food_network/orders_and_fulfillments_report/supplier_totals_by_distributor_report.rb b/lib/open_food_network/orders_and_fulfillment_report/supplier_totals_by_distributor_report.rb similarity index 97% rename from lib/open_food_network/orders_and_fulfillments_report/supplier_totals_by_distributor_report.rb rename to lib/open_food_network/orders_and_fulfillment_report/supplier_totals_by_distributor_report.rb index 404fd2eeb3..8731c58c70 100644 --- a/lib/open_food_network/orders_and_fulfillments_report/supplier_totals_by_distributor_report.rb +++ b/lib/open_food_network/orders_and_fulfillment_report/supplier_totals_by_distributor_report.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module OpenFoodNetwork - class OrdersAndFulfillmentsReport + class OrdersAndFulfillmentReport class SupplierTotalsByDistributorReport REPORT_TYPE = "order_cycle_supplier_totals_by_distributor" @@ -13,7 +13,7 @@ module OpenFoodNetwork @context = context end - def header + def table_headers [I18n.t(:report_header_producer), I18n.t(:report_header_product), I18n.t(:report_header_variant), I18n.t(:report_header_to_hub), I18n.t(:report_header_quantity), I18n.t(:report_header_curr_cost_per_unit), diff --git a/lib/open_food_network/orders_and_fulfillments_report/supplier_totals_report.rb b/lib/open_food_network/orders_and_fulfillment_report/supplier_totals_report.rb similarity index 96% rename from lib/open_food_network/orders_and_fulfillments_report/supplier_totals_report.rb rename to lib/open_food_network/orders_and_fulfillment_report/supplier_totals_report.rb index 9fd5f7fcf9..8ee9decf89 100644 --- a/lib/open_food_network/orders_and_fulfillments_report/supplier_totals_report.rb +++ b/lib/open_food_network/orders_and_fulfillment_report/supplier_totals_report.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module OpenFoodNetwork - class OrdersAndFulfillmentsReport + class OrdersAndFulfillmentReport class SupplierTotalsReport REPORT_TYPE = "order_cycle_supplier_totals" @@ -13,7 +13,7 @@ module OpenFoodNetwork @context = context end - def header + def table_headers [I18n.t(:report_header_producer), I18n.t(:report_header_product), I18n.t(:report_header_variant), I18n.t(:report_header_quantity), I18n.t(:report_header_total_units), I18n.t(:report_header_curr_cost_per_unit), diff --git a/spec/lib/open_food_network/orders_and_fulfillments_report/customer_totals_report_spec.rb b/spec/lib/open_food_network/orders_and_fulfillment_report/customer_totals_report_spec.rb similarity index 88% rename from spec/lib/open_food_network/orders_and_fulfillments_report/customer_totals_report_spec.rb rename to spec/lib/open_food_network/orders_and_fulfillment_report/customer_totals_report_spec.rb index 8f4a7f6a21..966cf6e05e 100644 --- a/spec/lib/open_food_network/orders_and_fulfillments_report/customer_totals_report_spec.rb +++ b/spec/lib/open_food_network/orders_and_fulfillment_report/customer_totals_report_spec.rb @@ -1,22 +1,21 @@ # frozen_string_literal: true require "spec_helper" -require 'open_food_network/orders_and_fulfillments_report' -require 'open_food_network/orders_and_fulfillments_report/customer_totals_report' -require 'open_food_network/order_grouper' +require 'open_food_network/orders_and_fulfillment_report' +require 'open_food_network/orders_and_fulfillment_report/customer_totals_report' -RSpec.describe OpenFoodNetwork::OrdersAndFulfillmentsReport::CustomerTotalsReport do +RSpec.describe OpenFoodNetwork::OrdersAndFulfillmentReport::CustomerTotalsReport do let!(:distributor) { create(:distributor_enterprise) } let!(:customer) { create(:customer, enterprise: distributor) } let(:current_user) { distributor.owner } let(:report) do - report_options = { report_type: described_class::REPORT_TYPE } - OpenFoodNetwork::OrdersAndFulfillmentsReport.new(current_user, report_options, true) + report_options = { report_subtype: described_class::REPORT_TYPE } + OpenFoodNetwork::OrdersAndFulfillmentReport.new(current_user, report_options, true) end let(:report_table) do - OpenFoodNetwork::OrderGrouper.new(report.rules, report.columns).table(report.table_items) + report.table_rows end context "viewing the report" do diff --git a/spec/lib/open_food_network/orders_and_fulfillments_report/distributor_totals_by_supplier_report_spec.rb b/spec/lib/open_food_network/orders_and_fulfillment_report/distributor_totals_by_supplier_report_spec.rb similarity index 65% rename from spec/lib/open_food_network/orders_and_fulfillments_report/distributor_totals_by_supplier_report_spec.rb rename to spec/lib/open_food_network/orders_and_fulfillment_report/distributor_totals_by_supplier_report_spec.rb index 7c5975eb7a..3da55893ad 100644 --- a/spec/lib/open_food_network/orders_and_fulfillments_report/distributor_totals_by_supplier_report_spec.rb +++ b/spec/lib/open_food_network/orders_and_fulfillment_report/distributor_totals_by_supplier_report_spec.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true require 'spec_helper' -require 'open_food_network/orders_and_fulfillments_report/distributor_totals_by_supplier_report' +require 'open_food_network/orders_and_fulfillment_report/distributor_totals_by_supplier_report' -RSpec.describe OpenFoodNetwork::OrdersAndFulfillmentsReport::DistributorTotalsBySupplierReport do +RSpec.describe OpenFoodNetwork::OrdersAndFulfillmentReport::DistributorTotalsBySupplierReport do let!(:distributor) { create(:distributor_enterprise) } let!(:order) do @@ -13,12 +13,12 @@ RSpec.describe OpenFoodNetwork::OrdersAndFulfillmentsReport::DistributorTotalsBy let(:current_user) { distributor.owner } let(:report) do - report_options = { report_type: described_class::REPORT_TYPE } - OpenFoodNetwork::OrdersAndFulfillmentsReport.new(current_user, report_options, true) + report_options = { report_subtype: described_class::REPORT_TYPE } + OpenFoodNetwork::OrdersAndFulfillmentReport.new(current_user, report_options, true) end let(:report_table) do - OpenFoodNetwork::OrderGrouper.new(report.rules, report.columns).table(report.table_items) + report.table_rows end it "generates the report" do diff --git a/spec/lib/open_food_network/orders_and_fulfillments_report/supplier_totals_by_distributor_report_spec.rb b/spec/lib/open_food_network/orders_and_fulfillment_report/supplier_totals_by_distributor_report_spec.rb similarity index 65% rename from spec/lib/open_food_network/orders_and_fulfillments_report/supplier_totals_by_distributor_report_spec.rb rename to spec/lib/open_food_network/orders_and_fulfillment_report/supplier_totals_by_distributor_report_spec.rb index 2ad62ba230..337f64ed45 100644 --- a/spec/lib/open_food_network/orders_and_fulfillments_report/supplier_totals_by_distributor_report_spec.rb +++ b/spec/lib/open_food_network/orders_and_fulfillment_report/supplier_totals_by_distributor_report_spec.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true require 'spec_helper' -require 'open_food_network/orders_and_fulfillments_report/supplier_totals_by_distributor_report' +require 'open_food_network/orders_and_fulfillment_report/supplier_totals_by_distributor_report' -RSpec.describe OpenFoodNetwork::OrdersAndFulfillmentsReport::SupplierTotalsByDistributorReport do +RSpec.describe OpenFoodNetwork::OrdersAndFulfillmentReport::SupplierTotalsByDistributorReport do let!(:distributor) { create(:distributor_enterprise) } let!(:order) do @@ -13,12 +13,12 @@ RSpec.describe OpenFoodNetwork::OrdersAndFulfillmentsReport::SupplierTotalsByDis let(:current_user) { distributor.owner } let(:report) do - report_options = { report_type: described_class::REPORT_TYPE } - OpenFoodNetwork::OrdersAndFulfillmentsReport.new(current_user, report_options, true) + report_options = { report_subtype: described_class::REPORT_TYPE } + OpenFoodNetwork::OrdersAndFulfillmentReport.new(current_user, report_options, true) end let(:report_table) do - OpenFoodNetwork::OrderGrouper.new(report.rules, report.columns).table(report.table_items) + report.table_rows end it "generates the report" do diff --git a/spec/lib/open_food_network/orders_and_fulfillments_report/supplier_totals_report_spec.rb b/spec/lib/open_food_network/orders_and_fulfillment_report/supplier_totals_report_spec.rb similarity index 59% rename from spec/lib/open_food_network/orders_and_fulfillments_report/supplier_totals_report_spec.rb rename to spec/lib/open_food_network/orders_and_fulfillment_report/supplier_totals_report_spec.rb index a3ec8baea9..f93c088866 100644 --- a/spec/lib/open_food_network/orders_and_fulfillments_report/supplier_totals_report_spec.rb +++ b/spec/lib/open_food_network/orders_and_fulfillment_report/supplier_totals_report_spec.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true require 'spec_helper' -require 'open_food_network/orders_and_fulfillments_report/supplier_totals_report' +require 'open_food_network/orders_and_fulfillment_report/supplier_totals_report' -RSpec.describe OpenFoodNetwork::OrdersAndFulfillmentsReport::SupplierTotalsReport do +RSpec.describe OpenFoodNetwork::OrdersAndFulfillmentReport::SupplierTotalsReport do let!(:distributor) { create(:distributor_enterprise) } let!(:order) do @@ -13,12 +13,12 @@ RSpec.describe OpenFoodNetwork::OrdersAndFulfillmentsReport::SupplierTotalsRepor let(:current_user) { distributor.owner } let(:report) do - report_options = { report_type: described_class::REPORT_TYPE } - OpenFoodNetwork::OrdersAndFulfillmentsReport.new(current_user, report_options, true) + report_options = { report_subtype: described_class::REPORT_TYPE } + OpenFoodNetwork::OrdersAndFulfillmentReport.new(current_user, report_options, true) end let(:report_table) do - OpenFoodNetwork::OrderGrouper.new(report.rules, report.columns).table(report.table_items) + report.table_rows end it "generates the report" do diff --git a/spec/lib/open_food_network/orders_and_fulfillments_report_spec.rb b/spec/lib/open_food_network/orders_and_fulfillments_report_spec.rb index 51343ddcab..249ac1c61c 100644 --- a/spec/lib/open_food_network/orders_and_fulfillments_report_spec.rb +++ b/spec/lib/open_food_network/orders_and_fulfillments_report_spec.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true require 'spec_helper' -require 'open_food_network/orders_and_fulfillments_report' +require 'open_food_network/orders_and_fulfillment_report' require 'open_food_network/order_grouper' -describe OpenFoodNetwork::OrdersAndFulfillmentsReport do +describe OpenFoodNetwork::OrdersAndFulfillmentReport do include AuthenticationHelper let(:distributor) { create(:distributor_enterprise) } @@ -163,8 +163,8 @@ describe OpenFoodNetwork::OrdersAndFulfillmentsReport do ] report_types.each do |report_type| - report = described_class.new(admin_user, report_type: report_type) - expect(report.header.size).to eq(report.columns.size) + report = described_class.new(admin_user, report_subtype: report_type) + expect(report.table_headers.size).to eq(report.columns.size) end end end @@ -179,8 +179,8 @@ describe OpenFoodNetwork::OrdersAndFulfillmentsReport do end let(:items) { - report = described_class.new(admin_user, { report_type: "order_cycle_customer_totals" }, true) - OpenFoodNetwork::OrderGrouper.new(report.rules, report.columns).table(report.table_items) + described_class.new(admin_user, { report_subtype: "order_cycle_customer_totals" }, true) + .table_rows } before do