2009-01-16 02:17:49 +01:00
|
|
|
# == Schema Information
|
2009-03-17 19:43:41 +01:00
|
|
|
# Schema version: 20090317175355
|
2009-01-16 02:17:49 +01:00
|
|
|
#
|
|
|
|
# Table name: stock_changes
|
|
|
|
#
|
2009-02-06 16:26:35 +01:00
|
|
|
# id :integer not null, primary key
|
|
|
|
# delivery_id :integer
|
|
|
|
# order_id :integer
|
|
|
|
# stock_article_id :integer
|
2009-02-06 17:06:08 +01:00
|
|
|
# quantity :integer default(0)
|
2009-02-06 16:26:35 +01:00
|
|
|
# created_at :datetime
|
2009-03-17 19:43:41 +01:00
|
|
|
# stock_taking_id :integer
|
2009-01-16 02:17:49 +01:00
|
|
|
#
|
|
|
|
|
|
|
|
class StockChange < ActiveRecord::Base
|
|
|
|
belongs_to :delivery
|
|
|
|
belongs_to :order
|
2009-02-06 16:26:35 +01:00
|
|
|
belongs_to :stock_article
|
2009-01-16 02:17:49 +01:00
|
|
|
|
2009-02-06 16:26:35 +01:00
|
|
|
validates_presence_of :stock_article_id, :quantity
|
2009-01-16 02:17:49 +01:00
|
|
|
validates_numericality_of :quantity
|
|
|
|
|
|
|
|
after_save :update_article_quantity
|
2009-02-05 16:40:02 +01:00
|
|
|
after_destroy :update_article_quantity
|
2009-01-16 02:17:49 +01:00
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def update_article_quantity
|
2009-02-06 16:26:35 +01:00
|
|
|
stock_article.update_quantity!
|
2009-01-16 02:17:49 +01:00
|
|
|
end
|
|
|
|
end
|