Introduced StockChange. Implemented first part of stockit-logic with updating article's quantity.
This commit is contained in:
parent
7ff0467b16
commit
b38025869a
27 changed files with 233 additions and 123 deletions
34
app/models/stock_change.rb
Normal file
34
app/models/stock_change.rb
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
# == Schema Information
|
||||
# Schema version: 20090115232435
|
||||
#
|
||||
# Table name: stock_changes
|
||||
#
|
||||
# id :integer(4) not null, primary key
|
||||
# delivery_id :integer(4)
|
||||
# order_id :integer(4)
|
||||
# article_id :integer(4)
|
||||
# quantity :decimal(6, 2) default(0.0)
|
||||
# created_at :datetime
|
||||
#
|
||||
|
||||
class StockChange < ActiveRecord::Base
|
||||
belongs_to :delivery
|
||||
belongs_to :order
|
||||
belongs_to :article
|
||||
|
||||
validates_presence_of :article_id, :quantity
|
||||
validates_numericality_of :quantity
|
||||
|
||||
after_save :update_article_quantity
|
||||
after_destroy :remove_added_quantity
|
||||
|
||||
protected
|
||||
|
||||
def update_article_quantity
|
||||
article.update_quantity(quantity)
|
||||
end
|
||||
|
||||
def remove_added_quantity
|
||||
article.update_quantity(quantity * -1)
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue