Merge pull request #4415 from lin-d-hop/delivery-report

Update end date on delivery report
This commit is contained in:
Luis Ramos
2019-11-08 16:58:27 +00:00
committed by GitHub
2 changed files with 5 additions and 5 deletions

View File

@@ -2,7 +2,7 @@ require 'open_food_network/user_balance_calculator'
module OpenFoodNetwork
class OrderCycleManagementReport
DEFAULT_DATE_INTERVAL = 1.month
DEFAULT_DATE_INTERVAL = { from: -1.month, to: 1.day }.freeze
attr_reader :params
def initialize(user, params = {}, render_table = false)
@params = sanitize_params(params)
@@ -137,8 +137,8 @@ module OpenFoodNetwork
def sanitize_params(params)
params[:q] ||= {}
params[:q][:completed_at_gt] ||= Time.zone.today - DEFAULT_DATE_INTERVAL
params[:q][:completed_at_lt] ||= Time.zone.today
params[:q][:completed_at_gt] ||= Time.zone.today + DEFAULT_DATE_INTERVAL[:from]
params[:q][:completed_at_lt] ||= Time.zone.today + DEFAULT_DATE_INTERVAL[:to]
params
end
end

View File

@@ -27,8 +27,8 @@ module OpenFoodNetwork
context "default date range" do
it "fetches orders completed in the past month" do
o1 = create(:order, completed_at: Time.zone.today - OrderCycleManagementReport::DEFAULT_DATE_INTERVAL - 1.day)
o2 = create(:order, completed_at: Time.zone.today - OrderCycleManagementReport::DEFAULT_DATE_INTERVAL + 1.day)
o1 = create(:order, completed_at: 1.month.ago - 1.day)
o2 = create(:order, completed_at: 1.month.ago + 1.day)
expect(subject.orders).to eq([o2])
end
end