internetee-registry/app/models/concerns/invoice/cancellable.rb
Artur Beljajev a97728c0f3 Refactor and improve invoices
- `runner 'Invoice.cancel_overdue_invoices'` in `schedule.rb` is
changed to `rake 'invoices:cancel_overdue'`.
- `invoices.payment_term` database column is removed and its value is
hardcoded in UI.
- `invoices.paid_at` is removed as unused
- `invoices.due_date` column's type is now `date`.
- `Invoice#invoice_items` renamed to `Invoice#items` and `Invoice`
interface to get a list of items is unified.
- Default date format in UI.
- Default translations are used.
- Tests improved.
- Specs converted to tests and removed along with factories.
- Database structure improved.
2019-03-14 15:39:24 +02:00

28 lines
515 B
Ruby

module Concerns
module Invoice
module Cancellable
extend ActiveSupport::Concern
included do
scope :non_cancelled, -> { where(cancelled_at: nil) }
end
def cancellable?
unpaid? && not_cancelled?
end
def cancel
raise 'Invoice cannot be cancelled' unless cancellable?
update!(cancelled_at: Time.zone.now)
end
def cancelled?
cancelled_at
end
def not_cancelled?
!cancelled?
end
end
end
end