Files
openfoodnetwork/app/models/subscription_line_item.rb
cyrillefr 37814c46e5 Fix cop RedundantPresenceValidationOnBelongs
- presence: true is redundant since Rails 5.0 BUT applies
  with new default config of
  belongs_to_required_by_default to true
  Lots of files with belongs_to_required_by_default = false
  (backward compatibility)
  So: deleting this setting implies to adding optional: true
  on belongs_to relations where there is no explicit check for presence.
  And also to delete redundant presence: true
  The implicit becomes the explicit and vice versa
- updated toto list
2024-04-15 19:32:23 +02:00

24 lines
630 B
Ruby

# frozen_string_literal: true
class SubscriptionLineItem < ApplicationRecord
belongs_to :subscription, inverse_of: :subscription_line_items
belongs_to :variant, -> { with_deleted }, class_name: 'Spree::Variant'
validates :quantity, presence: true, numericality: { only_integer: true }
default_scope { order('id ASC') }
scope :nil_price_estimate, -> { where(price_estimate: nil) }
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