foodsoft/app/models/delivery.rb

22 lines
520 B
Ruby
Raw Normal View History

class Delivery < ActiveRecord::Base
belongs_to :supplier, :with_deleted => true
2009-01-18 17:42:51 +01:00
has_one :invoice
has_many :stock_changes, :dependent => :destroy
scope :recent, :order => 'created_at DESC', :limit => 10
2009-01-18 17:42:51 +01:00
validates_presence_of :supplier_id
accepts_nested_attributes_for :stock_changes, :allow_destroy => :true
def new_stock_changes=(stock_change_attributes)
for attributes in stock_change_attributes
stock_changes.build(attributes) unless attributes[:quantity].to_i == 0
end
end
end