From 02b4f1eb43afb9fe38119431ff0fc40c39ade08b Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Sun, 20 Feb 2022 17:26:24 -0500 Subject: [PATCH] Added Invoice date --- app/models/qbo_invoice.rb | 30 ++++++++++++++++++++++++++++++ app/views/invoices/_list.html.erb | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) 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| %>
- <%= link_to "##{invoice.doc_number}", invoice_path(invoice), target: :_blank %> + <%= link_to "##{invoice.doc_number}", invoice_path(invoice), target: :_blank %> <%= invoice.txn_date %>
<% end %>