Files
openfoodnetwork/app/models/voucher.rb
Gaetan Craig-Riou b6213b25e9 add acts_as_paranoid to voucher
This is so the relation
`belongs_to :originator, -> { with_deleted }, polymorphic: true`
setup in Spree::Adjustement works as expected.
2023-05-15 13:42:37 +10:00

31 lines
572 B
Ruby

# frozen_string_literal: false
class Voucher < ApplicationRecord
acts_as_paranoid
include CalculatedAdjustments
belongs_to :enterprise
has_many :adjustments, as: :originator, class_name: 'Spree::Adjustment'
validates :code, presence: true, uniqueness: { scope: :enterprise_id }
before_validation :add_calculator
def value
10
end
def display_value
Spree::Money.new(value)
end
private
# For now voucher are only flat rate of 10
def add_calculator
self.calculator = Calculator::FlatRate.new(preferred_amount: -value)
end
end