mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Report Refactor 1: Orders & Distributors
This commit is contained in:
committed by
Jean-Baptiste Bellet
parent
01be6fb1f3
commit
e20c2e3ced
@@ -423,7 +423,7 @@ Metrics/AbcSize:
|
||||
- 'lib/discourse/single_sign_on.rb'
|
||||
- 'lib/open_food_network/customers_report.rb'
|
||||
- 'lib/open_food_network/group_buy_report.rb'
|
||||
- 'lib/open_food_network/order_and_distributor_report.rb'
|
||||
- 'lib/open_food_network/orders_and_distributors_report.rb'
|
||||
- 'lib/open_food_network/order_cycle_form_applicator.rb'
|
||||
- 'lib/open_food_network/order_cycle_permissions.rb'
|
||||
- 'lib/open_food_network/payments_report.rb'
|
||||
@@ -1135,7 +1135,7 @@ Style/OptionalBooleanParameter:
|
||||
- 'engines/order_management/app/services/order_management/reports/bulk_coop/bulk_coop_report.rb'
|
||||
- 'engines/order_management/app/services/order_management/stock/estimator.rb'
|
||||
- 'lib/open_food_network/customers_report.rb'
|
||||
- 'lib/open_food_network/order_and_distributor_report.rb'
|
||||
- 'lib/open_food_network/orders_and_distributors_report.rb'
|
||||
- 'lib/open_food_network/order_cycle_management_report.rb'
|
||||
- 'lib/open_food_network/orders_and_fulfillment_report.rb'
|
||||
- 'lib/open_food_network/payments_report.rb'
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
require 'csv'
|
||||
|
||||
require 'open_food_network/reports/list'
|
||||
require 'open_food_network/order_and_distributor_report'
|
||||
require 'open_food_network/orders_and_distributors_report'
|
||||
require 'open_food_network/products_and_inventory_report'
|
||||
require 'open_food_network/lettuce_share_report'
|
||||
require 'open_food_network/group_buy_report'
|
||||
@@ -54,12 +54,7 @@ module Spree
|
||||
end
|
||||
|
||||
def orders_and_distributors
|
||||
@report = OpenFoodNetwork::OrderAndDistributorReport.new spree_current_user,
|
||||
raw_params,
|
||||
render_content?
|
||||
@search = @report.search
|
||||
csv_file_name = "orders_and_distributors_#{timestamp}.csv"
|
||||
render_report(@report.header, @report.table, params[:csv], csv_file_name)
|
||||
render_report2
|
||||
end
|
||||
|
||||
def sales_tax
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
= render 'spree/admin/reports/date_range_form', f: f
|
||||
@@ -1,12 +0,0 @@
|
||||
= form_for @search, :url => spree.orders_and_distributors_admin_reports_path do |f|
|
||||
= render 'date_range_form', f: f
|
||||
|
||||
= check_box_tag :csv
|
||||
= label_tag :csv, t(:report_customers_csv)
|
||||
%br
|
||||
= button t(:search)
|
||||
|
||||
- if render_content?
|
||||
= render partial: "customer_names_message"
|
||||
|
||||
= render "table", id: "listing_orders", msg_option: t(:search)
|
||||
@@ -1,7 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module OpenFoodNetwork
|
||||
class OrderAndDistributorReport
|
||||
class OrdersAndDistributorsReport
|
||||
def initialize(user, params = {}, render_table = false)
|
||||
@params = params
|
||||
@user = user
|
||||
@@ -10,7 +10,7 @@ module OpenFoodNetwork
|
||||
@permissions = ::Permissions::Order.new(user, @params[:q])
|
||||
end
|
||||
|
||||
def header
|
||||
def table_headers
|
||||
[
|
||||
I18n.t(:report_header_order_date),
|
||||
I18n.t(:report_header_order_id),
|
||||
@@ -41,7 +41,7 @@ module OpenFoodNetwork
|
||||
ransack(@params[:q])
|
||||
end
|
||||
|
||||
def table
|
||||
def table_rows
|
||||
return [] unless @render_table
|
||||
|
||||
orders = search.result
|
||||
@@ -104,7 +104,7 @@ module OpenFoodNetwork
|
||||
order.distributor.address.address1,
|
||||
order.distributor.address.city,
|
||||
order.distributor.address.zipcode,
|
||||
order.shipping_method.name,
|
||||
order.shipping_method&.name,
|
||||
order.special_instructions
|
||||
]
|
||||
end
|
||||
@@ -99,9 +99,9 @@ describe Spree::Admin::ReportsController, type: :controller do
|
||||
it "only shows orders that I have access to" do
|
||||
spree_post :orders_and_distributors
|
||||
|
||||
expect(assigns(:search).result).to include(orderA1, orderB1)
|
||||
expect(assigns(:search).result).not_to include(orderA2)
|
||||
expect(assigns(:search).result).not_to include(orderB2)
|
||||
expect(assigns(:report).search.result).to include(orderA1, orderB1)
|
||||
expect(assigns(:report).search.result).not_to include(orderA2)
|
||||
expect(assigns(:report).search.result).not_to include(orderB2)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'spec_helper'
|
||||
require 'open_food_network/order_and_distributor_report'
|
||||
require 'open_food_network/orders_and_distributors_report'
|
||||
|
||||
module OpenFoodNetwork
|
||||
describe OrderAndDistributorReport do
|
||||
describe OrdersAndDistributorsReport do
|
||||
describe 'orders and distributors report' do
|
||||
it 'should return a header row describing the report' do
|
||||
subject = OrderAndDistributorReport.new nil
|
||||
subject = OrdersAndDistributorsReport.new nil
|
||||
|
||||
header = subject.header
|
||||
expect(header).to eq(
|
||||
expect(subject.table_headers).to eq(
|
||||
[
|
||||
'Order date', 'Order Id',
|
||||
'Customer Name', 'Customer Email', 'Customer Phone', 'Customer City',
|
||||
@@ -45,9 +44,9 @@ module OpenFoodNetwork
|
||||
end
|
||||
|
||||
it 'should denormalise order and distributor details for display as csv' do
|
||||
subject = OrderAndDistributorReport.new create(:admin_user), {}, true
|
||||
subject = OrdersAndDistributorsReport.new create(:admin_user), {}, true
|
||||
|
||||
table = subject.table
|
||||
table = subject.table_rows
|
||||
|
||||
expect(table.size).to eq 1
|
||||
expect(table[0]).to eq([
|
||||
@@ -77,9 +76,9 @@ module OpenFoodNetwork
|
||||
it "prints one row per line item" do
|
||||
create(:line_item_with_shipment, order: order)
|
||||
|
||||
subject = OrderAndDistributorReport.new(create(:admin_user), {}, true)
|
||||
subject = OrdersAndDistributorsReport.new(create(:admin_user), {}, true)
|
||||
|
||||
table = subject.table
|
||||
table = subject.table_rows
|
||||
expect(table.size).to eq 2
|
||||
end
|
||||
end
|
||||
@@ -80,7 +80,7 @@ describe '
|
||||
|
||||
it "delivery report" do
|
||||
click_link "Delivery Report"
|
||||
click_button "Search"
|
||||
click_button "Go"
|
||||
rows = find("table.report__table").all("thead tr")
|
||||
table = rows.map { |r| r.all("th").map { |c| c.text.strip } }
|
||||
expect(table.sort).to eq([
|
||||
|
||||
Reference in New Issue
Block a user