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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
FIX reports date picker and scopes (#13425)
brozek658d683a10ce
diff --git a/admin/app/views/spree/admin/reports/new.html.erb b/admin/app/views/spree/admin/reports/new.html.erbindex 0b77c90f04..e44ee694fd 100644--- a/admin/app/views/spree/admin/reports/new.html.erb+++ b/admin/app/views/spree/admin/reports/new.html.erb@@ -28,8 +28,8 @@<div class="flex gap-2"><%= render 'spree/admin/shared/calendar_range_picker',- date_from_value: @report.date_from,- date_to_value: @report.date_to %>+ date_from_value: params[:date_from] || 1.month.ago.in_time_zone(current_store.preferred_timezone).beginning_of_day,+ date_to_value: params[:date_to] || Time.current.in_time_zone(current_store.preferred_timezone).end_of_day %><div class="form-group"><%= select_tag :currency,diff --git a/core/app/models/spree/reports/products_performance.rb b/core/app/models/spree/reports/products_performance.rbindex e6636e8189..0f669d8ba1 100644--- a/core/app/models/spree/reports/products_performance.rb+++ b/core/app/models/spree/reports/products_performance.rb@@ -17,7 +17,7 @@ module Spreecurrency: currency},spree_orders: {- completed_at: (date_from.to_time.beginning_of_day)..(date_to.to_time.end_of_day)+ completed_at: date_from..date_to})diff --git a/core/app/models/spree/reports/sales_total.rb b/core/app/models/spree/reports/sales_total.rbindex e37a688bf0..ba036c2d82 100644--- a/core/app/models/spree/reports/sales_total.rb+++ b/core/app/models/spree/reports/sales_total.rb@@ -5,7 +5,7 @@ module Spreescope = store.line_items.where(order: Spree::Order.complete.where(currency: currency,- completed_at: (date_from.to_time.beginning_of_day)..(date_to.to_time.end_of_day)+ completed_at: date_from..date_to)).includes(:order, shipments: :inventory_units, variant: :product)diff --git a/core/spec/models/spree/report_line_items/products_performance_spec.rb b/core/spec/models/spree/report_line_items/products_performance_spec.rbindex a0e77c990b..c3a53fa08e 100644--- a/core/spec/models/spree/report_line_items/products_performance_spec.rb+++ b/core/spec/models/spree/report_line_items/products_performance_spec.rb@@ -8,6 +8,8 @@ RSpec.describe Spree::ReportLineItems::ProductsPerformance dolet!(: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 '#vendor' dodiff --git a/core/spec/models/spree/reports/products_performance_spec.rb b/core/spec/models/spree/reports/products_performance_spec.rbindex ab5f6460d0..ef189513a1 100644--- a/core/spec/models/spree/reports/products_performance_spec.rb+++ b/core/spec/models/spree/reports/products_performance_spec.rb@@ -36,6 +36,42 @@ RSpec.describe Spree::Reports::ProductsPerformance doendend+ 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' dobefore doorder.update(currency: 'EUR')diff --git a/core/spec/models/spree/reports/sales_total_spec.rb b/core/spec/models/spree/reports/sales_total_spec.rbindex 2d13e0dcd4..a4fb7adc73 100644--- a/core/spec/models/spree/reports/sales_total_spec.rb+++ b/core/spec/models/spree/reports/sales_total_spec.rb@@ -27,6 +27,40 @@ RSpec.describe Spree::Reports::SalesTotal doendend+ 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' dobefore doorder.update(currency: 'EUR')@@ -51,6 +85,8 @@ RSpec.describe Spree::Reports::SalesTotal dodescribe '#return_line_items' dolet(:return_line_item) { report.line_items.first }+ before { order.update(completed_at: report.date_from + 1.day) }+it 'returns line items' doexpect(return_line_item).to be_a(Spree::ReportLineItems::SalesTotal)