Report Refactor 1: Orders & Fulfilment

This commit is contained in:
Sebastian Castro
2022-04-04 22:02:18 +02:00
committed by Jean-Baptiste Bellet
parent 09247b21cd
commit e55462d18b
14 changed files with 67 additions and 80 deletions

View File

@@ -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]}"
%li
= link_to report_type[0], "#{orders_and_fulfillment_admin_reports_url}?report_subtype=#{report_type[1]}"

View File

@@ -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})

View File

@@ -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)

View File

@@ -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

View File

@@ -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),

View File

@@ -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),

View File

@@ -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),

View File

@@ -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),

View File

@@ -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),

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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