2019-01-13 07:05:54 +01:00
|
|
|
class StockChange < ApplicationRecord
|
2020-08-01 02:49:15 +02:00
|
|
|
belongs_to :delivery, optional: true, foreign_key: 'stock_event_id'
|
|
|
|
belongs_to :order, optional: true
|
|
|
|
belongs_to :stock_taking, optional: true, foreign_key: 'stock_event_id'
|
2013-03-16 17:53:24 +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
|