mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-01 21:47:16 +00:00
Rails 5 introduced this new class to confine application-specific monkey patches to our models only, and not leak into other libraries using ActiveRecord::Base. https://bigbinary.com/blog/application-record-in-rails-5
23 lines
615 B
Ruby
23 lines
615 B
Ruby
class SubscriptionLineItem < ApplicationRecord
|
|
belongs_to :subscription, inverse_of: :subscription_line_items
|
|
belongs_to :variant, -> { with_deleted }, class_name: 'Spree::Variant'
|
|
|
|
validates :subscription, presence: true
|
|
validates :variant, presence: true
|
|
validates :quantity, presence: true, numericality: { only_integer: true }
|
|
|
|
default_scope { order('id ASC') }
|
|
|
|
def total_estimate
|
|
(price_estimate || 0) * (quantity || 0)
|
|
end
|
|
|
|
# Used to calculators to estimate fees
|
|
alias_method :amount, :total_estimate
|
|
|
|
# Used to calculators to estimate fees
|
|
def price
|
|
price_estimate
|
|
end
|
|
end
|