mirror of
https://github.com/internetee/registry.git
synced 2025-08-05 17:28:18 +02:00
Overdue invoice cancelling
This commit is contained in:
parent
d708a953a4
commit
6070c31ed6
3 changed files with 13 additions and 1 deletions
|
@ -7,6 +7,8 @@ class Invoice < ActiveRecord::Base
|
|||
|
||||
accepts_nested_attributes_for :invoice_items
|
||||
|
||||
scope :unbinded, -> { where('id NOT IN (SELECT invoice_id FROM account_activities)') }
|
||||
|
||||
attr_accessor :billing_email
|
||||
validates :billing_email, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i }, allow_blank: true
|
||||
|
||||
|
@ -113,7 +115,11 @@ class Invoice < ActiveRecord::Base
|
|||
class << self
|
||||
def cancel_overdue_invoices
|
||||
cr_at = Time.zone.now - Setting.days_to_keep_overdue_invoices_active.days
|
||||
self.class.where('due_date < ? AND created_at < ?', Time.zone.now, cr_at)
|
||||
invoices = Invoice.unbinded.where(
|
||||
'due_date < ? AND created_at < ? AND cancelled_at IS NULL', Time.zone.now, cr_at
|
||||
)
|
||||
|
||||
invoices.update_all(cancelled_at: Time.zone.now)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue