Move voucher value to the model

Use Spree::Money to display amount with currency
This commit is contained in:
Gaetan Craig-Riou
2023-03-07 10:22:41 +11:00
parent 094fc039e9
commit 04748b6e0e
3 changed files with 11 additions and 3 deletions

View File

@@ -4,4 +4,12 @@ class Voucher < ApplicationRecord
belongs_to :enterprise
validates :code, presence: true, uniqueness: { scope: :enterprise_id }
def value
10
end
def display_value
Spree::Money.new(value)
end
end

View File

@@ -19,7 +19,7 @@
- @enterprise.vouchers.each do |voucher|
%tr
%td= voucher.code
%td $10
%td= voucher.display_value
%td
%td
%td

View File

@@ -19,5 +19,5 @@
.alpha.four.columns
= f.label :amount, t('.voucher_amount')
.omega.eight.columns
$
= f.text_field :amount, value: 10, disabled: true
= Spree::Money.currency_symbol
= f.text_field :amount, value: @voucher.value, disabled: true