From c17eddd69b8f4a914256fd9fc35dadfe4ffc7de7 Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Mon, 21 Oct 2024 21:46:58 +1100 Subject: [PATCH] Add Voucher#vine? And small refactor --- app/models/voucher.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/models/voucher.rb b/app/models/voucher.rb index eaa1d2273b..52ad6f2ef7 100644 --- a/app/models/voucher.rb +++ b/app/models/voucher.rb @@ -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'