Permalink
Browse files

Invoice line item date defaults to invoice date, when not provided

  • Loading branch information...
1 parent 0cc8eb0 commit 14a3bc47ebb93d50475bee6a5b9a5c6ec99b45fb @up_the_irons committed Feb 1, 2012
Showing with 9 additions and 0 deletions.
  1. +9 −0 lib/models/invoices_line_item.rb
@@ -1,3 +1,12 @@
class InvoicesLineItem < ActiveRecord::Base
belongs_to :invoice
+
+ before_validation :assign_date
+ validates_presence_of :date
+
+ def assign_date
+ if date.nil?
+ self.date = invoice.date
+ end
+ end
end

0 comments on commit 14a3bc4

Please sign in to comment.