EAN to string + integer validation
This commit is contained in:
parent
7dbed2374c
commit
3720120124
@ -18,7 +18,7 @@ class PProductRef < ApplicationRecord
|
||||
accepts_nested_attributes_for :p_product_ref_specs, allow_destroy: true
|
||||
|
||||
#validates :ct_price_ht, :presence => true
|
||||
|
||||
validate :ean, :is_integer
|
||||
|
||||
has_many :p_customer_product_prices, :dependent => :destroy
|
||||
accepts_nested_attributes_for :p_customer_product_prices, allow_destroy: true
|
||||
@ -167,4 +167,10 @@ class PProductRef < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def is_integer
|
||||
if ean.present? && ean.match(/\A[+-]?\d+\z/).nil?
|
||||
errors.add(:ean, "ne doit être composé que de chiffres")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -1,5 +1,5 @@
|
||||
class AddEanToPProductRefs < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
add_column :p_product_refs, :ean, :integer
|
||||
add_column :p_product_refs, :ean, :string
|
||||
end
|
||||
end
|
||||
|
@ -1799,7 +1799,7 @@ ActiveRecord::Schema.define(version: 2021_09_17_124338) do
|
||||
t.decimal "ca_dee", precision: 10
|
||||
t.decimal "cc_dee", precision: 10
|
||||
t.decimal "ct_dee", precision: 10
|
||||
t.integer "ean"
|
||||
t.string "ean"
|
||||
t.string "sorecop_comment"
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user