From 02787e668f71963e8e9f0789968ab45b8f7b8a66 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Thu, 20 Oct 2022 11:27:05 +0200 Subject: [PATCH 1/5] Remove `report_inverse_columns_logic` feature toggle Co-Authored-By: Maikel --- app/controllers/admin/reports_controller.rb | 13 +- .../reports/_rendering_options.html.haml | 21 +- app/views/admin/reports/index.html.haml | 3 +- lib/reporting/report_headers_builder.rb | 7 +- lib/reporting/report_row_builder.rb | 8 +- spec/lib/reports/report_spec.rb | 21 -- .../admin/reports/payments_report_spec.rb | 6 +- spec/system/admin/reports_spec.rb | 265 ++++++++---------- 8 files changed, 135 insertions(+), 209 deletions(-) diff --git a/app/controllers/admin/reports_controller.rb b/app/controllers/admin/reports_controller.rb index 35c9b5891a..01e6757347 100644 --- a/app/controllers/admin/reports_controller.rb +++ b/app/controllers/admin/reports_controller.rb @@ -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 diff --git a/app/views/admin/reports/_rendering_options.html.haml b/app/views/admin/reports/_rendering_options.html.haml index db1b543d24..8ba2a4a1ba 100644 --- a/app/views/admin/reports/_rendering_options.html.haml +++ b/app/views/admin/reports/_rendering_options.html.haml @@ -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) + \ No newline at end of file diff --git a/app/views/admin/reports/index.html.haml b/app/views/admin/reports/index.html.haml index 132653a982..0c95482d0e 100644 --- a/app/views/admin/reports/index.html.haml +++ b/app/views/admin/reports/index.html.haml @@ -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 } diff --git a/lib/reporting/report_headers_builder.rb b/lib/reporting/report_headers_builder.rb index 824394536c..29291ac56b 100644 --- a/lib/reporting/report_headers_builder.rb +++ b/lib/reporting/report_headers_builder.rb @@ -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 diff --git a/lib/reporting/report_row_builder.rb b/lib/reporting/report_row_builder.rb index 6b55e103df..882842cf34 100644 --- a/lib/reporting/report_row_builder.rb +++ b/lib/reporting/report_row_builder.rb @@ -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 diff --git a/spec/lib/reports/report_spec.rb b/spec/lib/reports/report_spec.rb index 964bd8f1bf..5ba8f9a4ba 100644 --- a/spec/lib/reports/report_spec.rb +++ b/spec/lib/reports/report_spec.rb @@ -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 diff --git a/spec/system/admin/reports/payments_report_spec.rb b/spec/system/admin/reports/payments_report_spec.rb index 2f55d63d1d..49e1a85cee 100644 --- a/spec/system/admin/reports/payments_report_spec.rb +++ b/spec/system/admin/reports/payments_report_spec.rb @@ -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([ diff --git a/spec/system/admin/reports_spec.rb b/spec/system/admin/reports_spec.rb index aee4705bf0..676feedf41 100644 --- a/spec/system/admin/reports_spec.rb +++ b/spec/system/admin/reports_spec.rb @@ -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 From edc667a3362d5c322e59a072dd3d543c5900cb47 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Thu, 20 Oct 2022 14:46:07 +0200 Subject: [PATCH 2/5] By default, some columns are hidden. --- app/controllers/admin/reports_controller.rb | 2 +- spec/controllers/admin/reports_controller_spec.rb | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/admin/reports_controller.rb b/app/controllers/admin/reports_controller.rb index 01e6757347..7f00bb32a4 100644 --- a/app/controllers/admin/reports_controller.rb +++ b/app/controllers/admin/reports_controller.rb @@ -47,7 +47,7 @@ module Admin # Initialize data params[:display_summary_row] = true if request.get? @params_fields_to_show = if request.get? - @report.columns.keys + @report.columns.keys - @report.fields_to_hide else params[:fields_to_show] end diff --git a/spec/controllers/admin/reports_controller_spec.rb b/spec/controllers/admin/reports_controller_spec.rb index c367c33712..0fcd50a369 100644 --- a/spec/controllers/admin/reports_controller_spec.rb +++ b/spec/controllers/admin/reports_controller_spec.rb @@ -251,6 +251,7 @@ describe Admin::ReportsController, type: :controller do allow(report).to receive(:table_headers).and_return [] allow(report).to receive(:table_rows).and_return [] allow(report).to receive(:columns).and_return({}) + allow(report).to receive(:fields_to_hide).and_return([]) spree_get :show, report_type: :products_and_inventory, test: "foo" expect(assigns(:report)).to eq(report) end @@ -302,6 +303,7 @@ describe Admin::ReportsController, type: :controller do allow(report).to receive(:table_headers).and_return [] allow(report).to receive(:table_rows).and_return [] allow(report).to receive(:columns).and_return({}) + allow(report).to receive(:fields_to_hide).and_return([]) spree_get :show, report_type: :customers, test: "foo" expect(assigns(:report)).to eq(report) end From 1c349049d1ffdbbe51dff516746e231d10e13ad7 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Thu, 20 Oct 2022 14:49:53 +0200 Subject: [PATCH 3/5] Remove report description when they are useless --- app/views/admin/reports/index.html.haml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/views/admin/reports/index.html.haml b/app/views/admin/reports/index.html.haml index 0c95482d0e..d169ce1139 100644 --- a/app/views/admin/reports/index.html.haml +++ b/app/views/admin/reports/index.html.haml @@ -15,8 +15,6 @@ - url = main_app.admin_report_url(report_type: report_type) = link_to name, url %td - - begin + - if report_subtypes.empty? = I18n.t!(:description, scope: [:admin, :reports, 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 } + = render partial: "report_subtype", locals: { report_subtypes: report_subtypes, report_type: report_type } From 6dec80aaaf2cecc17abb9d5d62781ee145c9b5b3 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Thu, 20 Oct 2022 14:51:19 +0200 Subject: [PATCH 4/5] Links only on right side --- app/views/admin/reports/index.html.haml | 8 ++++---- spec/system/admin/reports_spec.rb | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/views/admin/reports/index.html.haml b/app/views/admin/reports/index.html.haml index d169ce1139..9ec68931fa 100644 --- a/app/views/admin/reports/index.html.haml +++ b/app/views/admin/reports/index.html.haml @@ -11,10 +11,10 @@ - @reports.each do |report_type, report_subtypes| %tr %td - - name = I18n.t(:name, scope: [:admin, :reports, report_type]) - - url = main_app.admin_report_url(report_type: report_type) - = link_to name, url + = I18n.t(:name, scope: [:admin, :reports, report_type]) %td - if report_subtypes.empty? - = I18n.t!(:description, scope: [:admin, :reports, report_type]) + - name = I18n.t(:name, scope: [:admin, :reports, report_type]) + - url = main_app.admin_report_url(report_type: report_type) + = link_to name, url = render partial: "report_subtype", locals: { report_subtypes: report_subtypes, report_type: report_type } diff --git a/spec/system/admin/reports_spec.rb b/spec/system/admin/reports_spec.rb index 676feedf41..a8a9f734b9 100644 --- a/spec/system/admin/reports_spec.rb +++ b/spec/system/admin/reports_spec.rb @@ -135,7 +135,7 @@ describe ' end it "generates the payments reports" do - click_link 'Payment Reports' + click_link 'Payments By Type' click_button 'Go' rows = find("table.report__table").all("thead tr") @@ -298,7 +298,7 @@ describe ' expect(page).to have_content "All products" expect(page).to have_content "Inventory (on hand)" - click_link 'Products & Inventory' + click_link 'All products' click_button "Go" expect(page).to have_content "Supplier" expect(page).to have_table_row ["Supplier", "Producer Suburb", "Product", From e2441cdcf697f0c6ea60503d16acdfc9dd87df5b Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Thu, 20 Oct 2022 15:29:50 +0200 Subject: [PATCH 5/5] Use the report type or subtype as the title --- app/controllers/admin/reports_controller.rb | 5 +++++ app/controllers/concerns/reports_actions.rb | 4 ++++ app/views/admin/reports/show.html.haml | 3 +++ 3 files changed, 12 insertions(+) diff --git a/app/controllers/admin/reports_controller.rb b/app/controllers/admin/reports_controller.rb index 7f00bb32a4..9c88a0bd09 100644 --- a/app/controllers/admin/reports_controller.rb +++ b/app/controllers/admin/reports_controller.rb @@ -43,6 +43,11 @@ module Admin @report_type = report_type @report_subtypes = report_subtypes @report_subtype = report_subtype + @report_title = if report_subtype + report_subtype_title + else + I18n.t(:name, scope: [:admin, :reports, @report_type]) + end # Initialize data params[:display_summary_row] = true if request.get? diff --git a/app/controllers/concerns/reports_actions.rb b/app/controllers/concerns/reports_actions.rb index 35a508b154..6cd9e5157c 100644 --- a/app/controllers/concerns/reports_actions.rb +++ b/app/controllers/concerns/reports_actions.rb @@ -39,6 +39,10 @@ module ReportsActions params[:report_subtype] || report_subtypes_codes.first end + def report_subtype_title + report_subtypes.select { |_name, key| key.to_sym == report_subtype.to_sym }.first[0] + end + def ransack_params raw_params[:q] end diff --git a/app/views/admin/reports/show.html.haml b/app/views/admin/reports/show.html.haml index 3fc60d9d8b..caebd55c83 100644 --- a/app/views/admin/reports/show.html.haml +++ b/app/views/admin/reports/show.html.haml @@ -1,3 +1,6 @@ +- content_for :page_title do + = @report_title + = form_for @report.search, :url => url_for(only_path: false) do |f| %fieldset.no-border-bottom.print-hidden %legend{ align: 'center'}= t(:report_filters)