mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-29 21:17:17 +00:00
Report Refactor 3: Enterprise FeeSummary
This one as actually not really been refactored, too much work to rewrite it so I just encapsulated the result within the new methods definitions
This commit is contained in:
committed by
Jean-Baptiste Bellet
parent
b3e1ffe9e2
commit
42da443901
@@ -1,162 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "spec_helper"
|
||||
|
||||
# feature "enterprise fee summaries", js: true do
|
||||
# include AuthenticationHelper
|
||||
# include WebHelper
|
||||
|
||||
# let!(:distributor) { create(:distributor_enterprise) }
|
||||
# let!(:other_distributor) { create(:distributor_enterprise) }
|
||||
|
||||
# let!(:order_cycle) { create(:simple_order_cycle, coordinator: distributor) }
|
||||
# let!(:other_order_cycle) { create(:simple_order_cycle, coordinator: other_distributor) }
|
||||
|
||||
# before do
|
||||
# login_as current_user
|
||||
# end
|
||||
|
||||
# describe "navigation" do
|
||||
# context "when accessing the report as an superadmin" do
|
||||
# let(:current_user) { create(:admin_user) }
|
||||
|
||||
# it "shows link and allows access to the report" do
|
||||
# visit spree.admin_reports_path
|
||||
# click_on I18n.t("admin.reports.enterprise_fee_summary.name")
|
||||
# expect(page).to have_button("Go")
|
||||
# end
|
||||
# end
|
||||
|
||||
# context "when accessing the report as an admin" do
|
||||
# let(:current_user) { distributor.owner }
|
||||
|
||||
# it "shows link and allows access to the report" do
|
||||
# visit spree.admin_reports_path
|
||||
# click_on I18n.t("admin.reports.enterprise_fee_summary.name")
|
||||
# expect(page).to have_button("Go")
|
||||
# end
|
||||
# end
|
||||
|
||||
# context "when accessing the report as an enterprise user without sufficient permissions" do
|
||||
# let(:current_user) { create(:user) }
|
||||
|
||||
# it "does not allow access to the report" do
|
||||
# visit spree.admin_reports_path
|
||||
# expect(page).to have_no_link(I18n.t("admin.reports.enterprise_fee_summary.name"))
|
||||
# visit main_app.new_order_management_reports_enterprise_fee_summary_path
|
||||
# expect(page).to have_content(I18n.t("unauthorized"))
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
||||
# describe "smoke test for filters" do
|
||||
# before do
|
||||
# visit main_app.new_order_management_reports_enterprise_fee_summary_path
|
||||
# end
|
||||
|
||||
# context "when logged in as admin" do
|
||||
# let(:current_user) { create(:admin_user) }
|
||||
|
||||
# it "shows all available options" do
|
||||
# expect(page).to have_select "q_report_order_cycle_ids", with_options: [order_cycle.name]
|
||||
# end
|
||||
# end
|
||||
|
||||
# context "when logged in as enterprise user" do
|
||||
# let!(:order) do
|
||||
# create(:completed_order_with_fees, order_cycle: order_cycle,
|
||||
# distributor: distributor)
|
||||
# end
|
||||
# let(:current_user) { distributor.owner }
|
||||
|
||||
# it "shows available options for the enterprise" do
|
||||
# expect(page).to have_select "q_report_order_cycle_ids", options: [order_cycle.name]
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
||||
# describe "csv downloads" do
|
||||
# around do |example|
|
||||
# with_empty_downloads_folder { example.run }
|
||||
# end
|
||||
|
||||
# describe "smoke test for generation of report based on permissions" do
|
||||
# before do
|
||||
# visit main_app.new_order_management_reports_enterprise_fee_summary_path
|
||||
# end
|
||||
|
||||
# context "when logged in as admin" do
|
||||
# let!(:order) do
|
||||
# create(:completed_order_with_fees, order_cycle: order_cycle,
|
||||
# distributor: distributor)
|
||||
# end
|
||||
# let(:current_user) { create(:admin_user) }
|
||||
|
||||
# it "generates file with data for all enterprises" do
|
||||
# check I18n.t("filters.report_format_csv", scope: i18n_scope)
|
||||
# click_on "Go"
|
||||
|
||||
# expect(downloaded_filename).to include ".csv"
|
||||
# expect(downloaded_content).to have_content(distributor.name)
|
||||
# end
|
||||
# end
|
||||
|
||||
# context "when logged in as enterprise user" do
|
||||
# let!(:order) do
|
||||
# create(:completed_order_with_fees, order_cycle: order_cycle,
|
||||
# distributor: distributor)
|
||||
# end
|
||||
# let!(:other_order) do
|
||||
# create(:completed_order_with_fees, order_cycle: other_order_cycle,
|
||||
# distributor: other_distributor)
|
||||
# end
|
||||
# let(:current_user) { distributor.owner }
|
||||
|
||||
# it "generates file with data for the enterprise" do
|
||||
# check I18n.t("filters.report_format_csv", scope: i18n_scope)
|
||||
# click_on "Go"
|
||||
|
||||
# expect(downloaded_filename).to include ".csv"
|
||||
# csv_content = downloaded_content
|
||||
# expect(csv_content).to have_content(distributor.name)
|
||||
# expect(csv_content).not_to have_content(other_distributor.name)
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
||||
# describe "smoke test for filtering report based on filters" do
|
||||
# let!(:second_distributor) { create(:distributor_enterprise) }
|
||||
# let!(:second_order_cycle) { create(:simple_order_cycle, coordinator: second_distributor) }
|
||||
|
||||
# let!(:order) do
|
||||
# create(:completed_order_with_fees, order_cycle: order_cycle,
|
||||
# distributor: distributor)
|
||||
# end
|
||||
# let!(:second_order) do
|
||||
# create(:completed_order_with_fees, order_cycle: second_order_cycle,
|
||||
# distributor: second_distributor)
|
||||
# end
|
||||
|
||||
# let(:current_user) { create(:admin_user) }
|
||||
|
||||
# before do
|
||||
# visit main_app.new_order_management_reports_enterprise_fee_summary_path
|
||||
# end
|
||||
|
||||
# it "generates file with data for selected order cycle" do
|
||||
# select order_cycle.name, from: "report_order_cycle_ids"
|
||||
# check I18n.t("filters.report_format_csv", scope: i18n_scope)
|
||||
# click_on "Go"
|
||||
|
||||
# expect(downloaded_filename).to include ".csv"
|
||||
# csv_content = downloaded_content
|
||||
# expect(csv_content).to have_content(distributor.name)
|
||||
# expect(csv_content).not_to have_content(second_distributor.name)
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
||||
# def i18n_scope
|
||||
# "order_management.reports.enterprise_fee_summaries"
|
||||
# end
|
||||
# end
|
||||
@@ -3,7 +3,7 @@
|
||||
module Reporting
|
||||
module Reports
|
||||
module EnterpriseFeeSummary
|
||||
class EnterpriseFeeSummaryReport < ReportObjectTemplate
|
||||
class Base < ReportObjectTemplate
|
||||
attr_accessor :permissions, :parameters
|
||||
|
||||
def initialize(user, params = {})
|
||||
@@ -13,33 +13,29 @@ module Reporting
|
||||
p['start_at'] = p.delete('completed_at_gt')
|
||||
p['end_at'] = p.delete('completed_at_lt')
|
||||
end
|
||||
@parameters = Reporting::Reports::EnterpriseFeeSummary::Parameters.new(p || {})
|
||||
@parameters = Parameters.new(p || {})
|
||||
@parameters.validate!
|
||||
@permissions = Permissions.new(user)
|
||||
@parameters.authorize!(@permissions)
|
||||
end
|
||||
|
||||
def translate_header(key)
|
||||
I18n.t("header.#{key}", scope: i18n_scope)
|
||||
end
|
||||
|
||||
def i18n_scope
|
||||
"order_management.reports.enterprise_fee_summary.formats.csv"
|
||||
end
|
||||
|
||||
def message
|
||||
I18n.t("spree.admin.reports.customer_names_message.customer_names_tip")
|
||||
end
|
||||
|
||||
def table_headers
|
||||
data_row_attributes.map do |attribute|
|
||||
header_label(attribute)
|
||||
end
|
||||
def query_result
|
||||
enterprise_fee_type_total_list.sort
|
||||
end
|
||||
|
||||
def table_rows
|
||||
enterprise_fee_type_total_list.sort.map do |data|
|
||||
data_row_attributes.map do |attribute|
|
||||
data.public_send(attribute)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def data_row_attributes
|
||||
def data_attributes
|
||||
[
|
||||
:fee_type,
|
||||
:enterprise_name,
|
||||
@@ -52,13 +48,15 @@ module Reporting
|
||||
]
|
||||
end
|
||||
|
||||
def header_label(attribute)
|
||||
I18n.t("header.#{attribute}", scope: i18n_scope)
|
||||
# This report calculate data in a different way, so we just encapsulate the result
|
||||
# in the columns method
|
||||
def columns
|
||||
data_attributes.map { |field|
|
||||
[field.to_sym, proc { |data| data.public_send(field) }]
|
||||
}.to_h
|
||||
end
|
||||
|
||||
def i18n_scope
|
||||
"order_management.reports.enterprise_fee_summary.formats.csv"
|
||||
end
|
||||
private
|
||||
|
||||
def enterprise_fees_by_customer
|
||||
if parameters.order_cycle_ids.empty?
|
||||
@@ -73,19 +71,12 @@ module Reporting
|
||||
summarizer = Summarizer.new(total_data)
|
||||
|
||||
ReportData::EnterpriseFeeTypeTotal.new.tap do |total|
|
||||
enterprise_fee_type_summarizer_to_total_attributes.each do |attribute|
|
||||
data_attributes.each do |attribute|
|
||||
total.public_send("#{attribute}=", summarizer.public_send(attribute))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def enterprise_fee_type_summarizer_to_total_attributes
|
||||
[
|
||||
:fee_type, :enterprise_name, :fee_name, :customer_name, :fee_placement,
|
||||
:fee_calculated_on_transfer_through_name, :tax_category_name, :total_amount
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
File diff suppressed because it is too large
Load Diff
162
spec/system/admin/reports/enterprise_fee_summaries_spec.rb
Normal file
162
spec/system/admin/reports/enterprise_fee_summaries_spec.rb
Normal file
@@ -0,0 +1,162 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "spec_helper"
|
||||
|
||||
feature "enterprise fee summaries", js: true do
|
||||
include AuthenticationHelper
|
||||
include WebHelper
|
||||
|
||||
let!(:distributor) { create(:distributor_enterprise) }
|
||||
let!(:other_distributor) { create(:distributor_enterprise) }
|
||||
|
||||
let!(:order_cycle) { create(:simple_order_cycle, coordinator: distributor) }
|
||||
let!(:other_order_cycle) { create(:simple_order_cycle, coordinator: other_distributor) }
|
||||
|
||||
before do
|
||||
login_as current_user
|
||||
end
|
||||
|
||||
describe "navigation" do
|
||||
context "when accessing the report as an superadmin" do
|
||||
let(:current_user) { create(:admin_user) }
|
||||
|
||||
it "shows link and allows access to the report" do
|
||||
visit spree.admin_reports_path
|
||||
click_on I18n.t("admin.reports.enterprise_fee_summary.name")
|
||||
expect(page).to have_button("Go")
|
||||
end
|
||||
end
|
||||
|
||||
context "when accessing the report as an admin" do
|
||||
let(:current_user) { distributor.owner }
|
||||
|
||||
it "shows link and allows access to the report" do
|
||||
visit spree.admin_reports_path
|
||||
click_on I18n.t("admin.reports.enterprise_fee_summary.name")
|
||||
expect(page).to have_button("Go")
|
||||
end
|
||||
end
|
||||
|
||||
context "when accessing the report as an enterprise user without sufficient permissions" do
|
||||
let(:current_user) { create(:user) }
|
||||
|
||||
it "does not allow access to the report" do
|
||||
visit spree.admin_reports_path
|
||||
expect(page).to have_no_link(I18n.t("admin.reports.enterprise_fee_summary.name"))
|
||||
visit main_app.admin_report_path(report_type: 'enterprise_fee_summary')
|
||||
expect(page).to have_content(I18n.t("unauthorized"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "smoke test for filters" do
|
||||
before do
|
||||
visit main_app.admin_report_path(report_type: 'enterprise_fee_summary')
|
||||
end
|
||||
|
||||
context "when logged in as admin" do
|
||||
let(:current_user) { create(:admin_user) }
|
||||
|
||||
it "shows all available options" do
|
||||
expect(page).to have_select "q_order_cycle_ids", with_options: [order_cycle.name]
|
||||
end
|
||||
end
|
||||
|
||||
context "when logged in as enterprise user" do
|
||||
let!(:order) do
|
||||
create(:completed_order_with_fees, order_cycle: order_cycle,
|
||||
distributor: distributor)
|
||||
end
|
||||
let(:current_user) { distributor.owner }
|
||||
|
||||
it "shows available options for the enterprise" do
|
||||
expect(page).to have_select "q_order_cycle_ids", options: [order_cycle.name]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "csv downloads" do
|
||||
around do |example|
|
||||
with_empty_downloads_folder { example.run }
|
||||
end
|
||||
|
||||
describe "smoke test for generation of report based on permissions" do
|
||||
before do
|
||||
visit main_app.admin_report_path(report_type: 'enterprise_fee_summary')
|
||||
end
|
||||
|
||||
context "when logged in as admin" do
|
||||
let!(:order) do
|
||||
create(:completed_order_with_fees, order_cycle: order_cycle,
|
||||
distributor: distributor)
|
||||
end
|
||||
let(:current_user) { create(:admin_user) }
|
||||
|
||||
it "generates file with data for all enterprises" do
|
||||
check I18n.t("filters.report_format_csv", scope: i18n_scope)
|
||||
click_on "Go"
|
||||
|
||||
expect(downloaded_filename).to include ".csv"
|
||||
expect(downloaded_content).to have_content(distributor.name)
|
||||
end
|
||||
end
|
||||
|
||||
context "when logged in as enterprise user" do
|
||||
let!(:order) do
|
||||
create(:completed_order_with_fees, order_cycle: order_cycle,
|
||||
distributor: distributor)
|
||||
end
|
||||
let!(:other_order) do
|
||||
create(:completed_order_with_fees, order_cycle: other_order_cycle,
|
||||
distributor: other_distributor)
|
||||
end
|
||||
let(:current_user) { distributor.owner }
|
||||
|
||||
it "generates file with data for the enterprise" do
|
||||
check I18n.t("filters.report_format_csv", scope: i18n_scope)
|
||||
click_on "Go"
|
||||
|
||||
expect(downloaded_filename).to include ".csv"
|
||||
csv_content = downloaded_content
|
||||
expect(csv_content).to have_content(distributor.name)
|
||||
expect(csv_content).not_to have_content(other_distributor.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "smoke test for filtering report based on filters" do
|
||||
let!(:second_distributor) { create(:distributor_enterprise) }
|
||||
let!(:second_order_cycle) { create(:simple_order_cycle, coordinator: second_distributor) }
|
||||
|
||||
let!(:order) do
|
||||
create(:completed_order_with_fees, order_cycle: order_cycle,
|
||||
distributor: distributor)
|
||||
end
|
||||
let!(:second_order) do
|
||||
create(:completed_order_with_fees, order_cycle: second_order_cycle,
|
||||
distributor: second_distributor)
|
||||
end
|
||||
|
||||
let(:current_user) { create(:admin_user) }
|
||||
|
||||
before do
|
||||
visit main_app.admin_report_path(report_type: 'enterprise_fee_summary')
|
||||
end
|
||||
|
||||
it "generates file with data for selected order cycle" do
|
||||
select order_cycle.name, from: "report_order_cycle_ids"
|
||||
check I18n.t("filters.report_format_csv", scope: i18n_scope)
|
||||
click_on "Go"
|
||||
|
||||
expect(downloaded_filename).to include ".csv"
|
||||
csv_content = downloaded_content
|
||||
expect(csv_content).to have_content(distributor.name)
|
||||
expect(csv_content).not_to have_content(second_distributor.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def i18n_scope
|
||||
"order_management.reports.enterprise_fee_summaries"
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user