mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-09 03:20:21 +00:00
This is so the relation
`belongs_to :originator, -> { with_deleted }, polymorphic: true`
setup in Spree::Adjustement works as expected.
31 lines
572 B
Ruby
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
|