Merge pull request #6615 from Matt-Yorkley/money

Money!
This commit is contained in:
Pau Pérez Fabregat
2021-01-08 13:24:14 +01:00
committed by GitHub
5 changed files with 18 additions and 33 deletions

View File

@@ -27,7 +27,7 @@ gem 'cancan', '~> 1.6.10'
gem 'ffaker'
gem 'highline', '2.0.3' # Necessary for the install generator
gem 'json'
gem 'money', '< 6.1.0'
gem 'monetize', '~> 1.1'
gem 'paranoia', '~> 2.4'
gem 'ransack', '~> 1.8.10'
gem 'state_machines-activerecord'

View File

@@ -457,9 +457,10 @@ GEM
mini_racer (0.2.15)
libv8 (> 7.3)
minitest (5.14.3)
money (5.0.0)
i18n (~> 0.4)
json
monetize (1.9.4)
money (~> 6.12)
money (6.13.8)
i18n (>= 0.6.4, <= 2)
msgpack (1.3.3)
multi_json (1.15.0)
multi_xml (0.6.0)
@@ -789,7 +790,7 @@ DEPENDENCIES
knapsack
letter_opener (>= 1.4.1)
mini_racer (= 0.2.15)
money (< 6.1.0)
monetize (~> 1.1)
oauth2 (~> 1.4.4)
ofn-qz!
order_management!

View File

@@ -1,4 +1,4 @@
require 'spree/money_decorator'
require 'spree/money'
module Spree
module ReportsHelper

View File

@@ -9,7 +9,7 @@ module Spree
delegate :cents, to: :money
def initialize(amount, options = {})
@money = ::Money.parse([amount, (options[:currency] || Spree::Config[:currency])].join)
@money = ::Monetize.parse([amount, (options[:currency] || Spree::Config[:currency])].join)
@options = {}
@options[:with_currency] = Spree::Config[:display_currency]
@options[:symbol_position] = Spree::Config[:currency_symbol_position].to_sym
@@ -21,6 +21,11 @@ module Spree
@options[:symbol_position] = @options[:symbol_position].to_sym
end
# Return the currency symbol (on its own) for the current default currency
def self.currency_symbol
::Money.new(0, Spree::Config[:currency]).symbol
end
def to_s
@money.format(@options)
end
@@ -30,11 +35,15 @@ module Spree
if options[:html]
# 1) prevent blank, breaking spaces
# 2) prevent escaping of HTML character entities
output = output.gsub(" ", "&nbsp;").html_safe
output = output.sub(" ", "&nbsp;").html_safe
end
output
end
def format(options = {})
@money.format(@options.merge!(options))
end
def ==(other)
@money == other.money
end

View File

@@ -1,25 +0,0 @@
Spree::Money.class_eval do
# return the currency symbol (on its own) for the current default currency
def self.currency_symbol
Money.new(0, Spree::Config[:currency]).symbol
end
def rounded
@options[:no_cents] = true if @money.dollars % 1 == 0
to_s
end
def to_html(options = { html: true })
output = @money.format(@options.merge(options))
if options[:html]
# 1) prevent blank, breaking spaces
# 2) prevent escaping of HTML character entities
output = output.sub(" ", "&nbsp;").html_safe
end
output
end
def format(options = {})
@money.format(@options.merge!(options))
end
end