diff --git a/app/models/qbo_estimate.rb b/app/models/qbo_estimate.rb index d43fe06..ee220b7 100644 --- a/app/models/qbo_estimate.rb +++ b/app/models/qbo_estimate.rb @@ -62,5 +62,35 @@ class QboEstimate < ActiveRecord::Base estimate = base.fetch_by_id(id) return base.pdf(estimate) end + + # Magic Method + # Maps Get/Set methods to QBO estimate object + def method_missing(sym, *arguments) + # Check to see if the method exists + if Quickbooks::Model::Estimate.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(:estimate).fetch_by_id(self.id) + rescue Exception => e + @details = Quickbooks::Model::Estimate.new + end + end end diff --git a/app/views/estimates/_list.html.erb b/app/views/estimates/_list.html.erb index 0c7dfc9..42cda5d 100644 --- a/app/views/estimates/_list.html.erb +++ b/app/views/estimates/_list.html.erb @@ -2,7 +2,7 @@ <% @customer.qbo_estimates.each do |estimate| %>
- <%= link_to "##{estimate.doc_number}", estimate_path(estimate), target: :_blank %> + <%= link_to "##{estimate.doc_number}", estimate_path(estimate), target: :_blank %> <%= estimate.txn_date %>
<% end %>