Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Removed the legacy Spree::Report system

Damian Legawiec50494012e22a
diff --git a/docs/developer/core-concepts/reporting.mdx b/docs/developer/core-concepts/reporting.mdx
index fb2121adb8..311c5c524f 100644
--- a/docs/developer/core-concepts/reporting.mdx
+++ b/docs/developer/core-concepts/reporting.mdx
@@ -259,22 +259,6 @@ as `Spree::Exports::Report`, so it inherits the background job, attachment and
email. The export re-authorizes its members against the requesting user, which
is why it requires a user and API keys cannot queue one.
-## Relationship to `Spree::Report`
-
-`Spree::Report` still exists and still works. It is a **row-level CSV
-exporter** — one line per record, with attachment and mailer plumbing.
-
-The two answer different questions:
-
-| Question | Use |
-|----------|-----|
-| "Revenue by channel last quarter" | Reporting layer (aggregates, composable) |
-| "Every order line in March, as a spreadsheet" | `Spree::Report` (row-level export) |
-
-New report *types* for analytics are no longer accepted into core: register
-metrics and dimensions instead. See
-[Extend reporting](/developer/how-to/extend-reporting).
-
## Current limits
Worth knowing before you design an extension:
diff --git a/docs/developer/how-to/extend-reporting.mdx b/docs/developer/how-to/extend-reporting.mdx
index 67ab510fb7..9d4f016281 100644
--- a/docs/developer/how-to/extend-reporting.mdx
+++ b/docs/developer/how-to/extend-reporting.mdx
@@ -13,13 +13,6 @@ schema endpoint.
Read [how reporting works](/developer/core-concepts/reporting) first — this
guide assumes the query contract and the metric/dimension split.
-<Note>
-Upgrading from the `Spree::Report` / `ReportLineItem` pattern? That API still
-works for row-level CSV exports and is documented under
-[Build a Custom Report](/v5/developer/how-to/custom-report). For aggregate
-questions, register vocabulary instead.
-</Note>
-
## Add a metric
A metric is an aggregate over one registered base — `:orders`, `:line_items`,
@@ -216,4 +209,4 @@ the same clock, as an existing one.
- [Reporting](/developer/core-concepts/reporting) — the concepts
- [Permissions](/developer/dashboard/customization/permissions) — scopes and subjects
-- [Build a Custom Report](/v5/developer/how-to/custom-report) — the row-level CSV exporter
+- [Imports and exports](/developer/core-concepts/imports-exports) — row-level CSV
diff --git a/docs/developer/upgrades/5.6-to-6.0.mdx b/docs/developer/upgrades/5.6-to-6.0.mdx
index 375f6847d0..2791b46aaa 100644
--- a/docs/developer/upgrades/5.6-to-6.0.mdx
+++ b/docs/developer/upgrades/5.6-to-6.0.mdx
@@ -584,6 +584,18 @@ to `Spree::Base`.
The `spree_state_changes` and `spree_log_entries` tables are **not dropped until 6.1**, so your existing rows survive the upgrade. If you want the history long-term, export it before upgrading to 6.1.
+### `Spree::Report` is gone
+
+`Spree::Report`, its `Reports::SalesTotal` and `Reports::ProductsPerformance` subclasses, `Spree::ReportLineItem` and its subclasses, `Spree::ReportMailer`, `Spree::ReportSubscriber`, `Spree::Reports::GenerateJob`, the `Spree.reports` registry and the `reports` queue entry are all removed, along with the `reports` associations on `Spree::Store` and the admin user.
+
+Nothing in 5.6 could reach it: there was no API endpoint and no admin screen, so a report could only be created from Ruby.
+
+**Where each question goes now.** Aggregates — revenue by channel, product performance, anything you would have written a report class for — are [reporting](/developer/core-concepts/reporting) queries, composed from registered metrics and dimensions rather than a class per question. Row-level CSV of records is a `Spree::Export` subclass, which is what [imports and exports](/developer/core-concepts/imports-exports) covers, and unlike `Spree::Report` it has both an Admin API and a dashboard page.
+
+**Your rows are safe.** The `spree_reports` and `spree_report_line_items` tables are left exactly as they are — nothing reads them, and no migration drops them. A store installing 6.0 fresh never creates them. If you want the old report history, export it whenever suits you; there is no deadline.
+
+If you subclassed `Spree::Report` in your own application, that class no longer has a superclass and will raise on boot. Move the question to one of the two replacements above.
+
## Deprecated in 6.0, removed in 6.1
Every rename keeps the legacy name working for one release with a deprecation warning. The notable ones:
diff --git a/docs/plans/6.0-analytics-semantic-layer.md b/docs/plans/6.0-analytics-semantic-layer.md
index 9e8bf52f53..b08397a140 100644
--- a/docs/plans/6.0-analytics-semantic-layer.md
+++ b/docs/plans/6.0-analytics-semantic-layer.md
@@ -4,7 +4,7 @@
**Target:** Spree 6.0 (core + new dashboard home + Reports page) → 6.1 (facts adapter, AI) — Enterprise ClickHouse adapter out of band
**Depends on:** `6.0-admin-api.md` (v3 conventions), `5.5-admin-api-key-scopes.md` (scope gating), `6.0-multi-vendor-marketplace.md` (vendor forced scope + vendor dashboard consumer), `5.5-admin-api-cli.md` (first agent surface), `5.6-solid-queue-single-container.md` (fact writes + reconciliation jobs)
**Author:** Damian + Claude
-**Last updated:** 2026-09-11 (Decision 15: counters join the registry and serve the sidebar badges too; low stock threshold becomes a store preference)
+**Last updated:** 2026-09-11 (Decision 16: the legacy `Spree::Report` system is removed)
## Summary
@@ -93,7 +93,7 @@ Aggregates compute on decimal columns (`pre_tax_amount`, `total`). Floats never
The registry serializes into the tool schema (same source as the OpenAPI spec), so the model cannot reference a metric that doesn't exist; validation errors are recoverable in the agent loop; forced scopes hold below the LLM. Read-only — no mutation confirmation gate needed. First agent surface is the CLI (`spree api post /reporting/query`, per `5.5-admin-api-cli.md`), ahead of any in-app agent or MCP.
-### 10. `Spree::Report` stays; its authoring role ends
+### 10. `Spree::Report` stays; its authoring role ends — **superseded 2026-09-11 (Decision 16)**
`Spree::Report` is a row-level CSV exporter with attachment/mailer plumbing — orthogonal, keeps working. It is no longer the thing developers extend to answer aggregate questions; new report *types* for analytics purposes are not accepted into core once the registry lands. (Long term the CSV export path can consume the semantic layer for aggregate exports; row-level exports remain `Spree::Report`'s job.)
@@ -196,6 +196,14 @@ does not send us the data. That is now the only recorded gap.
The home screen's Operations card was the last hand-rolled number surface: five counts as private methods on a serializer in the API gem, five matching icon-plus-filter rows hardcoded in the dashboard, one permission (`read_dashboard`) covering all of them, and a `low_stock_threshold` request parameter the dashboard never sent. **Counters now join `Spree.reporting`** as a fourth member type beside metrics, dimensions and bases: `registry.counter :name, count: ->(store, channel:) { … }, subject:, key_scope:, link:, description:`. They are not compiled into the query (no range, no currency, no base — a counter is the state of the store at this instant), so the registry only stores the lambda; `Spree::Reporting::Counters` evaluates them for one store and channel, filtered by the same `member_allowed?` predicate the schema and the query apply, now shared through `Admin::ReportingAuthorization`. `GET /dashboard/counters` returns `{ channel_id, counters: [{ key, label, description, value, link, nav }] }` and the dashboard renders whatever arrives, keeping only an icon map with a fallback. **One request serves the home card and every sidebar badge:** the three post-sale badges each used to spend a list request with `limit: 1` purely to read a total off the pagination meta, and the returns badge counted `received` while the counter did not — two definitions of the same number. Counters now carry the nav entry they badge, so the sidebar reads the shared response and an extension's counter badges its own entry with no dashboard release. **The shell loads them, not the badges:** the sidebar mounts only the children of the section being viewed, so a badge-driven request left every page outside Orders with no counts at all (a defect the three replaced badges shared), and a parent entry sums its own counter with its children's so the total survives a collapsed submenu. Labels resolve through `reporting.counters.<key>` in the locale the way metric labels do. **The link is declared beside the count** so the list a merchant lands on shows exactly the rows counted — the previous out-of-stock link pointed at a products filter the server silently dropped. **`low_stock_threshold` is a `Spree::Store` preference** (integer, default 5, 0 = off), edited under Settings → Store → Inventory and named in the counter's own description; neither reference platform has a per-variant threshold, and Shopify's inventory report bands by days of supply rather than a count, so store-level is the grain. Not `Spree.operations` (reserved) and not a second namespace — the plan's own line that "state metrics join the registry" is the design.
+### Decision 16 — The legacy `Spree::Report` system is removed (2026-09-11, supersedes Decision 10)
+
+Decision 10 kept `Spree::Report` on the grounds that it is a row-level CSV exporter and therefore orthogonal to this layer. That reasoning no longer holds. It has **no v3 route and no dashboard screen**, so a merchant cannot run one at all — it is reachable only from Ruby. Both subclasses core shipped, `Reports::SalesTotal` and `Reports::ProductsPerformance`, are aggregate questions this layer now answers as seeded reports. And the row-level niche it was kept for is already served by `Spree::Export` (`Exports::Orders` and friends), which unlike `Spree::Report` has an Admin API and a dashboard page.
+
+So the whole subsystem goes: `Spree::Report`, its two subclasses, `Spree::ReportLineItem` and its two subclasses, `Reports::GenerateJob`, `ReportMailer` and its view, `ReportSubscriber`, the v3 `ReportSerializer`, the `Spree.reports` registry, the `reports` queue, the mailer preview and factory, and the `Store` / admin-user associations.
+
+**The tables are not touched.** The migration that creates `spree_reports` and `spree_report_line_items` is deleted, so a fresh 6.0 install never creates them, while an existing store keeps its rows exactly where they are — inert, read by nothing, and available if a merchant wants to export them by hand. Dropping them is not scheduled; there is no data-loss moment to time.
+
## Design Details
### Registry (`spree/core`)
@@ -311,7 +319,7 @@ Chart/tile/ranking-row components become shape-generic (consume `ReportingResult
- **Facts adapter** (6.1): schema + event subscribers + reconciliation/backfill rakes + refund-restates-original-day rules, behind the same contract; opt-in, Live stays default.
- **In-app AI agent** on top of Step 10; Blazer-style checks/alerts on saved reports as a follow-up plan.
-Legacy surfaces: `Spree::Admin::AnalyticsConcern` untouched (legacy admin is maintenance-mode); `Spree::Report` untouched per Decision 10.
+Legacy surfaces: `Spree::Admin::AnalyticsConcern` untouched (legacy admin is maintenance-mode); `Spree::Report` removed per Decision 16.
## Constraints on Current Work
@@ -331,7 +339,7 @@ Legacy surfaces: `Spree::Admin::AnalyticsConcern` untouched (legacy admin is mai
- **Order-level money on another table is a correlated subquery**, never a join on the aggregating scope — an order with three refunds stays one row.
- **New filters are dimensions.** Register a dimension (with `resolve`/`hydrate`/`subject`/`key_scope` when it identifies a resource); never add filter-only parameters to the endpoint.
- **Keep forced-scope discipline**: all analytics queries go through store associations (`store.orders`, `store.line_items`, …), filter exactly one currency, and use `Order.for_channel` for optional channel scoping.
-- **Don't add new `Spree::Report` STI subclasses for aggregate questions**; row-level CSV exports only.
+- **`Spree::Report` is gone** (Decision 16) — aggregate questions are registry members, row-level CSV is a `Spree::Export`. Nothing may reference `Spree::Report`, `Spree::ReportLineItem` or `Spree.reports` again.
- **New time-bucketed queries must document their timezone**; prefer store timezone (Decision 7).
- **Don't adopt Blazer/rollup as dependencies** (Decision 11).
diff --git a/docs/plans/decisions.md b/docs/plans/decisions.md
index 3aca74dd0a..3e22f12873 100644
--- a/docs/plans/decisions.md
+++ b/docs/plans/decisions.md
@@ -1,3 +1,11 @@
+## 2026-09-11: The legacy Spree::Report system is removed, its tables left alone
+
+**Context:** `6.0-analytics-semantic-layer.md` Decision 10 kept `Spree::Report` alongside the new reporting layer, on the grounds that it is a row-level CSV exporter and so answers a different question. Reviewing it once the layer shipped, that separation does not survive contact: `Spree::Report` has no v3 route and no dashboard screen, so a merchant cannot run one at all; both subclasses core ships are aggregate questions the new layer now answers as seeded reports; and row-level CSV is already `Spree::Export`'s job, with the Admin API and dashboard page `Spree::Report` never had.
+
+**Decision:** Remove the subsystem — the STI base and its two subclasses, `ReportLineItem` and its two subclasses, the generate job, the mailer and its view, the subscriber, the v3 serializer and its dependency key, the `Spree.reports` registry, the `reports` queue entry, the mailer preview, the factory, and the `Store` and admin-user associations. **Leave the tables.** The creating migration is deleted so a fresh install never makes them, while existing stores keep every row, inert. No drop migration is scheduled — there is no data-loss moment to time, and a merchant who wants the history can still read it.
+
+**Consequences:** Aggregate questions are registry members (`Spree.reporting`); row-level CSV is a `Spree::Export` subclass. Nothing may reference `Spree::Report`, `Spree::ReportLineItem` or `Spree.reports` again. A host app that subclassed `Spree::Report` breaks on upgrade and has to move to one of the two replacements — accepted, since the class was unreachable from any shipped surface. Supersedes Decision 10 in `6.0-analytics-semantic-layer.md`.
+
## 2026-09-11: Counters are reporting registry members, and one request serves the home card and the sidebar
**Context:** `dashboard/operations` served five counts as private methods on a serializer in the API gem, the dashboard hardcoded the matching rows (icons, labels, deep-link filters), one permission covered all five, and the out-of-stock deep link pointed at a products filter the server silently dropped. The low stock threshold was a request parameter with a hardcoded default that nothing sent.
diff --git a/spree/api/app/serializers/spree/api/v3/report_serializer.rb b/spree/api/app/serializers/spree/api/v3/report_serializer.rb
deleted file mode 100644
index feafd2c2d0..0000000000
--- a/spree/api/app/serializers/spree/api/v3/report_serializer.rb
+++ /dev/null
@@ -1,34 +0,0 @@
-# frozen_string_literal: true
-
-module Spree
- module Api
- module V3
- class ReportSerializer < BaseSerializer
- typelize type: [:string, nullable: true],
- user_id: [:string, nullable: true],
- currency: [:string, nullable: true],
- date_from: [:string, nullable: true], date_to: [:string, nullable: true]
-
- attributes :currency
-
- # Wire shorthand (`"sales_total"`), not the Ruby class name — clients
- # shouldn't have to know or parse `Spree::Reports::SalesTotal`.
- attribute :type do |report|
- Spree::Report.api_type_for(report.type)
- end
-
- attribute :user_id do |report|
- report.user&.prefixed_id
- end
-
- attribute :date_from do |report|
- report.date_from&.iso8601
- end
-
- attribute :date_to do |report|
- report.date_to&.iso8601
- end
- end
- end
- end
-end
diff --git a/spree/api/lib/spree/api/dependencies.rb b/spree/api/lib/spree/api/dependencies.rb
index b356afd9d7..27ba1f3268 100644
--- a/spree/api/lib/spree/api/dependencies.rb
+++ b/spree/api/lib/spree/api/dependencies.rb
@@ -90,7 +90,6 @@ module Spree
newsletter_subscriber_serializer: 'Spree::Api::V3::NewsletterSubscriberSerializer',
promotion_serializer: 'Spree::Api::V3::PromotionSerializer',
refund_serializer: 'Spree::Api::V3::RefundSerializer',
- report_serializer: 'Spree::Api::V3::ReportSerializer',
stock_level_serializer: 'Spree::Api::V3::StockLevelSerializer',
stock_movement_serializer: 'Spree::Api::V3::StockMovementSerializer',
stock_reservation_serializer: 'Spree::Api::V3::StockReservationSerializer',
diff --git a/spree/api/spec/serializers/spree/api/v3/report_serializer_spec.rb b/spree/api/spec/serializers/spree/api/v3/report_serializer_spec.rb
deleted file mode 100644
index 539df6592d..0000000000
--- a/spree/api/spec/serializers/spree/api/v3/report_serializer_spec.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe Spree::Api::V3::ReportSerializer do
- let(:store) { @default_store }
- let(:report) { create(:report) }
- let(:base_params) { { store: store, currency: 'USD' } }
-
- subject { described_class.new(report, params: base_params).to_h }
-
- it 'includes all expected attributes' do
- expect(subject.keys).to match_array(%w[
- id type user_id currency date_from date_to
- ])
- end
-
- it 'returns the prefixed id' do
- expect(subject['id']).to eq(report.prefixed_id)
- end
-
- it 'returns prefixed user_id' do
- expect(subject['user_id']).to eq(report.user.prefixed_id)
- end
-
- it 'returns date_from as ISO8601' do
- expect(subject['date_from']).to be_present
- end
-end
diff --git a/spree/core/app/jobs/spree/reports/generate_job.rb b/spree/core/app/jobs/spree/reports/generate_job.rb
deleted file mode 100644
index 5738c4bdc3..0000000000
--- a/spree/core/app/jobs/spree/reports/generate_job.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-module Spree
- module Reports
- class GenerateJob < Spree::BaseJob
- queue_as Spree.queues.reports
-
- # `Report#generate` is not retry-safe: each call re-attaches a new ActiveStorage
- # blob (leaving the prior one orphaned) and re-enqueues the completion email.
- # Opt out of the parent's retry policy so transient errors fail fast into the
- # dead queue for operator review rather than producing duplicate side effects.
- retry_on ActiveRecord::Deadlocked,
- ActiveRecord::LockWaitTimeout,
- ActiveRecord::ConnectionNotEstablished,
- ActiveRecord::ConnectionFailed,
- ActiveRecord::RecordNotFound,
- attempts: 1
-
- def perform(report_id)
- report = Spree::Report.find_by_prefix_id!(report_id)
- report.generate
- end
- end
- end
-end
diff --git a/spree/core/app/mailers/spree/report_mailer.rb b/spree/core/app/mailers/spree/report_mailer.rb
deleted file mode 100644
index be782ca683..0000000000
--- a/spree/core/app/mailers/spree/report_mailer.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-module Spree
- class ReportMailer < BaseMailer
- def report_done(report)
- @report = report
-
- with_store_locale(@report.store) do
- mail(
- to: @report.user.email,
- subject: Spree.t('report_mailer.report_done.subject', report_name: @report.human_name).to_s
- )
- end
- end
-
- private
-
- def current_store
- @current_store ||= @report.store
- end
- end
-end
diff --git a/spree/core/app/models/concerns/spree/admin_user_methods.rb b/spree/core/app/models/concerns/spree/admin_user_methods.rb
index 0ab37dbe4d..403274b0f4 100644
--- a/spree/core/app/models/concerns/spree/admin_user_methods.rb
+++ b/spree/core/app/models/concerns/spree/admin_user_methods.rb
@@ -43,7 +43,6 @@ module Spree
has_many :created_exchanges, class_name: 'Spree::Exchange', foreign_key: :created_by_id
has_many :created_claims, class_name: 'Spree::Claim', foreign_key: :created_by_id
has_many :created_store_credits, class_name: 'Spree::StoreCredit', foreign_key: :created_by_id
- has_many :reports, class_name: 'Spree::Report', foreign_key: :user_id
has_many :exports, class_name: 'Spree::Export', foreign_key: :user_id
# Callbacks
@@ -99,7 +98,6 @@ module Spree
created_store_credits.update_all(created_by_id: nil, updated_at: Time.current)
# resources to destroy
- reports.destroy_all
exports.destroy_all
end
end
diff --git a/spree/core/app/models/spree/exports/report.rb b/spree/core/app/models/spree/exports/report.rb
index b481381b00..3249bd7c75 100644
--- a/spree/core/app/models/spree/exports/report.rb
+++ b/spree/core/app/models/spree/exports/report.rb
@@ -16,8 +16,7 @@ module Spree
:reports
end
- # Not a bulk export of a model — the derived `Spree::Report` (legacy CSV
- # reports) would be wrong, so anchor on the saved-report model instead.
+ # Not a bulk export of a model, so anchor on the saved-report model.
def self.model_class
Spree::SavedReport
end
diff --git a/spree/core/app/models/spree/report.rb b/spree/core/app/models/spree/report.rb
deleted file mode 100644
index 1f0260d316..0000000000
--- a/spree/core/app/models/spree/report.rb
+++ /dev/null
@@ -1,131 +0,0 @@
-module Spree
- class Report < Spree.base_class
- has_prefix_id :rep
-
- include Spree::SingleStoreResource
-
- publishes_lifecycle_events
-
- # Set event prefix for all Report subclasses
- # This ensures Spree::Reports::SalesTotal publishes 'report.create' not 'sales_total.create'
- self.event_prefix = 'report'
-
- #
- # Associations
- #
- belongs_to :store, class_name: 'Spree::Store'
- belongs_to :user, class_name: Spree.admin_user_class.to_s, optional: true
-
- #
- # Callbacks
- #
- after_initialize :set_default_values
- # NOTE: generate_async is now handled by Spree::ReportSubscriber listening to 'report.create' event
-
- #
- # Validations
- #
- validates :date_from, :date_to, :currency, presence: true
-
- #
- # Attachments
- #
- has_one_attached :attachment, service: Spree.private_storage_service_name
-
- def event_serializer_class
- 'Spree::Api::V3::ReportSerializer'.safe_constantize
- end
-
- # Registered report subclasses, mirroring Spree::Export/Spree::Import so
- # `api_type_for` can resolve an STI column value without constantizing it.
- #
- # @return [Array<Class>]
- def self.available_types
- Spree.reports
- end
-
- # @deprecated Use `.api_type` — identical derivation, consistent with the
- # rest of the API's `type` fields.
- def self.report_type
- api_type
- end
-
- # Returns a scope of records to be used for generating report lines
- #
- # @return [ActiveRecord::Relation]
- def line_items_scope
- raise NotImplementedError, "Subclass #{self.class.name} must implement #line_items_scope"
- end
-
- # Returns an array of report lines
- #
- # @return [Array<Spree::ReportLineItem>]
- def line_items(options = {})
- scope = line_items_scope
- scope = scope.limit(options[:limit]) if options[:limit].present?
-
- scope.map { |record| line_item_class.new(record: record, report: self) }
- end
-
- def human_name
- [Spree.t("report_names.#{type.demodulize.underscore}"), store.name, date_from.strftime('%Y-%m-%d'), date_to.strftime('%Y-%m-%d')].join(' - ')
- end
-
- def generate_async
- Spree::Reports::GenerateJob.perform_later(id)
- end
-
- def generate
- generate_csv
- handle_attachment
- send_report_done_email
- end
-
- def generate_csv
- ::CSV.open(report_tmp_file_path, 'wb', encoding: 'UTF-8', col_sep: ',', row_sep: "\r\n") do |csv|
- csv << line_item_class.csv_headers
- line_items_scope.find_in_batches do |batch|
- batch.each do |record|
- csv << line_item_class.new(record: record, report: self).to_csv
- end
- end
- end
- end
-
- def handle_attachment
- file = ::File.open(report_tmp_file_path)
- attachment.attach(io: file, filename: attachment_file_name)
- ::File.delete(report_tmp_file_path) if ::File.exist?(report_tmp_file_path)
- end
-
- def send_report_done_email
- return unless user.present?
-
- Spree::ReportMailer.report_done(self).deliver_later
- end
-
- # eg. Spree::ReportLineItems::SalesTotal
- def line_item_class
- "Spree::ReportLineItems::#{type.demodulize}".safe_constantize
- end
-
- # eg. "store-sales-total-report-20250201120000.csv"
- def attachment_file_name
- @attachment_file_name ||= "#{store.code}-#{type.demodulize.parameterize}-report-#{created_at.strftime('%Y%m%d%H%M%S')}.csv"
- end
-
- private
-
- def report_tmp_file_path
- Rails.root.join('tmp', attachment_file_name)
- end
-
- def set_default_values
- return if store.blank?
-
- self.currency ||= store.default_currency
- self.date_from ||= 1.month.ago.in_time_zone(store.preferred_timezone).beginning_of_day
- self.date_to ||= Time.current.in_time_zone(store.preferred_timezone).end_of_day
- end
- end
-end
diff --git a/spree/core/app/models/spree/report_line_item.rb b/spree/core/app/models/spree/report_line_item.rb
deleted file mode 100644
index 46eea83e82..0000000000
--- a/spree/core/app/models/spree/report_line_item.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-module Spree
- class ReportLineItem
- include ActiveModel::Model
- include ActiveModel::Attributes
-
- attr_accessor :record, :report
-
- delegate :store, :currency, to: :report
- delegate :id, to: :record, prefix: true
-
- def self.headers
- attribute_types.keys.map do |attribute|
- { name: attribute.to_sym, label: Spree.t(attribute.to_sym) }
- end
- end
-
- def self.csv_headers
- attribute_types.keys
- end
-
- def to_csv
- self.class.attribute_types.keys.map do |attribute|
- send(attribute)
- end
- end
- end
-end
diff --git a/spree/core/app/models/spree/report_line_items/products_performance.rb b/spree/core/app/models/spree/report_line_items/products_performance.rb
deleted file mode 100644
index 3070a86d45..0000000000
--- a/spree/core/app/models/spree/report_line_items/products_performance.rb
+++ /dev/null
@@ -1,71 +0,0 @@
-module Spree
- module ReportLineItems
- class ProductsPerformance < Spree::ReportLineItem
- attribute :sku, :string
- attribute :name, :string
- attribute :seller, :string
- attribute :category_lvl0, :string
- attribute :category_lvl1, :string
- attribute :category_lvl2, :string
- attribute :price, :string
- attribute :weeks_online, :integer
- attribute :pre_tax_amount, :string
- attribute :tax_total, :string
- attribute :quantity, :integer
- attribute :promo_total, :string
- attribute :total, :string
-
- delegate :sku, :name, to: :record
-
- def seller
- record.try(:seller_name)
- end
-
- def category_lvl0
- mapped_categories&.first
- end
-
- def category_lvl1
- mapped_categories&.second
- end
-
- def category_lvl2
- mapped_categories&.third
- end
-
- def price
- record.price_in(currency).display_amount
- end
-
- def pre_tax_amount
- Spree::Money.new(record.pre_tax_amount, currency: currency)
- end
-
- def promo_total
- Spree::Money.new(record.promo_total, currency: currency)
- end
-
- def tax_total
- Spree::Money.new(record.tax_total, currency: currency)
- end
-
- def quantity
- record.quantity
- end
-
- def total
- Spree::Money.new(record.total, currency: currency)
- end
-
- def weeks_online
- start_date = record.available_on.presence || record.created_at
-
- (Time.current - start_date.in_time_zone(store.preferred_timezone)).seconds.in_weeks.to_i
- end
-
- def mapped_categories
- @mapped_categories ||= record.primary_category&.pretty_name&.split('->')&.map(&:strip)
- end
- end
- end
-end
diff --git a/spree/core/app/models/spree/report_line_items/sales_total.rb b/spree/core/app/models/spree/report_line_items/sales_total.rb
deleted file mode 100644
index cae77beeb4..0000000000
--- a/spree/core/app/models/spree/report_line_items/sales_total.rb
+++ /dev/null
@@ -1,49 +0,0 @@
-module Spree
- module ReportLineItems
- class SalesTotal < Spree::ReportLineItem
- attribute :date, :string
- attribute :order, :string
- attribute :product, :string
- attribute :quantity, :integer
- attribute :pre_tax_amount, :decimal
- attribute :promo_total, :decimal
- attribute :shipment_total, :decimal
- attribute :tax_total, :decimal
- attribute :total, :decimal
-
- delegate :quantity, to: :record
-
- def date
- record.order.completed_at.strftime('%Y-%m-%d')
- end
-
- def order
- record.order.number
- end
-
- def product
- record.variant.descriptive_name
- end
-
- def total
- Spree::Money.new(record.final_amount + record.delivery_cost, currency: record.currency)
- end
-
- def promo_total
- record.display_discount_total
- end
-
- def pre_tax_amount
- record.display_pre_tax_amount
- end
-
- def shipment_total
- record.display_delivery_cost
- end
-
- def tax_total
- record.display_tax_total
- end
- end
- end
-end
diff --git a/spree/core/app/models/spree/reports/products_performance.rb b/spree/core/app/models/spree/reports/products_performance.rb
deleted file mode 100644
index c73558023c..0000000000
--- a/spree/core/app/models/spree/reports/products_performance.rb
+++ /dev/null
@@ -1,44 +0,0 @@
-module Spree
- module Reports
- class ProductsPerformance < Spree::Report
- def line_items_scope
- line_items_scope = Spree::LineItem.
- select("
- #{Spree::LineItem.table_name}.quantity as quantity,
- #{Spree::LineItem.table_name}.pre_tax_amount as pre_tax_amount,
- #{Spree::LineItem.table_name}.discount_total as promo_total,
- #{Spree::LineItem.table_name}.included_tax_total + #{Spree::LineItem.table_name}.additional_tax_total AS tax_total,
- #{Spree::LineItem.table_name}.pre_tax_amount + #{Spree::LineItem.table_name}.adjustment_total AS total,
- #{Spree::Variant.table_name}.product_id AS product_id
- ").
- joins(:variant, :order).
- where(
- spree_line_items: {
- currency: currency
- },
- spree_orders: {
- completed_at: date_from..date_to
- }
- )
-
- return Spree::Product.none if line_items_scope.empty?
-
- line_items_sql = line_items_scope.to_sql
-
- product_scope = store.products
- product_scope = product_scope.where(seller_id: seller.id) if defined?(seller) && seller.present?
-
- product_scope.includes(:categories, :tax_category, variants: :prices).
- joins("LEFT JOIN (#{line_items_sql}) AS line_items ON #{Spree::Product.table_name}.id = line_items.product_id").
- select("
- spree_products.*,
- COALESCE(SUM(line_items.pre_tax_amount), 0.0) AS pre_tax_amount,
- COALESCE(SUM(line_items.quantity), 0) AS quantity,
- COALESCE(SUM(line_items.promo_total), 0.0) AS promo_total,
- COALESCE(SUM(line_items.tax_total), 0.0) AS tax_total,
- COALESCE(SUM(line_items.total), 0.0) AS total
- ").group('spree_products.id')
- end
- end
- end
-end
diff --git a/spree/core/app/models/spree/reports/sales_total.rb b/spree/core/app/models/spree/reports/sales_total.rb
deleted file mode 100644
index 1b276e963e..0000000000
--- a/spree/core/app/models/spree/reports/sales_total.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-module Spree
- module Reports
- class SalesTotal < Spree::Report
- def line_items_scope
- scope = store.line_items.where(
- order: Spree::Order.complete.where(
- currency: currency,
- completed_at: date_from..date_to
- )
- ).includes(:order, shipments: :inventory_units, variant: :product)
-
- scope = scope.where(seller_id: seller.id) if defined?(seller) && seller.present?
-
- scope
- end
- end
- end
-end
diff --git a/spree/core/app/models/spree/store.rb b/spree/core/app/models/spree/store.rb
index 8dcdb4898b..44ba24702a 100644
--- a/spree/core/app/models/spree/store.rb
+++ b/spree/core/app/models/spree/store.rb
@@ -282,7 +282,6 @@ module Spree
self[:default_country_code] = value&.iso
end
- has_many :reports, class_name: 'Spree::Report'
has_many :exports, class_name: 'Spree::Export'
has_many :integrations, class_name: 'Spree::Integration'
diff --git a/spree/core/app/subscribers/spree/report_subscriber.rb b/spree/core/app/subscribers/spree/report_subscriber.rb
deleted file mode 100644
index c9aca4370b..0000000000
--- a/spree/core/app/subscribers/spree/report_subscriber.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-# frozen_string_literal: true
-
-module Spree
- # Handles Report lifecycle events.
- #
- # This subscriber replaces the following callbacks in Spree::Report:
- # - after_commit :generate_async, on: :create
- #
- # When a report is created, this subscriber triggers the async generation job.
- #
- # We use async: false because this subscriber just queues a background job,
- # so there's no benefit to running the subscriber itself asynchronously.
- #
- class ReportSubscriber < Spree::Subscriber
- subscribes_to 'report.created', async: false
-
- on 'report.created', :generate_report_async
-
- def generate_report_async(event)
- report_id = event.payload['id']
- return unless report_id
-
- Spree::Reports::GenerateJob.perform_later(report_id)
- end
- end
-end
diff --git a/spree/core/app/views/spree/report_mailer/report_done.html.erb b/spree/core/app/views/spree/report_mailer/report_done.html.erb
deleted file mode 100644
index 32fcfc7c9f..0000000000
--- a/spree/core/app/views/spree/report_mailer/report_done.html.erb
+++ /dev/null
@@ -1,7 +0,0 @@
-<%= render layout: 'spree/shared/mailer_hero' do %>
- <h1><%= Spree.t('report_mailer.greeting', user_name: @report.user&.first_name) %></h1>
- <p><%= Spree.t('report_mailer.report_done.message') %></p>
- <% if spree.respond_to?(:admin_report_url) %>
- <%= render 'spree/shared/mailer_button', url: spree.admin_report_url(@report, host: @current_store.formatted_url), label: @report.attachment.filename %>
- <% end %>
-<% end %>
diff --git a/spree/core/config/locales/en.yml b/spree/core/config/locales/en.yml
index 77820bc304..1bb092b8a5 100644
--- a/spree/core/config/locales/en.yml
+++ b/spree/core/config/locales/en.yml
@@ -1675,12 +1675,6 @@ en:
remove_gift_card_on_completed_order_error: You can't remove the gift card after the order was placed
rename: Rename
report: Report
- report_mailer:
- greeting: Hi %{user_name},
- report_done:
- message: Please use the link below to download it.
- subject: Your report %{report_name} is ready
- thanks: Thank you,
report_names:
products_performance: Products performance
sales_total: Sales total
diff --git a/spree/core/db/migrate/20250204162453_create_spree_reports.rb b/spree/core/db/migrate/20250204162453_create_spree_reports.rb
deleted file mode 100644
index d8f2bc5cc7..0000000000
--- a/spree/core/db/migrate/20250204162453_create_spree_reports.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-class CreateSpreeReports < ActiveRecord::Migration[6.1]
- def change
- create_table :spree_reports do |t|
- t.references :store, null: false
- t.references :user
- t.string 'type'
- t.string 'currency'
- t.datetime 'date_from'
- t.datetime 'date_to'
- t.timestamps
- end
- end
-end
diff --git a/spree/core/lib/spree/core.rb b/spree/core/lib/spree/core.rb
index cacc95b05e..24ddaa5484 100644
--- a/spree/core/lib/spree/core.rb
+++ b/spree/core/lib/spree/core.rb
@@ -122,7 +122,6 @@ module Spree
images: :default,
imports: :default,
products: :default,
- reports: :default,
variants: :default,
categories: :default,
collections: :default,
@@ -626,13 +625,6 @@ module Spree
Rails.application.config.spree.taggable_types = value
end
- def self.reports
- Rails.application.config.spree.reports
- end
-
- def self.reports=(value)
- Rails.application.config.spree.reports = value
- end
# Registry of the Getting Started onboarding tasks shown on the admin
# dashboard. See {Spree::SetupTasks} for the extension API.
diff --git a/spree/core/lib/spree/core/engine.rb b/spree/core/lib/spree/core/engine.rb
index 278b28b4db..046e9b5a17 100644
--- a/spree/core/lib/spree/core/engine.rb
+++ b/spree/core/lib/spree/core/engine.rb
@@ -501,11 +501,6 @@ module Spree
Spree::CollectionRules::AvailableOn,
]
- Rails.application.config.spree.reports = [
- Spree::Reports::ProductsPerformance,
- Spree::Reports::SalesTotal
- ]
-
Rails.application.config.spree.translatable_resources = [
Spree::OptionType,
Spree::OptionValue,
@@ -618,7 +613,6 @@ module Spree
Spree::SellerTransferSubscriber,
Spree::SellerTransferReversalSubscriber,
Spree::ExportSubscriber,
- Spree::ReportSubscriber,
Spree::InvitationEmailSubscriber,
Spree::SellerOnboardingSubscriber,
Spree::AdminUserEmailSubscriber,
diff --git a/spree/core/lib/spree/core/previews/report_preview.rb b/spree/core/lib/spree/core/previews/report_preview.rb
deleted file mode 100644
index 8dabce73b6..0000000000
--- a/spree/core/lib/spree/core/previews/report_preview.rb
+++ /dev/null
@@ -1,40 +0,0 @@
-require_relative 'preview_data'
-
-# Preview Spree report emails at /rails/mailers/spree/report
-class Spree::ReportPreview < ActionMailer::Preview
- include Spree::PreviewData::LocaleParam
-
- def report_done
- Spree::ReportMailer.report_done(report)
- end
-
- private
-
- # Reuse the most recent report, or build an in-memory example so the preview
- # works on a database that has never run a report. When the preview toolbar
- # requests a locale, always use the example so its store carries that locale.
- # The example is never saved, so no `report.created` side effects fire.
- def report
- return example_report if locale.present?
-
- Spree::Report.last || example_report
- end
-
- def example_report
- store = Spree::PreviewData.store(locale)
- report = Spree::Reports::SalesTotal.new(
- id: 0,
- store: store,
- user: Spree::PreviewData.admin_user,
- date_from: 30.days.ago.to_date,
- date_to: Date.current,
- currency: store.default_currency
- )
- report.attachment.attach(
- io: StringIO.new("date,total\n2026-01-01,1234.56\n"),
- filename: 'sales-total.csv',
- content_type: 'text/csv'
- )
- report
- end
-end
diff --git a/spree/core/lib/spree/testing_support/factories/report_factory.rb b/spree/core/lib/spree/testing_support/factories/report_factory.rb
deleted file mode 100644
index 7feca0abe8..0000000000
--- a/spree/core/lib/spree/testing_support/factories/report_factory.rb
+++ /dev/null
@@ -1,33 +0,0 @@
-# == Schema Information
-#
-# Table name: spree_reports
-#
-# id :bigint not null, primary key
-# type :string
-# currency :string
-# date_from :datetime
-# date_to :datetime
-# created_at :datetime not null
-# updated_at :datetime not null
-# store_id :bigint not null
-# user_id :bigint
-#
-FactoryBot.define do
- factory :report, class: 'Spree::Reports::SalesTotal' do
- association :store, factory: :store
- association :user, factory: :admin_user
- type { 'Spree::Reports::SalesTotal' }
- currency { 'USD' }
- date_from { 1.month.ago }
- date_to { Time.current }
- end
-
- factory :products_performance_report, class: 'Spree::Reports::ProductsPerformance' do
- association :store, factory: :store
- association :user, factory: :admin_user
- type { 'Spree::Reports::ProductsPerformance' }
- currency { 'USD' }
- date_from { 1.month.ago }
- date_to { Time.current }
- end
-end
diff --git a/spree/core/spec/lib/spree/core_environment_spec.rb b/spree/core/spec/lib/spree/core_environment_spec.rb
index 8143de079d..b01c71d189 100644
--- a/spree/core/spec/lib/spree/core_environment_spec.rb
+++ b/spree/core/spec/lib/spree/core_environment_spec.rb
@@ -58,11 +58,6 @@ RSpec.describe 'Spree environment accessors' do
expect(Spree.taxon_rules).to be_an(Array)
end
- it 'provides access to reports' do
- expect(Spree.reports).to eq(Rails.application.config.spree.reports)
- expect(Spree.reports).to be_an(Array)
- end
-
it 'provides access to translatable_resources' do
expect(Spree.translatable_resources).to eq(Rails.application.config.spree.translatable_resources)
expect(Spree.translatable_resources).to be_an(Array)
@@ -113,14 +108,6 @@ RSpec.describe 'Spree environment accessors' do
Spree.stock_splitters = original
end
- it 'allows setting reports' do
- original = Spree.reports.dup
- Spree.reports = ['Custom::Report']
- expect(Spree.reports).to eq(['Custom::Report'])
- expect(Rails.application.config.spree.reports).to eq(['Custom::Report'])
- # Restore original
- Spree.reports = original
- end
end
describe 'nested accessors' do
diff --git a/spree/core/spec/mailers/spree/report_mailer_spec.rb b/spree/core/spec/mailers/spree/report_mailer_spec.rb
deleted file mode 100644
index b53a133e6e..0000000000
--- a/spree/core/spec/mailers/spree/report_mailer_spec.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-require 'spec_helper'
-
-RSpec.describe Spree::ReportMailer, type: :mailer do
- let(:store) { @default_store }
- let(:user) { create(:admin_user) }
- let(:report) { create(:report, store: store, user: user) }
- let(:spree) { Spree::Core::Engine.routes.url_helpers }
-
- describe '#report_done' do
- subject(:mail) { described_class.report_done(report) }
-
- before do
- allow(spree).to receive(:admin_report_url).and_return("http://test.com/admin/reports/#{report.id}")
- end
-
- it 'renders the subject' do
- expect(mail.subject).to eq(
- Spree.t('report_mailer.report_done.subject', report_name: report.human_name)
- )
- end
-
- it 'sends to the correct recipient' do
- expect(mail.to).to eq([user.email])
- end
-
- it 'sends from the store mail from address' do
- expect(mail.from).to eq([store.mail_from_address])
- end
-
- it 'sets reply-to as the store customer support email' do
- expect(mail.reply_to).to eq([store.customer_support_email])
- end
-
- it 'includes download link in the body' do
- expect(mail.body.encoded).to include("/admin/reports/#{report.id}")
- end
- end
-end
diff --git a/spree/core/spec/models/spree/admin_user_spec.rb b/spree/core/spec/models/spree/admin_user_spec.rb
index 5d9ebb46b5..fe59dc3a39 100644
--- a/spree/core/spec/models/spree/admin_user_spec.rb
+++ b/spree/core/spec/models/spree/admin_user_spec.rb
@@ -54,12 +54,11 @@ describe Spree.admin_user_class, type: :model do
let!(:gift_cards) { create_list(:gift_card, 2, created_by: admin_user) }
let!(:refunds) { create_list(:refund, 2, refunder: admin_user, amount: 1) }
let!(:returns) { create_list(:return, 2, created_by: admin_user) }
- let!(:reports) { create_list(:report, 2, user: admin_user) }
let!(:store_credits) { create_list(:store_credit, 2, created_by: admin_user) }
let!(:exports) { create_list(:export, 2, user: admin_user) }
it 'nullifies admin user resources' do
- expect { admin_user.destroy }.to change(Spree.admin_user_class, :count).by(-1).and change(Spree::Export, :count).by(-2).and change(Spree::Report, :count).by(-2)
+ expect { admin_user.destroy }.to change(Spree.admin_user_class, :count).by(-1).and change(Spree::Export, :count).by(-2)
expect(cancelled_orders.all? { |order| order.reload.canceler_id.nil? }).to be_truthy
expect(approved_orders.all? { |order| order.reload.approver_id.nil? }).to be_truthy
diff --git a/spree/core/spec/models/spree/concerns/admin_user_methods_spec.rb b/spree/core/spec/models/spree/concerns/admin_user_methods_spec.rb
index 401a6db48b..5b087f1bc4 100644
--- a/spree/core/spec/models/spree/concerns/admin_user_methods_spec.rb
+++ b/spree/core/spec/models/spree/concerns/admin_user_methods_spec.rb
@@ -130,7 +130,6 @@ describe Spree::AdminUserMethods do
let!(:refund) { create(:refund, refunder: admin_user, amount: 1) }
let!(:return_record) { create(:return, created_by: admin_user) }
let!(:store_credit) { create(:store_credit, created_by: admin_user) }
- let!(:report) { create(:report, user: admin_user) }
let!(:export) { create(:export, user: admin_user) }
it 'nullifies canceler_id on canceled orders' do
@@ -168,9 +167,6 @@ describe Spree::AdminUserMethods do
expect(store_credit.reload.created_by_id).to be_nil
end
- it 'destroys reports' do
- expect { admin_user.destroy }.to change(Spree::Report, :count).by(-1)
- end
it 'destroys exports' do
expect { admin_user.destroy }.to change(Spree::Export, :count).by(-1)
diff --git a/spree/core/spec/models/spree/report_line_item_spec.rb b/spree/core/spec/models/spree/report_line_item_spec.rb
deleted file mode 100644
index cc24659b91..0000000000
--- a/spree/core/spec/models/spree/report_line_item_spec.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-require 'spec_helper'
-
-RSpec.describe Spree::ReportLineItem do
- let(:store) { @default_store }
- let(:order) { create(:order, store: store) }
- let(:report) { create(:report, store: store, currency: 'USD') }
- let(:report_line_item) { described_class.new(report: report, record: order) }
-
- describe '.headers' do
- it 'returns array of hashes with name and label' do
- allow(described_class).to receive(:attribute_types).and_return({ 'foo' => nil })
- allow(Spree).to receive(:t).with(:foo).and_return('Foo Label')
-
- expect(described_class.headers).to eq([{name: :foo, label: 'Foo Label'}])
- end
- end
-
- describe '.csv_headers' do
- it 'returns array of attribute keys' do
- allow(described_class).to receive(:attribute_types).and_return({ 'foo' => nil, 'bar' => nil })
- expect(described_class.csv_headers).to eq(['foo', 'bar'])
- end
- end
-
- describe '#to_csv' do
- it 'returns array of attribute values' do
- allow(described_class).to receive(:attribute_types).and_return({ 'foo' => nil, 'bar' => nil })
- report_line_item = described_class.new
- allow(report_line_item).to receive(:foo).and_return('foo_value')
- allow(report_line_item).to receive(:bar).and_return('bar_value')
-
- expect(report_line_item.to_csv).to eq(['foo_value', 'bar_value'])
- end
- end
-end
diff --git a/spree/core/spec/models/spree/report_line_items/products_performance_spec.rb b/spree/core/spec/models/spree/report_line_items/products_performance_spec.rb
deleted file mode 100644
index 84300ef054..0000000000
--- a/spree/core/spec/models/spree/report_line_items/products_performance_spec.rb
+++ /dev/null
@@ -1,92 +0,0 @@
-require 'spec_helper'
-
-RSpec.describe Spree::ReportLineItems::ProductsPerformance do
- let(:store) { @default_store }
- let(:report) { create(:products_performance_report, store: store) }
- let(:order) { create(:completed_order_with_totals, store: store, currency: report.currency) }
-
- let!(:product) { order.line_items.first.product }
- let!(:variant) { order.line_items.first.variant }
-
- before { order.update(completed_at: report.date_from + 1.day) }
-
- subject { report.line_items.first }
-
- describe '#seller' do
- it 'returns seller name from record' do
- expect(subject.seller).to eq(variant.try(:seller_name))
- end
- end
-
- describe '#category_levels' do
- let(:category) { create(:category, name: 'Shoes') }
-
- context 'when product has taxons' do
- before do
- product.categories << category
- product.save!
- end
-
- it 'returns mapped category levels' do
- # A top-level category is level 0 — there is no taxonomy root above it.
- expect(subject.category_lvl0).to eq('Shoes')
- expect(subject.category_lvl1).to be_nil
- expect(subject.category_lvl2).to be_nil
- end
- end
-
- context 'when product has no taxons' do
- it 'returns nil for all category levels' do
- expect(subject.category_lvl0).to be_nil
- expect(subject.category_lvl1).to be_nil
- expect(subject.category_lvl2).to be_nil
- end
- end
- end
-
- describe '#price' do
- it 'returns formatted price in report currency' do
- expect(subject.price).to eq(variant.price_in(report.currency).display_amount)
- end
- end
-
- describe '#weeks_online' do
- context 'with available on' do
- before do
- product.update(available_on: 2.weeks.ago)
- end
-
- it 'returns number of weeks since product activation' do
- expect(subject.weeks_online).to eq(2)
- end
- end
-
- context 'without available on' do
- before do
- product.update(available_on: nil, created_at: 3.weeks.ago)
- end
-
- it 'returns number of weeks since product creation' do
- expect(subject.weeks_online).to eq(3)
- end
- end
- end
-
- describe 'money amounts' do
- let(:line_item) { report.line_items.first }
-
- it 'returns formatted money amounts' do
- expect(subject.pre_tax_amount).to eq(Spree::Money.new(line_item.pre_tax_amount, currency: report.currency))
- expect(subject.tax_total).to eq(Spree::Money.new(line_item.tax_total, currency: report.currency))
- expect(subject.promo_total).to eq(Spree::Money.new(line_item.promo_total, currency: report.currency))
- expect(subject.total).to eq(Spree::Money.new(line_item.total, currency: report.currency))
- end
- end
-
- describe '#quantity' do
- it 'returns line item quantity' do
- expect(subject.quantity).to eq(report.line_items.first.quantity)
- end
- end
-
-end
diff --git a/spree/core/spec/models/spree/report_line_items/sales_total_spec.rb b/spree/core/spec/models/spree/report_line_items/sales_total_spec.rb
deleted file mode 100644
index 940ecd8b94..0000000000
--- a/spree/core/spec/models/spree/report_line_items/sales_total_spec.rb
+++ /dev/null
@@ -1,62 +0,0 @@
-require 'spec_helper'
-
-RSpec.describe Spree::ReportLineItems::SalesTotal do
- let(:order) { create(:completed_order_with_totals) }
- let(:line_item) { order.line_items.first }
- let(:sales_total) { described_class.new(record: line_item) }
-
- describe '#date' do
- it 'returns formatted completed_at date' do
- expect(sales_total.date).to eq(order.completed_at.strftime('%Y-%m-%d'))
- end
- end
-
- describe '#order' do
- it 'returns order number' do
- expect(sales_total.order).to eq(order.number)
- end
- end
-
- describe '#product' do
- it 'returns variant descriptive name' do
- expect(sales_total.product).to eq(line_item.variant.descriptive_name)
- end
- end
-
- describe '#quantity' do
- it 'returns quantity' do
- expect(sales_total.quantity).to eq(line_item.quantity)
- end
- end
-
- describe '#total' do
- it 'returns money object with final amount plus shipping' do
- total = Spree::Money.new(line_item.final_amount + line_item.delivery_cost, currency: line_item.currency)
- expect(sales_total.total).to eq(total)
- end
- end
-
- describe '#promo_total' do
- it 'returns display promo total' do
- expect(sales_total.promo_total).to eq(line_item.display_promo_total)
- end
- end
-
- describe '#pre_tax_amount' do
- it 'returns display pre tax amount' do
- expect(sales_total.pre_tax_amount).to eq(line_item.display_pre_tax_amount)
- end
- end
-
- describe '#shipment_total' do
- it 'returns display shipping cost' do
- expect(sales_total.shipment_total).to eq(line_item.display_delivery_cost)
- end
- end
-
- describe '#tax_total' do
- it 'returns display tax total' do
- expect(sales_total.tax_total).to eq(line_item.display_tax_total)
- end
- end
-end
diff --git a/spree/core/spec/models/spree/report_spec.rb b/spree/core/spec/models/spree/report_spec.rb
deleted file mode 100644
index aad399461f..0000000000
--- a/spree/core/spec/models/spree/report_spec.rb
+++ /dev/null
@@ -1,67 +0,0 @@
-require 'spec_helper'
-
-RSpec.describe Spree::Report, type: :model do
- it_behaves_like 'lifecycle events', factory: :report
-
- let(:store) { @default_store }
- let(:user) { create(:admin_user) }
- let(:report) { build(:report, store: store, user: user) }
-
- describe '#human_name' do
- before { report.save! }
-
- it 'returns formatted name with store, dates and report type' do
- expected_name = [
- 'Sales total',
- store.name,
- report.date_from.strftime('%Y-%m-%d'),
- report.date_to.strftime('%Y-%m-%d')
- ].join(' - ')
-
- expect(report.human_name).to eq(expected_name)
- end
- end
-
- describe '#generate' do
- before { report.save! }
-
- it 'generates CSV file and attaches it' do
- expect { report.generate }.to change(report.attachment, :attached?).from(false).to(true)
- end
-
- it 'sends report done email when user is present' do
- expect { report.generate }.to have_enqueued_job(ActionMailer::MailDeliveryJob)
- end
-
- context 'when user is not present' do
- let(:report) { build(:report, store: store, user: nil) }
-
- it 'does not send report done email' do
- expect { report.generate }.not_to have_enqueued_job(ActionMailer::MailDeliveryJob)
- end
- end
- end
-
- describe '#attachment_file_name' do
- before { report.save! }
-
- it 'returns the correct file name format' do
- expect(report.attachment_file_name).to match(/#{store.code}-salestotal-report-\d{14}\.csv/)
- end
- end
-
- describe 'callbacks' do
- describe 'after_initialize' do
- let(:new_report) { Spree::Report.new(store: store) }
-
- it 'sets default currency from store' do
- expect(new_report.currency).to eq(store.default_currency)
- end
-
- it 'sets default date range' do
- expect(new_report.date_from).to be_within(1.day).of(1.month.ago)
- expect(new_report.date_to).to be_within(1.day).of(Time.current)
- end
- end
- end
-end
diff --git a/spree/core/spec/models/spree/reports/products_performance_spec.rb b/spree/core/spec/models/spree/reports/products_performance_spec.rb
deleted file mode 100644
index 21601f7b7a..0000000000
--- a/spree/core/spec/models/spree/reports/products_performance_spec.rb
+++ /dev/null
@@ -1,85 +0,0 @@
-require 'spec_helper'
-
-RSpec.describe Spree::Reports::ProductsPerformance do
- let(:store) { @default_store }
- let(:report) { create(:products_performance_report, store: store) }
- let(:product) { create(:product) }
- let(:variant) { create(:variant, product: product) }
- let(:order) { create(:completed_order_with_totals, store: store, currency: report.currency) }
- let(:line_item) { create(:line_item, order: order, variant: variant) }
-
- describe '#line_items_scope' do
- context 'when order is within date range' do
- before do
- order.update(completed_at: report.date_from + 1.day)
- line_item.save!
- end
-
- it 'includes products with sales data' do
- result = report.line_items_scope.first
-
- expect(result.pre_tax_amount.to_f).to eq(line_item.pre_tax_amount)
- expect(result.quantity).to eq(line_item.quantity)
- expect(result.promo_total.to_f).to eq(line_item.promo_total)
- expect(result.tax_total.to_f).to eq(line_item.included_tax_total + line_item.additional_tax_total)
- expect(result.total.to_f).to eq(line_item.pre_tax_amount + line_item.adjustment_total)
- end
- end
-
- context 'when order is outside date range' do
- before do
- order.update(completed_at: report.date_from - 1.day)
- end
-
- it 'excludes products from orders outside date range' do
- expect(report.line_items_scope).to be_empty
- end
- end
-
- context 'date range boundary conditions' do
- before { line_item.save! }
-
- context 'when order completed exactly at date_from' do
- before { order.update(completed_at: report.date_from) }
-
- it 'includes products' do
- expect(report.line_items_scope).not_to be_empty
- end
- end
-
- context 'when order completed exactly at date_to' do
- before { order.update(completed_at: report.date_to) }
-
- it 'includes products' do
- expect(report.line_items_scope).not_to be_empty
- end
- end
-
- context 'when order completed 1 minute before date_from' do
- before { order.update(completed_at: report.date_from - 1.minute) }
-
- it 'excludes products' do
- expect(report.line_items_scope).to be_empty
- end
- end
-
- context 'when order completed 1 minute after date_to' do
- before { order.update(completed_at: report.date_to + 1.minute) }
-
- it 'excludes products' do
- expect(report.line_items_scope).to be_empty
- end
- end
- end
-
- context 'when order has different currency' do
- before do
- order.update(currency: 'EUR')
- end
-
- it 'excludes products with different currency' do
- expect(report.line_items_scope).to be_empty
- end
- end
- end
-end
diff --git a/spree/core/spec/models/spree/reports/sales_total_spec.rb b/spree/core/spec/models/spree/reports/sales_total_spec.rb
deleted file mode 100644
index ed25ffce60..0000000000
--- a/spree/core/spec/models/spree/reports/sales_total_spec.rb
+++ /dev/null
@@ -1,103 +0,0 @@
-require 'spec_helper'
-
-RSpec.describe Spree::Reports::SalesTotal do
- let(:store) { @default_store }
- let(:report) { create(:report, store: store) }
- let(:order) { create(:completed_order_with_totals, store: store, currency: report.currency) }
- let!(:line_item) { order.line_items.first }
-
- describe '#line_items_scope' do
- context 'when order is within date range' do
- before do
- order.update(completed_at: report.date_from + 1.day)
- end
-
- it 'includes line items from completed orders within date range' do
- expect(report.line_items_scope).to include(line_item)
- end
- end
-
- context 'when order is outside date range' do
- before do
- order.update(completed_at: report.date_from - 1.day)
- end
-
- it 'excludes line items from orders outside date range' do
- expect(report.line_items_scope).not_to include(line_item)
- end
- end
-
- context 'date range boundary conditions' do
- context 'when order completed exactly at date_from' do
- before { order.update(completed_at: report.date_from) }
-
- it 'includes line items' do
- expect(report.line_items_scope).to include(line_item)
- end
- end
-
- context 'when order completed exactly at date_to' do
- before { order.update(completed_at: report.date_to) }
-
- it 'includes line items' do
- expect(report.line_items_scope).to include(line_item)
- end
- end
-
- context 'when order completed 1 minute before date_from' do
- before { order.update(completed_at: report.date_from - 1.minute) }
-
- it 'excludes line items' do
- expect(report.line_items_scope).not_to include(line_item)
- end
- end
-
- context 'when order completed 1 minute after date_to' do
- before { order.update(completed_at: report.date_to + 1.minute) }
-
- it 'excludes line items' do
- expect(report.line_items_scope).not_to include(line_item)
- end
- end
- end
-
- context 'when order has different currency' do
- before do
- order.update(currency: 'EUR')
- end
-
- it 'excludes line items with different currency' do
- expect(report.line_items_scope).not_to include(line_item)
- end
- end
-
- context 'when order is incomplete' do
- before do
- order.update(completed_at: nil)
- end
-
- it 'excludes line items from incomplete orders' do
- expect(report.line_items_scope).not_to include(line_item)
- end
- end
- end
-
- describe '#return_line_items' do
- let(:return_line_item) { report.line_items.first }
-
- before { order.update(completed_at: report.date_from + 1.day) }
-
- it 'returns line items' do
- expect(return_line_item).to be_a(Spree::ReportLineItems::SalesTotal)
-
- expect(return_line_item.date).to eq(order.completed_at.strftime('%Y-%m-%d'))
- expect(return_line_item.order).to eq(order.number)
- expect(return_line_item.product).to eq(line_item.variant.descriptive_name)
- expect(return_line_item.quantity).to eq(line_item.quantity)
- expect(return_line_item.tax_total).to eq(line_item.display_tax_total)
- expect(return_line_item.promo_total).to eq(line_item.display_promo_total)
- expect(return_line_item.pre_tax_amount).to eq(line_item.display_pre_tax_amount)
- expect(return_line_item.shipment_total).to eq(line_item.display_delivery_cost)
- end
- end
-end
diff --git a/spree/core/spec/subscribers/spree/report_subscriber_spec.rb b/spree/core/spec/subscribers/spree/report_subscriber_spec.rb
deleted file mode 100644
index 53667518a4..0000000000
--- a/spree/core/spec/subscribers/spree/report_subscriber_spec.rb
+++ /dev/null
@@ -1,55 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe Spree::ReportSubscriber do
- describe '.subscription_patterns' do
- it 'subscribes to report.created event' do
- expect(described_class.subscription_patterns).to include('report.created')
- end
- end
-
- describe '.event_handlers' do
- it 'routes report.created to generate_report_async' do
- expect(described_class.event_handlers['report.created']).to eq(:generate_report_async)
- end
- end
-
- describe '#generate_report_async' do
- let(:store) { @default_store }
- let(:user) { create(:admin_user) }
- let(:subscriber) { described_class.new }
-
- let(:report) do
- create(:report,
- store: store,
- user: user,
- date_from: 1.month.ago,
- date_to: Time.current,
- currency: store.default_currency
- )
- end
-
- it 'passes prefixed ID to job' do
- event = Spree::Event.new(
- name: 'report.created',
- payload: { 'id' => report.prefixed_id }
- )
-
- expect(Spree::Reports::GenerateJob).to receive(:perform_later).with(report.prefixed_id)
-
- subscriber.generate_report_async(event)
- end
-
- it 'does not call job if id is missing' do
- event = Spree::Event.new(
- name: 'report.created',
- payload: {}
- )
-
- expect(Spree::Reports::GenerateJob).not_to receive(:perform_later)
-
- subscriber.generate_report_async(event)
- end
- end
-end
diff --git a/spree/lib/generators/spree/install/templates/config/initializers/spree.rb b/spree/lib/generators/spree/install/templates/config/initializers/spree.rb
index 8478dfdf94..cbe087dd30 100644
--- a/spree/lib/generators/spree/install/templates/config/initializers/spree.rb
+++ b/spree/lib/generators/spree/install/templates/config/initializers/spree.rb
@@ -77,9 +77,8 @@ Rails.application.config.after_initialize do
# Taxon rules
# Spree.taxon_rules << Spree::TaxonRules::ProductsWithColor
- # Exports and reports
+ # Exports
# Spree.export_types << Spree::Exports::Payments
- # Spree.reports << Spree::Reports::MassivelyOvercomplexReportForCfo
# Role-based permissions
# Staff roles and their permissions are managed as data — in the dashboard
@@ -104,7 +103,6 @@ end
# Spree.queues.images = :default
# Spree.queues.imports = :default
# Spree.queues.products = :default
-# Spree.queues.reports = :default
# Spree.queues.variants = :default
# Spree.queues.taxons = :default
# Spree.queues.stock_location_stock_levels = :default