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.
This commit is contained in:
David Cook
2024-06-20 14:48:16 +10:00
parent 5b8f590520
commit 141a883e4d
2 changed files with 6 additions and 13 deletions

View File

@@ -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

View File

@@ -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