From 141a883e4dc858aa95449c7d129cfe743169a52f Mon Sep 17 00:00:00 2001 From: David Cook Date: Thu, 20 Jun 2024 14:48:16 +1000 Subject: [PATCH] Refactor report So it turns out that all these features are built into the report framework. LineItems includes complete_not_canceled_visible_orders. It even takes care of masking non-editable orders. --- .../reports/orders_and_distributors/base.rb | 17 ++++++----------- .../orders_and_distributors_report_spec.rb | 2 -- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/lib/reporting/reports/orders_and_distributors/base.rb b/lib/reporting/reports/orders_and_distributors/base.rb index 2f54235d5e..a9cf0a2128 100644 --- a/lib/reporting/reports/orders_and_distributors/base.rb +++ b/lib/reporting/reports/orders_and_distributors/base.rb @@ -32,20 +32,11 @@ module Reporting # rubocop:enable Metrics/AbcSize def search - permissions.visible_orders.select("DISTINCT spree_orders.*"). - complete.not_state(:canceled). - ransack(ransack_params) + report_line_items.list end def query_result - orders = search.result - # Mask non editable order details - editable_orders_ids = permissions.editable_orders.select(&:id).map(&:id) - orders - .filter { |order| order.in?(editable_orders_ids) } - .each { |order| Orders::MaskDataService.new(order).call } - # Get Line Items - orders.map(&:line_items).flatten + search end private @@ -53,6 +44,10 @@ module Reporting def permissions @permissions ||= ::Permissions::Order.new(user, ransack_params) end + + def report_line_items + @report_line_items ||= Reporting::LineItems.new(permissions, params) + end end end end diff --git a/spec/lib/reports/orders_and_distributors_report_spec.rb b/spec/lib/reports/orders_and_distributors_report_spec.rb index ff23b9e63b..58374912f9 100644 --- a/spec/lib/reports/orders_and_distributors_report_spec.rb +++ b/spec/lib/reports/orders_and_distributors_report_spec.rb @@ -115,7 +115,6 @@ RSpec.describe Reporting::Reports::OrdersAndDistributors::Base do end it "shows line items supplied by my producers, with contact details hidden" do - pending '#12559' expect(row).not_to include("FirstName LastName") expect(row).not_to include("123-456", "City", order.email) expect(row[2..5]).to eq ["HIDDEN", "HIDDEN", "", ""] @@ -128,7 +127,6 @@ RSpec.describe Reporting::Reports::OrdersAndDistributors::Base do it "shows line items supplied by my producers, with only contact names shown" do expect(row).to include("FirstName LastName") - pending '#12559' expect(row).not_to include("123-456", "City", order.email) expect(row[2..5]).to eq [bill_address.full_name, "HIDDEN", "", ""] end