diff --git a/app/models/qbo_invoice.rb b/app/models/qbo_invoice.rb index 0091231..befb625 100644 --- a/app/models/qbo_invoice.rb +++ b/app/models/qbo_invoice.rb @@ -164,5 +164,35 @@ class QboInvoice < ActiveRecord::Base logger.error "Failed to update invoice" end end + + # Magic Method + # Maps Get/Set methods to QBO invoice object + def method_missing(sym, *arguments) + # Check to see if the method exists + if Quickbooks::Model::Invoice.method_defined?(sym) + # download details if required + pull unless @details + method_name = sym.to_s + # Setter + if method_name[-1, 1] == "=" + @details.method(method_name).call(arguments[0]) + # Getter + else + return @details.method(method_name).call + end + end + end + + private + + # pull the details + def pull + begin + raise Exception unless self.id + @details = Qbo.get_base(:invoice).fetch_by_id(self.id) + rescue Exception => e + @details = Quickbooks::Model::Invoice.new + end + end end diff --git a/app/views/invoices/_list.html.erb b/app/views/invoices/_list.html.erb index af532a1..81c9a54 100644 --- a/app/views/invoices/_list.html.erb +++ b/app/views/invoices/_list.html.erb @@ -2,7 +2,7 @@ <% @customer.qbo_invoices.each do |invoice| %>