mirror of
https://github.com/internetee/registry.git
synced 2025-08-03 16:32:04 +02:00
parent
3741e2d2a3
commit
58ae53b1e6
17 changed files with 264 additions and 13 deletions
|
@ -1,6 +1,7 @@
|
|||
module Billing
|
||||
class Price < ActiveRecord::Base
|
||||
include Versions
|
||||
include Concerns::Billing::Price::Expirable
|
||||
has_paper_trail class_name: '::PriceVersion'
|
||||
|
||||
self.auto_html5_validation = false
|
||||
|
@ -11,6 +12,7 @@ module Billing
|
|||
validates :operation_category, inclusion: { in: Proc.new { |price| price.class.operation_categories } }
|
||||
validates :duration, inclusion: { in: Proc.new { |price| price.class.durations } }
|
||||
|
||||
alias_attribute :expire_time, :valid_to
|
||||
monetize :price_cents, allow_nil: true, numericality: { greater_than_or_equal_to: 0 }
|
||||
after_initialize :init_values
|
||||
|
||||
|
|
21
app/models/concerns/billing/price/expirable.rb
Normal file
21
app/models/concerns/billing/price/expirable.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
module Concerns::Billing::Price::Expirable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
class_methods do
|
||||
def unexpired
|
||||
where("#{attribute_alias(:expire_time)} >= ?", Time.zone.now)
|
||||
end
|
||||
|
||||
def expired
|
||||
where("#{attribute_alias(:expire_time)} < ?", Time.zone.now)
|
||||
end
|
||||
end
|
||||
|
||||
def expire
|
||||
self[:valid_to] = Time.zone.now - 1
|
||||
end
|
||||
|
||||
def expired?
|
||||
expire_time.past?
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue