mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Account invoice jobs run according to rails config time zone rather than system time zone
This commit is contained in:
@@ -2,11 +2,11 @@ class FinalizeAccountInvoices
|
||||
attr_reader :year, :month, :start_date, :end_date
|
||||
|
||||
def initialize(year = nil, month = nil)
|
||||
ref_point = Time.now - 1.month
|
||||
ref_point = Time.zone.now - 1.month
|
||||
@year = year || ref_point.year
|
||||
@month = month || ref_point.month
|
||||
@start_date = Time.new(@year, @month)
|
||||
@end_date = Time.new(@year, @month) + 1.month
|
||||
@start_date = Time.zone.local(@year, @month)
|
||||
@end_date = Time.zone.local(@year, @month) + 1.month
|
||||
end
|
||||
|
||||
def before(job)
|
||||
@@ -46,13 +46,13 @@ class FinalizeAccountInvoices
|
||||
private
|
||||
|
||||
def settings_are_valid?
|
||||
unless end_date <= Time.now
|
||||
unless end_date <= Time.zone.now
|
||||
Bugsnag.notify(RuntimeError.new("InvalidJobSettings"), {
|
||||
job: "FinalizeAccountInvoices",
|
||||
error: "end_date is in the future",
|
||||
data: {
|
||||
end_date: end_date.localtime.strftime("%F %T"),
|
||||
now: Time.now.strftime("%F %T")
|
||||
now: Time.zone.now.strftime("%F %T")
|
||||
}
|
||||
})
|
||||
return false
|
||||
|
||||
@@ -2,12 +2,12 @@ class UpdateAccountInvoices
|
||||
attr_reader :year, :month, :start_date, :end_date
|
||||
|
||||
def initialize(year = nil, month = nil)
|
||||
ref_point = Time.now - 1.day
|
||||
ref_point = Time.zone.now - 1.day
|
||||
@year = year || ref_point.year
|
||||
@month = month || ref_point.month
|
||||
@start_date = Time.new(@year, @month)
|
||||
@end_date = Time.new(@year, @month) + 1.month
|
||||
@end_date = Time.now.beginning_of_day if start_date == Time.now.beginning_of_month
|
||||
@start_date = Time.zone.local(@year, @month)
|
||||
@end_date = Time.zone.local(@year, @month) + 1.month
|
||||
@end_date = Time.zone.now.beginning_of_day if start_date == Time.zone.now.beginning_of_month
|
||||
end
|
||||
|
||||
def before(job)
|
||||
@@ -76,13 +76,13 @@ class UpdateAccountInvoices
|
||||
private
|
||||
|
||||
def settings_are_valid?
|
||||
unless end_date <= Time.now
|
||||
unless end_date <= Time.zone.now
|
||||
Bugsnag.notify(RuntimeError.new("InvalidJobSettings"), {
|
||||
job: "UpdateAccountInvoices",
|
||||
error: "end_date is in the future",
|
||||
data: {
|
||||
end_date: end_date.localtime.strftime("%F %T"),
|
||||
now: Time.now.strftime("%F %T")
|
||||
now: Time.zone.now.strftime("%F %T")
|
||||
}
|
||||
})
|
||||
return false
|
||||
|
||||
@@ -2,18 +2,18 @@ class UpdateBillablePeriods
|
||||
attr_reader :year, :month, :start_date, :end_date
|
||||
|
||||
def initialize(year = nil, month = nil)
|
||||
ref_point = Time.now - 1.day
|
||||
ref_point = Time.zone.now - 1.day
|
||||
@year = year || ref_point.year
|
||||
@month = month || ref_point.month
|
||||
@start_date = Time.new(@year, @month)
|
||||
@end_date = Time.new(@year, @month) + 1.month
|
||||
@end_date = Time.now.beginning_of_day if start_date == Time.now.beginning_of_month
|
||||
@start_date = Time.zone.local(@year, @month)
|
||||
@end_date = Time.zone.local(@year, @month) + 1.month
|
||||
@end_date = Time.zone.now.beginning_of_day if start_date == Time.zone.now.beginning_of_month
|
||||
end
|
||||
|
||||
def perform
|
||||
return unless settings_are_valid?
|
||||
|
||||
job_start_time = Time.now
|
||||
job_start_time = Time.zone.now
|
||||
|
||||
enterprises = Enterprise.where('created_at < (?)', end_date).select([:id, :name, :owner_id, :sells, :shop_trial_start_date, :created_at])
|
||||
|
||||
@@ -111,13 +111,13 @@ class UpdateBillablePeriods
|
||||
private
|
||||
|
||||
def settings_are_valid?
|
||||
unless end_date <= Time.now
|
||||
unless end_date <= Time.zone.now
|
||||
Bugsnag.notify(RuntimeError.new("InvalidJobSettings"), {
|
||||
job: "UpdateBillablePeriods",
|
||||
error: "end_date is in the future",
|
||||
data: {
|
||||
end_date: end_date.localtime.strftime("%F %T"),
|
||||
now: Time.now.strftime("%F %T")
|
||||
now: Time.zone.now.strftime("%F %T")
|
||||
}
|
||||
})
|
||||
return false
|
||||
|
||||
@@ -6,10 +6,11 @@ end
|
||||
|
||||
|
||||
describe FinalizeAccountInvoices do
|
||||
let!(:year) { Time.zone.now.year }
|
||||
|
||||
describe "unit specs" do
|
||||
let!(:finalizer) { FinalizeAccountInvoices.new }
|
||||
let!(:start_of_july) { Time.now.beginning_of_year + 6.months }
|
||||
let!(:year) { Time.now.year }
|
||||
let!(:start_of_july) { Time.local(year, 7) }
|
||||
|
||||
describe "perform" do
|
||||
let!(:accounts_distributor) { create(:distributor_enterprise) }
|
||||
@@ -87,8 +88,8 @@ describe FinalizeAccountInvoices do
|
||||
end
|
||||
end
|
||||
|
||||
context "an a specific year and month are passed as arguments" do
|
||||
let!(:finalizer) { FinalizeAccountInvoices.new(Time.now.year, 7) }
|
||||
context "and a specific year and month are passed as arguments" do
|
||||
let!(:finalizer) { FinalizeAccountInvoices.new(year, 7) }
|
||||
|
||||
before do
|
||||
allow(finalizer).to receive(:finalizer)
|
||||
@@ -163,7 +164,7 @@ describe FinalizeAccountInvoices do
|
||||
end
|
||||
|
||||
describe "validation spec" do
|
||||
let!(:start_of_july) { Time.now.beginning_of_year + 6.months }
|
||||
let!(:start_of_july) { Time.local(year, 7) }
|
||||
|
||||
let!(:updater) { UpdateAccountInvoices.new }
|
||||
let!(:finalizer) { FinalizeAccountInvoices.new }
|
||||
|
||||
@@ -5,8 +5,10 @@ def travel_to(time)
|
||||
end
|
||||
|
||||
describe UpdateAccountInvoices do
|
||||
let(:year) { Time.zone.now.year }
|
||||
|
||||
describe "units specs" do
|
||||
let!(:start_of_july) { Time.now.beginning_of_year + 6.months }
|
||||
let!(:start_of_july) { Time.local(year, 7) }
|
||||
|
||||
let!(:updater) { UpdateAccountInvoices.new }
|
||||
|
||||
@@ -65,7 +67,7 @@ describe UpdateAccountInvoices do
|
||||
end
|
||||
|
||||
context "when specfic a specific month (and year) are passed as arguments" do
|
||||
let!(:updater) { UpdateAccountInvoices.new(Time.now.year, 7) }
|
||||
let!(:updater) { UpdateAccountInvoices.new(year, 7) }
|
||||
|
||||
before do
|
||||
allow(updater).to receive(:update)
|
||||
@@ -319,7 +321,7 @@ describe UpdateAccountInvoices do
|
||||
end
|
||||
|
||||
describe "validation spec" do
|
||||
let!(:start_of_july) { Time.now.beginning_of_year + 6.months }
|
||||
let!(:start_of_july) { Time.local(year, 7) }
|
||||
|
||||
let!(:updater) { UpdateAccountInvoices.new }
|
||||
|
||||
|
||||
@@ -5,9 +5,10 @@ def travel_to(time)
|
||||
end
|
||||
|
||||
describe UpdateBillablePeriods do
|
||||
let!(:year) { Time.zone.now.year }
|
||||
|
||||
describe "unit specs" do
|
||||
let!(:start_of_july) { Time.now.beginning_of_year + 6.months }
|
||||
let!(:year) { Time.now.year }
|
||||
let!(:start_of_july) { Time.local(year, 7) }
|
||||
|
||||
let!(:updater) { UpdateBillablePeriods.new }
|
||||
|
||||
@@ -508,7 +509,7 @@ describe UpdateBillablePeriods do
|
||||
end
|
||||
|
||||
context "cleaning up untouched billable periods" do
|
||||
let(:job_start_time) { Time.now }
|
||||
let(:job_start_time) { Time.zone.now }
|
||||
let(:enterprise) { create(:enterprise) }
|
||||
# Updated after start
|
||||
let!(:bp1) { create(:billable_period, enterprise: enterprise, updated_at: job_start_time + 2.seconds, begins_at: start_of_july, ends_at: start_of_july + 5.days ) }
|
||||
@@ -549,9 +550,8 @@ describe UpdateBillablePeriods do
|
||||
|
||||
describe "validation spec" do
|
||||
# Chose july to test with because June has 30 days and so is easy to calculate end date for shop trial
|
||||
let!(:start_of_july) { Time.now.beginning_of_year + 6.months }
|
||||
|
||||
let!(:year) { Time.now.year }
|
||||
let!(:year) { Time.zone.now.year }
|
||||
let!(:start_of_july) { Time.local(year, 7) }
|
||||
|
||||
let!(:enterprise) { create(:supplier_enterprise, sells: 'any') }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user