Second part of stock-integration.
Introduced StockArticle and a special page for ordering from stock. StockChanges will be created and the StockArticle.quantity updated in 'order.close!'.
This commit is contained in:
parent
1912a3fd80
commit
c17b63b192
37 changed files with 616 additions and 340 deletions
49
app/models/stock_article.rb
Normal file
49
app/models/stock_article.rb
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
# == Schema Information
|
||||
# Schema version: 20090120184410
|
||||
#
|
||||
# Table name: articles
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# name :string(255) default(""), not null
|
||||
# supplier_id :integer default(0), not null
|
||||
# article_category_id :integer default(0), not null
|
||||
# unit :string(255) default(""), not null
|
||||
# note :string(255)
|
||||
# availability :boolean default(TRUE), not null
|
||||
# manufacturer :string(255)
|
||||
# origin :string(255)
|
||||
# shared_updated_on :datetime
|
||||
# price :decimal(, )
|
||||
# tax :float
|
||||
# deposit :decimal(, ) default(0.0)
|
||||
# unit_quantity :integer default(1), not null
|
||||
# order_number :string(255)
|
||||
# created_at :datetime
|
||||
# updated_at :datetime
|
||||
# quantity :decimal(, ) default(0.0)
|
||||
# deleted_at :datetime
|
||||
# type :string(255)
|
||||
#
|
||||
|
||||
class StockArticle < Article
|
||||
has_many :stock_changes
|
||||
|
||||
named_scope :available, :conditions => "quantity > 0"
|
||||
|
||||
# Update the quantity of items in stock
|
||||
def update_quantity!
|
||||
update_attribute :quantity, stock_changes.collect(&:quantity).sum
|
||||
end
|
||||
|
||||
# Check for unclosed orders and substract its ordered quantity
|
||||
def quantity_available(exclude_order = nil)
|
||||
available = quantity
|
||||
for order in Order.stockit.all(:conditions => "state = 'open' OR state = 'finished'")
|
||||
unless order == exclude_order
|
||||
order_article = order.order_articles.first(:conditions => {:article_id => id})
|
||||
available -= order_article.units_to_order if order_article
|
||||
end
|
||||
end
|
||||
available
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue