Remove report_inverse_columns_logic feature toggle

Co-Authored-By: Maikel <maikel@email.org.au>
This commit is contained in:
Jean-Baptiste Bellet
2022-10-20 11:27:05 +02:00
parent 48e18b016a
commit 02787e668f
8 changed files with 135 additions and 209 deletions

View File

@@ -46,14 +46,11 @@ module Admin
# Initialize data
params[:display_summary_row] = true if request.get?
if OpenFoodNetwork::FeatureToggle.enabled?(:report_inverse_columns_logic,
spree_current_user)
@params_fields_to_show = if request.get?
@report.columns.keys
else
params[:fields_to_show]
end
end
@params_fields_to_show = if request.get?
@report.columns.keys
else
params[:fields_to_show]
end
@data = Reporting::FrontendData.new(spree_current_user)
end

View File

@@ -1,11 +1,5 @@
- if @report_subtypes.present? && @report_subtypes.count > 1
- if feature?(:report_inverse_columns_logic, spree_current_user)
%input{type: 'hidden', name: 'report_subtype', value: @report_subtype}
- else
.row
.alpha.two.columns= label_tag nil, t(:report_type)
.omega.fourteen.columns
= select_tag(:report_subtype, options_for_select(@report_subtypes, @report_subtype))
%input{type: 'hidden', name: 'report_subtype', value: @report_subtype}
.row.rendering-options{ "data-controller": "csv-select" }
.alpha.two.columns
@@ -31,12 +25,7 @@
- if @report.available_headers.present?
.row
- if feature? :report_inverse_columns_logic, spree_current_user
.alpha.two.columns= label_tag nil, t(:report_columns)
.omega.fourteen.columns
= render MultipleCheckedSelectComponent.new(name: "fields_to_show", options: @report.available_headers, selected: @params_fields_to_show)
- else
.alpha.two.columns= label_tag nil, t(:report_hide_columns)
.omega.fourteen.columns
= select_tag(:fields_to_hide, options_for_select(@report.available_headers, params[:fields_to_hide]),
class: "select2 fullwidth", multiple: true)
.alpha.two.columns= label_tag nil, t(:report_columns)
.omega.fourteen.columns
= render MultipleCheckedSelectComponent.new(name: "fields_to_show", options: @report.available_headers, selected: @params_fields_to_show)

View File

@@ -17,7 +17,6 @@
%td
- begin
= I18n.t!(:description, scope: [:admin, :reports, report_type])
- if feature? :report_inverse_columns_logic, spree_current_user
= render partial: "report_subtype", locals: { report_subtypes: report_subtypes, report_type: report_type }
= render partial: "report_subtype", locals: { report_subtypes: report_subtypes, report_type: report_type }
- rescue I18n::MissingTranslationData
= render partial: "report_subtype", locals: { report_subtypes: report_subtypes, report_type: report_type }

View File

@@ -10,12 +10,7 @@ module Reporting
end
def table_headers
filter = if OpenFoodNetwork::FeatureToggle.enabled?(:report_inverse_columns_logic,
@current_user)
proc { |key| key.to_sym.in?(fields_to_show) }
else
proc { |key| !key.to_sym.in?(fields_to_hide) }
end
filter = proc { |key| key.to_sym.in?(fields_to_show) }
report.columns.keys.filter { |key| filter.call(key) }.map do |key|
translate_header(key)
end

View File

@@ -28,12 +28,8 @@ module Reporting
end
def slice_and_format_row(row)
result = if OpenFoodNetwork::FeatureToggle.enabled?(:report_inverse_columns_logic,
@current_user)
row.to_h.select { |k, _v| k.in?(report.fields_to_show) }
else
row.to_h.reject { |k, _v| k.in?(report.fields_to_hide) }
end
result = row.to_h.select { |k, _v| k.in?(report.fields_to_show) }
unless report.raw_render?
result = result.map { |k, v| [k, format_cell(v, k)] }.to_h
end

View File

@@ -101,28 +101,7 @@ module Reporting
check_report
end
describe "fields_to_hide" do
before do
allow(OpenFoodNetwork::FeatureToggle).to receive(:enabled?).with(
:report_inverse_columns_logic, anything
).and_return(false)
end
let(:params) { { fields_to_hide: [:product] } }
it "works" do
@expected_headers = ['Hub', 'Price']
check_report
end
end
describe "fields_to_show" do
before do
allow(OpenFoodNetwork::FeatureToggle).to receive(:enabled?).with(
:report_inverse_columns_logic, anything
).and_return(true)
end
let(:params) { { fields_to_show: [:hub, :price] } }
it "works" do

View File

@@ -31,12 +31,12 @@ describe "Payments Reports" do
create(:line_item_with_shipment, order: other_order, product: product)
login_as_admin
visit main_app.admin_report_path(report_type: 'payments')
visit admin_reports_path
end
context "when choosing itemised payments report type" do
it "shows orders with payment state, their balance and totals" do
select I18n.t(:report_itemised_payment), from: "report_subtype"
click_link "Itemised Payment Totals"
find("[type='submit']").click
expect(page.find("table.report__table thead tr").text).to have_content([
@@ -71,7 +71,7 @@ describe "Payments Reports" do
}
it 'shows orders with payment state, their balance and and payment totals' do
select I18n.t(:report_payment_totals), from: "report_subtype"
click_link "Payment Totals"
find("[type='submit']").click
expect(page.find("table.report__table thead tr").text).to have_content([

View File

@@ -31,55 +31,35 @@ describe '
end
end
shared_examples "Can access Customers reports and generate report" do |inverse_columns_logic|
describe "Can access Customers reports and generate customers report" do
before do
allow(OpenFoodNetwork::FeatureToggle).to receive(:enabled?).and_call_original
allow(OpenFoodNetwork::FeatureToggle).to receive(:enabled?).with(
:report_inverse_columns_logic, anything
).and_return(inverse_columns_logic)
login_as_admin_and_visit admin_reports_path
end
describe "Customers report" do
before do
login_as_admin_and_visit admin_reports_path
end
it "customers report" do
click_link "Mailing List"
click_button "Go"
it "customers report" do
click_link "Mailing List"
unless inverse_columns_logic
expect(page).to have_select('report_subtype',
selected: 'Mailing List')
end
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([
["Email", "First Name", "Last Name", "Suburb"].map(&:upcase)
].sort)
end
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([
["Email", "First Name", "Last Name", "Suburb"].map(&:upcase)
].sort)
end
it "customers report" do
click_link "Addresses"
click_button "Go"
it "customers report" do
click_link "Addresses"
unless inverse_columns_logic
expect(page).to have_select('report_subtype',
selected: 'Addresses')
end
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([
["First Name", "Last Name", "Billing Address", "Email", "Phone", "Hub", "Hub Address",
"Shipping Method"].map(&:upcase)
].sort)
end
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([
["First Name", "Last Name", "Billing Address", "Email", "Phone", "Hub", "Hub Address",
"Shipping Method"].map(&:upcase)
].sort)
end
end
it_behaves_like "Can access Customers reports and generate report", true
it_behaves_like "Can access Customers reports and generate report", false
describe "Order cycle management report" do
before do
login_as_admin_and_visit admin_reports_path
@@ -177,7 +157,7 @@ describe '
end
end
shared_examples "sales tax report" do |inverse_columns_logic|
context "sales tax report" do
let(:distributor1) {
create(:distributor_enterprise, with_payment_and_shipping: true, charges_sales_tax: true)
}
@@ -226,10 +206,6 @@ describe '
}
before do
allow(OpenFoodNetwork::FeatureToggle).to receive(:enabled?).and_call_original
allow(OpenFoodNetwork::FeatureToggle).to receive(:enabled?).with(
:report_inverse_columns_logic, anything
).and_return(inverse_columns_logic)
order1.reload
break unless order1.next! until order1.delivery?
@@ -245,12 +221,9 @@ describe '
end
it "generate Tax Types reports" do
if inverse_columns_logic
click_link "Tax Types"
else
click_link "Sales Tax"
select("Tax Types", from: "report_subtype")
end
click_link "Tax Types"
click_button "Go"
# Then it should give me access only to managed enterprises
expect(page).to have_select 'q_distributor_id_eq',
with_options: [user1.enterprises.first.name]
@@ -279,31 +252,16 @@ describe '
end
it "generate Tax Rates report" do
if inverse_columns_logic
click_link "Tax Rates"
else
click_link "Sales Tax"
select("Tax Rates", from: "report_subtype")
end
click_link "Tax Rates"
click_button "Go"
click_button 'Go'
expect(page).to have_css(".report__table thead th", text: "20.0% ($)")
expect(page).to have_css(".report__table thead th", text: "0.0% ($)")
if inverse_columns_logic.eql?("false")
expect(page).to have_table_row [order1.number.to_s, "1446.7", "16.76", "0", "270.08",
"286.84", "1733.54"]
end
if inverse_columns_logic.eql?("true")
expect(page).to have_table_row [order1.number.to_s, "1446.7", "0", "16.76", "270.08",
"286.84", "1733.54"]
end
expect(page).to have_table_row [order1.number.to_s, "1446.7", "16.76", "0", "270.08",
"286.84", "1733.54"]
end
end
it_behaves_like "sales tax report", false
it_behaves_like "sales tax report", true
describe "products and inventory report", js: true do
let(:supplier) { create(:supplier_enterprise, name: 'Supplier Name') }
let(:taxon) { create(:taxon, name: 'Taxon Name') }
@@ -426,12 +384,11 @@ describe '
describe 'bulk coop report' do
before do
login_as_admin_and_visit admin_reports_path
click_link 'Bulk Co-Op'
end
it "generating Bulk Co-op Supplier Report" do
select "Bulk Co-op Supplier Report", from: "report_subtype"
click_button 'Go'
click_link "Bulk Co-op Supplier Report"
click_button "Go"
expect(page).to have_table_row [
"Supplier",
@@ -449,8 +406,8 @@ describe '
end
it "generating Bulk Co-op Allocation report" do
select "Bulk Co-op Allocation", from: "report_subtype"
click_button 'Go'
click_link "Bulk Co-op Allocation"
click_button "Go"
expect(page).to have_table_row [
"Customer",
@@ -468,8 +425,8 @@ describe '
end
it "generating Bulk Co-op Packing Sheets report" do
select "Bulk Co-op Packing Sheets", from: "report_subtype"
click_button 'Go'
click_link "Bulk Co-op Packing Sheets"
click_button "Go"
expect(page).to have_table_row [
"Customer",
@@ -480,8 +437,8 @@ describe '
end
it "generating Bulk Co-op Customer Payments report" do
select "Bulk Co-op Customer Payments", from: "report_subtype"
click_button 'Go'
click_link "Bulk Co-op Customer Payments"
click_button "Go"
expect(page).to have_table_row [
"Customer",
@@ -581,9 +538,6 @@ describe '
Timecop.travel(Time.zone.local(2021, 4, 25, 14, 0, 0)) { order1.finalize! }
order1.reload
order1.create_tax_charge!
login_as_admin_and_visit admin_reports_path
click_link 'Xero Invoices'
end
around do |example|
@@ -592,76 +546,93 @@ describe '
end
end
it "shows Xero invoices report" do
click_button "Go"
expect(xero_invoice_table).to match_table [
xero_invoice_header,
xero_invoice_summary_row('Total untaxable produce (no tax)', 12.54,
'GST Free Income'),
xero_invoice_summary_row('Total taxable produce (tax inclusive)', 1500.45,
'GST on Income'),
xero_invoice_summary_row('Total untaxable fees (no tax)', 10.0,
'GST Free Income'),
xero_invoice_summary_row('Total taxable fees (tax inclusive)', 20.0, 'GST on Income'),
xero_invoice_summary_row('Delivery Shipping Cost (tax inclusive)', 100.55,
'GST on Income'),
xero_invoice_summary_row('Total untaxable admin adjustments (no tax)', 30.0,
'GST Free Income'),
xero_invoice_summary_row('Total taxable admin adjustments (tax inclusive)', 40.0,
'GST on Income')
]
context "summary report" do
before do
login_as_admin_and_visit admin_reports_path
click_link "Summary"
click_button 'Go'
end
it "shows Xero invoices report" do
expect(xero_invoice_table).to match_table [
xero_invoice_header,
xero_invoice_summary_row('Total untaxable produce (no tax)', 12.54,
'GST Free Income'),
xero_invoice_summary_row('Total taxable produce (tax inclusive)', 1500.45,
'GST on Income'),
xero_invoice_summary_row('Total untaxable fees (no tax)', 10.0,
'GST Free Income'),
xero_invoice_summary_row('Total taxable fees (tax inclusive)', 20.0,
'GST on Income'),
xero_invoice_summary_row('Delivery Shipping Cost (tax inclusive)', 100.55,
'GST on Income'),
xero_invoice_summary_row('Total untaxable admin adjustments (no tax)', 30.0,
'GST Free Income'),
xero_invoice_summary_row('Total taxable admin adjustments (tax inclusive)', 40.0,
'GST on Income')
]
end
it "can customise a number of fields" do
fill_in 'initial_invoice_number', with: '5'
pick_datetime '#invoice_date', Date.new(2021, 2, 12)
pick_datetime '#due_date', Date.new(2021, 3, 12)
fill_in 'account_code', with: 'abc123'
click_button 'Go'
opts = { invoice_number: '5', invoice_date: '2021-02-12',
due_date: '2021-03-12', account_code: 'abc123' }
expect(xero_invoice_table).to match_table [
xero_invoice_header,
xero_invoice_summary_row('Total untaxable produce (no tax)', 12.54,
'GST Free Income', opts),
xero_invoice_summary_row('Total taxable produce (tax inclusive)', 1500.45,
'GST on Income', opts),
xero_invoice_summary_row('Total untaxable fees (no tax)', 10.0,
'GST Free Income', opts),
xero_invoice_summary_row('Total taxable fees (tax inclusive)', 20.0,
'GST on Income', opts),
xero_invoice_summary_row('Delivery Shipping Cost (tax inclusive)', 100.55,
'GST on Income', opts),
xero_invoice_summary_row('Total untaxable admin adjustments (no tax)', 30.0,
'GST Free Income', opts),
xero_invoice_summary_row('Total taxable admin adjustments (tax inclusive)', 40.0,
'GST on Income', opts)
]
end
end
it "can customise a number of fields" do
fill_in 'initial_invoice_number', with: '5'
context "detailed report" do
before do
login_as_admin_and_visit admin_reports_path
click_link "Detailed"
click_button 'Go'
end
pick_datetime '#invoice_date', Date.new(2021, 2, 12)
pick_datetime '#due_date', Date.new(2021, 3, 12)
it "generates a detailed report" do
login_as_admin_and_visit admin_reports_path
click_link "Detailed"
click_button 'Go'
fill_in 'account_code', with: 'abc123'
click_button 'Go'
opts = {}
opts = { invoice_number: '5', invoice_date: '2021-02-12',
due_date: '2021-03-12', account_code: 'abc123' }
expect(xero_invoice_table).to match_table [
xero_invoice_header,
xero_invoice_summary_row('Total untaxable produce (no tax)', 12.54,
'GST Free Income', opts),
xero_invoice_summary_row('Total taxable produce (tax inclusive)', 1500.45,
'GST on Income', opts),
xero_invoice_summary_row('Total untaxable fees (no tax)', 10.0,
'GST Free Income', opts),
xero_invoice_summary_row('Total taxable fees (tax inclusive)', 20.0,
'GST on Income', opts),
xero_invoice_summary_row('Delivery Shipping Cost (tax inclusive)', 100.55,
'GST on Income', opts),
xero_invoice_summary_row('Total untaxable admin adjustments (no tax)', 30.0,
'GST Free Income', opts),
xero_invoice_summary_row('Total taxable admin adjustments (tax inclusive)', 40.0,
'GST on Income', opts)
]
end
it "generates a detailed report" do
select 'Detailed', from: 'report_subtype'
click_button 'Go'
opts = {}
expect(xero_invoice_table).to match_table [
xero_invoice_header,
xero_invoice_li_row(line_item1),
xero_invoice_li_row(line_item2),
xero_invoice_adjustment_row(adj_admin1),
xero_invoice_adjustment_row(adj_admin2),
xero_invoice_summary_row('Total untaxable fees (no tax)', 10.0,
'GST Free Income', opts),
xero_invoice_summary_row('Total taxable fees (tax inclusive)', 20.0,
'GST on Income', opts),
xero_invoice_summary_row('Delivery Shipping Cost (tax inclusive)', 100.55,
'GST on Income', opts)
]
expect(xero_invoice_table).to match_table [
xero_invoice_header,
xero_invoice_li_row(line_item1),
xero_invoice_li_row(line_item2),
xero_invoice_adjustment_row(adj_admin1),
xero_invoice_adjustment_row(adj_admin2),
xero_invoice_summary_row('Total untaxable fees (no tax)', 10.0,
'GST Free Income', opts),
xero_invoice_summary_row('Total taxable fees (tax inclusive)', 20.0,
'GST on Income', opts),
xero_invoice_summary_row('Delivery Shipping Cost (tax inclusive)', 100.55,
'GST on Income', opts)
]
end
end
end