Report Refactor 1: Order Cycle Management

This commit is contained in:
Sebastian Castro
2022-03-24 17:40:36 +00:00
committed by Jean-Baptiste Bellet
parent 1fee45035c
commit 01be6fb1f3
7 changed files with 28 additions and 54 deletions

View File

@@ -50,19 +50,7 @@ module Spree
end
def order_cycle_management
raw_params[:q] ||= {}
@report_types = report_types[:order_cycle_management]
@report_type = params[:report_type]
# -- Build Report with Order Grouper
@report = OpenFoodNetwork::OrderCycleManagementReport.new spree_current_user,
raw_params,
render_content?
@table = @report.table_items
render_report(@report.header, @table, params[:csv],
"order_cycle_management_#{timestamp}.csv")
render_report2
end
def orders_and_distributors

View File

@@ -1,4 +1,4 @@
%ul{style: "margin-left: 12pt"}
- report_types.each do |report_type|
%li
= link_to report_type[0], "#{order_cycle_management_admin_reports_url}?report_type=#{report_type[1]}"
= link_to report_type[0], "#{order_cycle_management_admin_reports_url}?report_subtype=#{report_type[1]}"

View File

@@ -0,0 +1,18 @@
= 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_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_payment)
.omega.fourteen.columns= select_tag(:payment_method_in, options_for_select(report_payment_method_options(@report.orders), params[:payment_method_in]), {class: "select2 fullwidth", multiple: true})
.row
.alpha.two.columns= label_tag nil, "#{t(:shipping_methods)}: "
.omega.fourteen.columns= select_tag(:shipping_method_in, options_for_select(report_shipping_method_options(@report.orders), params[:shipping_method_in]), {class: "select2 fullwidth", multiple: true})

View File

@@ -1,32 +0,0 @@
= form_for @report.search, :url => spree.order_cycle_management_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_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_payment)
.omega.fourteen.columns= select_tag(:payment_method_in, options_for_select(report_payment_method_options(@report.orders), params[:payment_method_in]), {class: "select2 fullwidth", multiple: true})
.row
.alpha.two.columns= label_tag nil, "#{t(:shipping_methods)}: "
.omega.fourteen.columns= select_tag(:shipping_method_in, options_for_select(report_shipping_method_options(@report.orders), params[:shipping_method_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)
= render "table", id: "listing_ocm_orders", msg_option: t(:search)

View File

@@ -12,7 +12,7 @@ module OpenFoodNetwork
@render_table = render_table
end
def header
def table_headers
if is_payment_methods?
[
I18n.t(:report_header_first_name),
@@ -63,7 +63,7 @@ module OpenFoodNetwork
filter(orders_with_balance)
end
def table_items
def table_rows
return [] unless @render_table
if is_payment_methods?
@@ -147,7 +147,7 @@ module OpenFoodNetwork
end
def is_payment_methods?
params[:report_type] == "payment_methods"
params[:report_subtype] == "payment_methods"
end
def customer_code(email)

View File

@@ -313,7 +313,7 @@ describe Spree::Admin::ReportsController, type: :controller do
spree_post :order_cycle_management, {
q: { completed_at_lt: 1.day.ago },
shipping_method_in: ["123"], # We just need to search for shipping methods
report_type: "delivery",
report_subtype: "delivery",
}
expect(response).to have_http_status(:ok)

View File

@@ -146,14 +146,14 @@ module OpenFoodNetwork
end
end
describe '#table_items' do
describe '#table_rows' do
subject { OrderCycleManagementReport.new(user, params, true) }
let(:distributor) { create(:distributor_enterprise) }
before { distributor.enterprise_roles.create!(user: user) }
context 'when the report type is payment_methods' do
let(:params) { { report_type: 'payment_methods' } }
let(:params) { { report_subtype: 'payment_methods' } }
let!(:order) do
create(
@@ -164,7 +164,7 @@ module OpenFoodNetwork
end
it 'returns rows with payment information' do
expect(subject.table_items).to eq([[
expect(subject.table_rows).to eq([[
order.billing_address.firstname,
order.billing_address.lastname,
order.distributor.name,
@@ -190,7 +190,7 @@ module OpenFoodNetwork
end
it 'returns rows with delivery information' do
expect(subject.table_items).to eq([[
expect(subject.table_rows).to eq([[
order.ship_address.firstname,
order.ship_address.lastname,
order.distributor.name,