From 04748b6e0e7c5cd20274405e880cbd4e7e4daebf Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Tue, 7 Mar 2023 10:22:41 +1100 Subject: [PATCH] Move voucher value to the model Use Spree::Money to display amount with currency --- app/models/voucher.rb | 8 ++++++++ app/views/admin/enterprises/form/_vouchers.html.haml | 2 +- app/views/admin/vouchers/new.html.haml | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/models/voucher.rb b/app/models/voucher.rb index a36da2f218..28c74ca7de 100644 --- a/app/models/voucher.rb +++ b/app/models/voucher.rb @@ -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 diff --git a/app/views/admin/enterprises/form/_vouchers.html.haml b/app/views/admin/enterprises/form/_vouchers.html.haml index 608ae5dd56..66492b0b50 100644 --- a/app/views/admin/enterprises/form/_vouchers.html.haml +++ b/app/views/admin/enterprises/form/_vouchers.html.haml @@ -19,7 +19,7 @@ - @enterprise.vouchers.each do |voucher| %tr %td= voucher.code - %td $10 + %td= voucher.display_value %td %td %td diff --git a/app/views/admin/vouchers/new.html.haml b/app/views/admin/vouchers/new.html.haml index f35befdd67..806d49856b 100644 --- a/app/views/admin/vouchers/new.html.haml +++ b/app/views/admin/vouchers/new.html.haml @@ -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