2009-01-08 16:33:27 +01:00
|
|
|
# == Schema Information
|
2009-02-02 16:35:43 +01:00
|
|
|
# Schema version: 20090119155930
|
2009-01-08 16:33:27 +01:00
|
|
|
#
|
|
|
|
# Table name: deliveries
|
|
|
|
#
|
2009-02-02 16:35:43 +01:00
|
|
|
# id :integer not null, primary key
|
|
|
|
# supplier_id :integer
|
2009-01-08 16:33:27 +01:00
|
|
|
# delivered_on :date
|
|
|
|
# created_at :datetime
|
|
|
|
#
|
|
|
|
|
|
|
|
class Delivery < ActiveRecord::Base
|
|
|
|
|
|
|
|
belongs_to :supplier
|
2009-01-18 17:42:51 +01:00
|
|
|
has_one :invoice
|
2009-02-06 16:26:35 +01:00
|
|
|
has_many :stock_changes, :dependent => :destroy
|
2009-01-08 16:33:27 +01:00
|
|
|
|
2009-01-18 17:42:51 +01:00
|
|
|
named_scope :recent, :order => 'created_at DESC', :limit => 10
|
|
|
|
|
2009-01-08 16:33:27 +01:00
|
|
|
validates_presence_of :supplier_id
|
2009-01-16 02:17:49 +01:00
|
|
|
|
2009-05-17 16:11:39 +02:00
|
|
|
accepts_nested_attributes_for :stock_changes, :allow_destroy => :true
|
|
|
|
|
|
|
|
def new_stock_changes=(stock_change_attributes)
|
2009-01-16 02:17:49 +01:00
|
|
|
for attributes in stock_change_attributes
|
2009-02-06 17:06:08 +01:00
|
|
|
stock_changes.build(attributes) unless attributes[:quantity].to_i == 0
|
2009-01-16 02:17:49 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-01-08 16:33:27 +01:00
|
|
|
end
|