Update qbo_invoice.rb

This commit is contained in:
2016-09-13 22:54:52 -04:00
committed by GitHub
parent bbc3b138cf
commit 41313029cd

View File

@@ -11,9 +11,9 @@
class QboInvoice < ActiveRecord::Base class QboInvoice < ActiveRecord::Base
unloadable unloadable
has_and_belongs_to_many :issues belongs_to_many :issues
attr_accessible :doc_number attr_accessible :doc_number, :id
validates_presence_of :doc_number validates_presence_of :doc_number, :id
self.primary_key = :id self.primary_key = :id
def self.get_base def self.get_base
@@ -48,9 +48,7 @@ class QboInvoice < ActiveRecord::Base
# processes the invoice into the system # processes the invoice into the system
def self.process_invoice(invoice) def self.process_invoice(invoice)
is_changed = false is_changed = false
# Scan the line items for hashtags and attach to the applicable issues # Scan the line items for hashtags and attach to the applicable issues
@@ -58,23 +56,17 @@ class QboInvoice < ActiveRecord::Base
if line.description if line.description
line.description.scan(/#(\w+)/).flatten.each { |issue| line.description.scan(/#(\w+)/).flatten.each { |issue|
i = Issue.find_by_id(issue.to_i) i = Issue.find_by_id(issue.to_i)
begin
# Load the invoice into the database
qbo_invoice = QboInvoice.find_or_create_by(id: invoice.id)
#if qbo_invoice.new?
qbo_invoice.doc_number = invoice.doc_number
qbo_invoice.id = invoice.id
qbo_invoice.save!
#end
# Attach the invoice to the issue # Load the invoice into the database
unless i.qbo_invoices.include?(qbo_invoice) qbo_invoice = QboInvoice.find_or_create_by(id: invoice.id)
i.qbo_invoices << qbo_invoice.id qbo_invoice.doc_number = invoice.doc_number
i.qbo_invoices.save! qbo_invoice.id = invoice.id
end qbo_invoice.save!
rescue
puts "Something when wrong..." # Attach the invoice to the issue
# do nothing, the reccord exists unless i.qbo_invoices.include?(qbo_invoice)
i.qbo_invoices << qbo_invoice
i.qbo_invoices.save!
end end
# update the invoive custom fields with infomation from the work ticket if available # update the invoive custom fields with infomation from the work ticket if available