2009-01-08 16:33:27 +01:00
|
|
|
# == Schema Information
|
2009-01-13 19:01:56 +01:00
|
|
|
# Schema version: 20090113111624
|
2009-01-08 16:33:27 +01:00
|
|
|
#
|
|
|
|
# Table name: invoices
|
|
|
|
#
|
|
|
|
# id :integer(4) not null, primary key
|
|
|
|
# supplier_id :integer(4)
|
|
|
|
# delivery_id :integer(4)
|
|
|
|
# number :string(255)
|
|
|
|
# date :date
|
|
|
|
# paid_on :date
|
2009-01-13 19:01:56 +01:00
|
|
|
# note :text
|
2009-01-08 16:33:27 +01:00
|
|
|
# amount :decimal(8, 2) default(0.0), not null
|
|
|
|
# created_at :datetime
|
|
|
|
# updated_at :datetime
|
|
|
|
#
|
|
|
|
|
|
|
|
class Invoice < ActiveRecord::Base
|
|
|
|
|
|
|
|
belongs_to :supplier
|
|
|
|
|
|
|
|
validates_presence_of :supplier_id
|
|
|
|
validates_uniqueness_of :date, :scope => [:supplier_id]
|
|
|
|
|
2009-01-10 19:36:58 +01:00
|
|
|
named_scope :unpaid, :conditions => { :paid_on => nil }
|
|
|
|
|
2009-01-08 16:33:27 +01:00
|
|
|
# Custom attribute setter that accepts decimal numbers using localized decimal separator.
|
|
|
|
def amount=(amount)
|
|
|
|
self[:amount] = String.delocalized_decimal(amount)
|
|
|
|
end
|
|
|
|
end
|