mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Add filter on completed_at of an order
This commit is contained in:
committed by
Filipe
parent
4f332504af
commit
c134de850c
@@ -1,3 +1,5 @@
|
||||
= render 'admin/reports/date_range_form', f: f
|
||||
|
||||
.row
|
||||
.alpha.two.columns= label_tag nil, t(:report_customers_hub)
|
||||
.omega.fourteen.columns
|
||||
|
||||
@@ -12,7 +12,19 @@ module Reporting
|
||||
end
|
||||
|
||||
def filter(orders)
|
||||
filter_to_distributor filter_to_order_cycle orders
|
||||
filter_to_completed_at filter_to_distributor filter_to_order_cycle orders
|
||||
end
|
||||
|
||||
def filter_to_completed_at(orders)
|
||||
if params[:q] &&
|
||||
params[:q][:completed_at_gt].present? &&
|
||||
params[:q][:completed_at_lt].present?
|
||||
orders.where("completed_at >= ? AND completed_at <= ?",
|
||||
params[:q][:completed_at_gt],
|
||||
params[:q][:completed_at_lt])
|
||||
else
|
||||
orders
|
||||
end
|
||||
end
|
||||
|
||||
def filter_to_distributor(orders)
|
||||
|
||||
@@ -284,6 +284,16 @@ module Reporting
|
||||
expect(subject.filter(orders)).to eq(orders)
|
||||
end
|
||||
|
||||
it "filters to a specific completed_at date" do
|
||||
o1 = create(:order, completed_at: 1.day.ago)
|
||||
o2 = create(:order, completed_at: 3.days.ago)
|
||||
o3 = create(:order, completed_at: 5.days.ago)
|
||||
|
||||
allow(subject).to receive(:params).and_return({ q: { completed_at_gt: 1.day.before(o2.completed_at),
|
||||
completed_at_lt: 1.day.after(o2.completed_at) } })
|
||||
expect(subject.filter(orders)).to eq([o2])
|
||||
end
|
||||
|
||||
it "filters to a specific distributor" do
|
||||
d1 = create(:distributor_enterprise)
|
||||
d2 = create(:distributor_enterprise)
|
||||
|
||||
Reference in New Issue
Block a user