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
@@ -49,8 +49,6 @@ 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,24 +56,18 @@ 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 # Load the invoice into the database
qbo_invoice = QboInvoice.find_or_create_by(id: invoice.id) qbo_invoice = QboInvoice.find_or_create_by(id: invoice.id)
#if qbo_invoice.new?
qbo_invoice.doc_number = invoice.doc_number qbo_invoice.doc_number = invoice.doc_number
qbo_invoice.id = invoice.id qbo_invoice.id = invoice.id
qbo_invoice.save! qbo_invoice.save!
#end
# Attach the invoice to the issue # Attach the invoice to the issue
unless i.qbo_invoices.include?(qbo_invoice) unless i.qbo_invoices.include?(qbo_invoice)
i.qbo_invoices << qbo_invoice.id i.qbo_invoices << qbo_invoice
i.qbo_invoices.save! i.qbo_invoices.save!
end end
rescue
puts "Something when wrong..."
# do nothing, the reccord exists
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
invoice.custom_fields.each { |cf| invoice.custom_fields.each { |cf|