Skip to content

Commit

Permalink
Add validations to stock items and stock movements.
Browse files Browse the repository at this point in the history
  • Loading branch information
dkubb authored and Jeff Dutil committed May 12, 2015
1 parent 3ae91e0 commit d5d2037
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion core/app/models/spree/stock_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ class StockItem < Spree::Base

validates_presence_of :stock_location, :variant
validates_uniqueness_of :variant_id, scope: [:stock_location_id, :deleted_at]
validates :count_on_hand, numericality: { greater_than_or_equal_to: 0 }, if: :verify_count_on_hand?

validates_numericality_of :count_on_hand,
greater_than_or_equal_to: 0,
less_than_or_equal_to: 2**31 - 1,
only_integer: true, if: :verify_count_on_hand?

delegate :weight, :should_track_inventory?, to: :variant

Expand Down
7 changes: 6 additions & 1 deletion core/app/models/spree/stock_movement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ class StockMovement < Spree::Base
after_create :update_stock_item_quantity

validates :stock_item, presence: true
validates :quantity, presence: true
validates :quantity, presence: true, numericality: {
greater_than_or_equal_to: -2**31,
less_than_or_equal_to: 2**31-1,
only_integer: true,
allow_nil: true
}

scope :recent, -> { order('created_at DESC') }

Expand Down

0 comments on commit d5d2037

Please sign in to comment.