Move code from localize_input gem into Foodsoft

This commit is contained in:
Patrick Gansterer 2022-02-03 08:37:38 +01:00
parent c59715381e
commit 6a3636d8cb
9 changed files with 33 additions and 8 deletions

View file

@ -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'

View file

@ -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

View file

@ -1,4 +1,5 @@
class Article < ApplicationRecord
include LocalizeInput
include PriceCalculation
# @!attribute name

View file

@ -1,4 +1,5 @@
class ArticlePrice < ApplicationRecord
include LocalizeInput
include PriceCalculation
# @!attribute price

View file

@ -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

View 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

View file

@ -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

View file

@ -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

View file

@ -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'