Move code from localize_input gem into Foodsoft
This commit is contained in:
parent
c59715381e
commit
6a3636d8cb
9 changed files with 33 additions and 8 deletions
1
Gemfile
1
Gemfile
|
@ -27,7 +27,6 @@ gem 'haml-rails'
|
|||
gem 'kaminari'
|
||||
gem 'simple_form'
|
||||
gem 'inherited_resources'
|
||||
gem 'localize_input', git: 'https://github.com/carchrae/localize_input.git'
|
||||
gem 'daemons'
|
||||
gem 'doorkeeper'
|
||||
gem 'doorkeeper-i18n'
|
||||
|
|
|
@ -1,9 +1,3 @@
|
|||
GIT
|
||||
remote: https://github.com/carchrae/localize_input.git
|
||||
revision: 597e33bb42a3b0fd58c3ea7d4f5a208c2911b43d
|
||||
specs:
|
||||
localize_input (0.1.0)
|
||||
|
||||
GIT
|
||||
remote: https://github.com/technoweenie/acts_as_versioned.git
|
||||
revision: 63b1fc8529d028fae632fe80ec0cb25df56cd76b
|
||||
|
@ -606,7 +600,6 @@ DEPENDENCIES
|
|||
kaminari
|
||||
less-rails
|
||||
listen
|
||||
localize_input!
|
||||
mailcatcher
|
||||
meta_request
|
||||
midi-smtp-server
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
class Article < ApplicationRecord
|
||||
include LocalizeInput
|
||||
include PriceCalculation
|
||||
|
||||
# @!attribute name
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
class ArticlePrice < ApplicationRecord
|
||||
include LocalizeInput
|
||||
include PriceCalculation
|
||||
|
||||
# @!attribute price
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
class BankTransaction < ApplicationRecord
|
||||
include LocalizeInput
|
||||
# @!attribute external_id
|
||||
# @return [String] Unique Identifier of the transaction within the bank account.
|
||||
# @!attribute date
|
||||
|
|
25
app/models/concerns/localize_input.rb
Normal file
25
app/models/concerns/localize_input.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
module LocalizeInput
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
class_methods do
|
||||
def localize_input_of(*attr_names)
|
||||
attr_names.flatten.each do |attr|
|
||||
define_method "#{attr}=" do |input|
|
||||
begin
|
||||
if input.is_a? String
|
||||
Rails.logger.debug "Input: #{input.inspect}"
|
||||
separator = I18n.t("separator", :scope => "number.format")
|
||||
delimiter = I18n.t("delimiter", :scope => "number.format")
|
||||
input.gsub!(delimiter, "") if input.match(/\d+#{Regexp.escape(delimiter)}+\d+#{Regexp.escape(separator)}+\d+/) # Remove delimiter
|
||||
input.gsub!(separator, ".") # Replace separator with db compatible character
|
||||
end
|
||||
self[attr] = input
|
||||
rescue
|
||||
Rails.logger.warn "Can't localize input: #{input}"
|
||||
self[attr] = input
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,6 +1,8 @@
|
|||
# financial transactions are the foodcoop internal financial transactions
|
||||
# only ordergroups have an account balance and are happy to transfer money
|
||||
class FinancialTransaction < ApplicationRecord
|
||||
include LocalizeInput
|
||||
|
||||
belongs_to :ordergroup, optional: true
|
||||
belongs_to :user
|
||||
belongs_to :financial_link, optional: true
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
# The chronologically order of the Ordergroup - activity are stored in GroupOrderArticleQuantity
|
||||
#
|
||||
class GroupOrderArticle < ApplicationRecord
|
||||
include LocalizeInput
|
||||
|
||||
belongs_to :group_order
|
||||
belongs_to :order_article
|
||||
has_many :group_order_article_quantities, dependent: :destroy
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
class Invoice < ApplicationRecord
|
||||
include CustomFields
|
||||
include LocalizeInput
|
||||
|
||||
belongs_to :supplier
|
||||
belongs_to :created_by, :class_name => 'User', :foreign_key => 'created_by_user_id'
|
||||
|
|
Loading…
Reference in a new issue