Introduced StockTaking. TODO: Dry up the stockit/stock_takings/deliveries controllers/views!
This commit is contained in:
parent
2bb4cdb9d6
commit
951d19db6a
30 changed files with 436 additions and 55 deletions
|
|
@ -35,6 +35,7 @@ class Article < ActiveRecord::Base
|
|||
has_many :article_prices, :order => "created_at"
|
||||
|
||||
named_scope :available, :conditions => {:availability => true}
|
||||
named_scope :not_in_stock, :conditions => {:type => nil}
|
||||
|
||||
# Validations
|
||||
validates_presence_of :name, :unit, :price, :tax, :deposit, :unit_quantity, :supplier_id, :article_category_id
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ class StockArticle < Article
|
|||
|
||||
named_scope :available, :conditions => "quantity > 0"
|
||||
|
||||
before_destroy :check_quantity
|
||||
|
||||
# Update the quantity of items in stock
|
||||
def update_quantity!
|
||||
update_attribute :quantity, stock_changes.collect(&:quantity).sum
|
||||
|
|
@ -46,4 +48,10 @@ class StockArticle < Article
|
|||
end
|
||||
available
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def check_quantity
|
||||
raise "#{name} kann nicht gelöscht werden. Der Lagerbestand ist nicht null." unless quantity == 0
|
||||
end
|
||||
end
|
||||
|
|
|
|||
13
app/models/stock_taking.rb
Normal file
13
app/models/stock_taking.rb
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
class StockTaking < ActiveRecord::Base
|
||||
|
||||
has_many :stock_changes, :dependent => :destroy
|
||||
has_many :stock_articles, :through => :stock_changes
|
||||
|
||||
validates_presence_of :date
|
||||
|
||||
def stock_change_attributes=(stock_change_attributes)
|
||||
for attributes in stock_change_attributes
|
||||
stock_changes.build(attributes) unless attributes[:quantity].to_i == 0
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue