2019-01-13 07:05:54 +01:00
|
|
|
class StockChange < ApplicationRecord
|
2020-08-01 20:11:25 +02:00
|
|
|
belongs_to :delivery, foreign_key: 'stock_event_id'
|
2009-01-16 02:17:49 +01:00
|
|
|
belongs_to :order
|
2020-08-01 20:11:25 +02:00
|
|
|
belongs_to :stock_taking, 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
|