Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Invoice < ActiveRecord::Base
- validates_presence_of :refnum
- validates_presence_of :payer
- validates_presence_of :payee
- validates_presence_of :total
- validates_uniqueness_of :refnum, :scope => :payer
- before_save :generate_refnum
- has_many :invoicelines, :dependent => :destroy
- belongs_to :payer, :class_name => "User", :foreign_key => "payer"
- belongs_to :payee, :class_name => "User", :foreign_key => "payee"
- accepts_nested_attributes_for :invoicelines, :allow_destroy => true
- def generate_refnum
- last_id = Invoice.where(:payer => self.payer.id).last.id
- self.refnum = last_id + 1 || 1
- end
- end
Add Comment
Please, Sign In to add comment