mirror of
https://github.com/internetee/registry.git
synced 2025-07-25 20:18:22 +02:00
Automatic invoice cancelling #2539
This commit is contained in:
parent
7139a0c9ed
commit
7a26b77606
2 changed files with 2 additions and 2 deletions
|
@ -40,7 +40,7 @@ class Invoice < ActiveRecord::Base
|
||||||
|
|
||||||
cr_at = Time.zone.now - Setting.days_to_keep_overdue_invoices_active.days
|
cr_at = Time.zone.now - Setting.days_to_keep_overdue_invoices_active.days
|
||||||
invoices = Invoice.unbinded.where(
|
invoices = Invoice.unbinded.where(
|
||||||
'due_date < ? AND created_at < ? AND cancelled_at IS NULL', Time.zone.now, cr_at
|
'due_date < ? AND cancelled_at IS NULL', cr_at
|
||||||
)
|
)
|
||||||
|
|
||||||
count = invoices.update_all(cancelled_at: Time.zone.now)
|
count = invoices.update_all(cancelled_at: Time.zone.now)
|
||||||
|
|
|
@ -71,7 +71,7 @@ describe Invoice do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should cancel overdue invoices' do
|
it 'should cancel overdue invoices' do
|
||||||
Fabricate(:invoice, created_at: Time.zone.now - 35.days, due_date: Time.zone.now - 1.days)
|
Fabricate(:invoice, created_at: Time.zone.now - 35.days, due_date: Time.zone.now - 30.days)
|
||||||
Invoice.cancel_overdue_invoices
|
Invoice.cancel_overdue_invoices
|
||||||
Invoice.where(cancelled_at: nil).count.should == 1
|
Invoice.where(cancelled_at: nil).count.should == 1
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue