class Accounting::InvoiceCharge < ApplicationRecord
  audited

  belongs_to :invoice
  belongs_to :charge, class_name: 'Accounting::Transaction', foreign_key: :transaction_id

  validate :voided_charge

  private
    def voided_charge
      return unless charge.void

      invoice.errors.add(:base, 'Charges attached to an invoice cannot be voided')
    end
end
