mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Add Voucher#vine?
And small refactor
This commit is contained in:
committed by
Rachel Arnould
parent
b30096317c
commit
c17eddd69b
@@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: false
|
||||
|
||||
class Voucher < ApplicationRecord
|
||||
VINE_TYPE = "VINE".freeze
|
||||
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
acts_as_paranoid
|
||||
@@ -18,8 +20,8 @@ class Voucher < ApplicationRecord
|
||||
|
||||
TYPES = ["Vouchers::FlatRate", "Vouchers::PercentageRate"].freeze
|
||||
|
||||
scope :vine, -> { where(voucher_type: "VINE") }
|
||||
scope :not_vine, -> { where.not(voucher_type: "VINE").or(where(voucher_type: nil)) }
|
||||
scope :vine, -> { where(voucher_type: VINE_TYPE) }
|
||||
scope :not_vine, -> { where.not(voucher_type: VINE_TYPE).or(where(voucher_type: nil)) }
|
||||
|
||||
def code=(value)
|
||||
super(value.to_s.strip)
|
||||
@@ -45,6 +47,10 @@ class Voucher < ApplicationRecord
|
||||
order.adjustments.create(adjustment_attributes)
|
||||
end
|
||||
|
||||
def vine?
|
||||
voucher_type == VINE_TYPE
|
||||
end
|
||||
|
||||
# The following method must be overriden in a concrete voucher.
|
||||
def display_value
|
||||
raise NotImplementedError, 'please use concrete voucher'
|
||||
|
||||
Reference in New Issue
Block a user