lib/xeroizer/models/invoice.rb in xeroizer-2.20.0 vs lib/xeroizer/models/invoice.rb in xeroizer-3.0.0

- old
+ new

@@ -1,7 +1,8 @@ require "xeroizer/models/attachment" require "xeroizer/models/online_invoice" +require "xeroizer/models/history_record" module Xeroizer module Record class InvoiceModel < BaseModel @@ -14,10 +15,11 @@ set_permissions :read, :write, :update include AttachmentModel::Extensions include OnlineInvoiceModel::Extensions + include HistoryRecordModel::Extensions public # Retrieve the PDF version of the invoice matching the `id`. # @param [String] id invoice's ID. @@ -52,10 +54,11 @@ } unless defined?(INVOICE_STATUS) INVOICE_STATUSES = INVOICE_STATUS.keys.sort include Attachment::Extensions include OnlineInvoice::Extensions + include HistoryRecord::Extensions set_primary_key :invoice_id set_possible_primary_keys :invoice_id, :invoice_number list_contains_summary_only true @@ -89,10 +92,11 @@ has_many :line_items, :complete_on_page => true has_many :payments has_many :credit_notes has_many :prepayments - validates_presence_of :date, :due_date, :unless => :new_record? + validates_presence_of :date, :if => :new_record? + validates_presence_of :due_date, :if => :approved? validates_inclusion_of :type, :in => INVOICE_TYPES validates_inclusion_of :status, :in => INVOICE_STATUSES, :unless => :new_record? validates_inclusion_of :line_amount_types, :in => LINE_AMOUNT_TYPES, :unless => :new_record? validates_associated :contact validates_associated :line_items, :allow_blanks => true, :unless => :approved?