mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-04-03 06:59:14 +00:00
Obsolete BillablePeriods only deleted if their associated order is not already complete
This commit is contained in:
@@ -91,10 +91,10 @@ class UpdateBillablePeriods
|
||||
|
||||
def clean_up_untouched_billable_periods_for(enterprise, job_start_time)
|
||||
# Snag and then delete any BillablePeriods which overlap
|
||||
obsolete_billable_periods = enterprise.billable_periods.where('ends_at > (?) AND begins_at < (?) AND updated_at < (?)', start_date, end_date, job_start_time)
|
||||
obsolete_billable_periods = enterprise.billable_periods.where('ends_at > (?) AND begins_at < (?) AND billable_periods.updated_at < (?)', start_date, end_date, job_start_time)
|
||||
|
||||
if obsolete_billable_periods.any?
|
||||
current_billable_periods = enterprise.billable_periods.where('ends_at >= (?) AND begins_at <= (?) AND updated_at > (?)', start_date, end_date, job_start_time)
|
||||
current_billable_periods = enterprise.billable_periods.where('ends_at >= (?) AND begins_at <= (?) AND billable_periods.updated_at > (?)', start_date, end_date, job_start_time)
|
||||
|
||||
Delayed::Worker.logger.info "#{enterprise.name} #{start_date.strftime("%F %T")} #{job_start_time.strftime("%F %T")}"
|
||||
Delayed::Worker.logger.info "#{obsolete_billable_periods.first.updated_at.strftime("%F %T")}"
|
||||
@@ -105,7 +105,9 @@ class UpdateBillablePeriods
|
||||
})
|
||||
end
|
||||
|
||||
obsolete_billable_periods.each(&:delete)
|
||||
obsolete_billable_periods.includes({ account_invoice: :order}).
|
||||
where('spree_orders.state <> \'complete\' OR account_invoices.order_id IS NULL').
|
||||
each(&:delete)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
Reference in New Issue
Block a user