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,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…
Add table
Add a link
Reference in a new issue