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
|
accepts_nested_attributes_for :p_product_ref_specs, allow_destroy: true
|
||||||
|
|
||||||
#validates :ct_price_ht, :presence => true
|
#validates :ct_price_ht, :presence => true
|
||||||
|
validate :ean, :is_integer
|
||||||
|
|
||||||
has_many :p_customer_product_prices, :dependent => :destroy
|
has_many :p_customer_product_prices, :dependent => :destroy
|
||||||
accepts_nested_attributes_for :p_customer_product_prices, allow_destroy: true
|
accepts_nested_attributes_for :p_customer_product_prices, allow_destroy: true
|
||||||
@ -167,4 +167,10 @@ class PProductRef < ApplicationRecord
|
|||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
class AddEanToPProductRefs < ActiveRecord::Migration[6.0]
|
class AddEanToPProductRefs < ActiveRecord::Migration[6.0]
|
||||||
def change
|
def change
|
||||||
add_column :p_product_refs, :ean, :integer
|
add_column :p_product_refs, :ean, :string
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1799,7 +1799,7 @@ ActiveRecord::Schema.define(version: 2021_09_17_124338) do
|
|||||||
t.decimal "ca_dee", precision: 10
|
t.decimal "ca_dee", precision: 10
|
||||||
t.decimal "cc_dee", precision: 10
|
t.decimal "cc_dee", precision: 10
|
||||||
t.decimal "ct_dee", precision: 10
|
t.decimal "ct_dee", precision: 10
|
||||||
t.integer "ean"
|
t.string "ean"
|
||||||
t.string "sorecop_comment"
|
t.string "sorecop_comment"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user