Skip to content

Commit

Permalink
Ignore stock level column of Product
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszreszke committed Nov 12, 2024
1 parent b06d158 commit b796822
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions rails_application/app/models/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,20 @@

class Product < ApplicationRecord
self.locking_column = :version
self.ignored_columns = %w[stock_level]

validates :name, presence: true
validates :price, numericality: { greater_than: 0 }
validate :validate_vat_rate
validates :sku, presence: true

has_one :product_catalog, class_name: "Inventory::ProductCatalog", foreign_key: :product_id
has_one :product_catalog,
class_name: "Inventory::ProductCatalog",
foreign_key: :product_id

default_scope { where(latest: true) }

before_create :set_stock_level

def set_stock_level
self.stock_level = 0
end

def validate_vat_rate
unless vat_rate.is_a?(Numeric)
errors.add(:vat_rate, "is not a number")
end
errors.add(:vat_rate, "is not a number") unless vat_rate.is_a?(Numeric)
end
end

0 comments on commit b796822

Please sign in to comment.