mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2025-11-08 17:04:23 -05:00
Added Private Note Scanning
Also removed redundant checks
This commit is contained in:
@@ -46,32 +46,46 @@ class QboInvoice < ActiveRecord::Base
|
||||
process_invoice invoice
|
||||
end
|
||||
|
||||
# processes the invoice into the system
|
||||
def self.process_invoice(invoice)
|
||||
|
||||
is_changed = false
|
||||
|
||||
# Scan the line items for hashtags and attach to the applicable issues
|
||||
invoice.line_items.each { |line|
|
||||
if line.description
|
||||
line.description.scan(/#(\w+)/).flatten.each { |issue|
|
||||
i = Issue.find_by_id(issue.to_i)
|
||||
private
|
||||
|
||||
# Attach the invoice to the issue
|
||||
def self.attach_to_issue(issue, invoice)
|
||||
# Load the invoice into the database
|
||||
qbo_invoice = QboInvoice.find_or_create_by(id: invoice.id)
|
||||
qbo_invoice.doc_number = invoice.doc_number
|
||||
qbo_invoice.id = invoice.id
|
||||
qbo_invoice.save!
|
||||
|
||||
# Attach the invoice to the issue
|
||||
unless i.qbo_invoices.include?(qbo_invoice)
|
||||
i.qbo_invoices << qbo_invoice
|
||||
i.save!
|
||||
unless issue.qbo_invoices.include?(qbo_invoice)
|
||||
issue.qbo_invoices << qbo_invoice
|
||||
issue.save!
|
||||
end
|
||||
end
|
||||
|
||||
# processes the invoice into the system
|
||||
def self.process_invoice(invoice)
|
||||
|
||||
is_changed = false
|
||||
|
||||
# Check the private notes
|
||||
invoice.private_note.scan(/#(\w+)/).flatten.each { |issue|
|
||||
attach_to_issue(Issue.find_by_id(issue.to_i), invoice)
|
||||
}
|
||||
|
||||
# Scan the line items for hashtags and attach to the applicable issues
|
||||
invoice.line_items.each { |line|
|
||||
if line.description
|
||||
line.description.scan(/#(\w+)/).flatten.each { |issue|
|
||||
attach_to_issue(Issue.find_by_id(issue.to_i), invoice)
|
||||
}
|
||||
end
|
||||
}
|
||||
|
||||
# update the invoive custom fields with infomation from the work ticket if available
|
||||
invoice.custom_fields.each { |cf|
|
||||
|
||||
# TODO Add some hooks here
|
||||
|
||||
# VIN from the attached vehicle
|
||||
begin
|
||||
if cf.name.eql? "VIN"
|
||||
@@ -123,9 +137,8 @@ class QboInvoice < ActiveRecord::Base
|
||||
# Nothing to do here, there is no match
|
||||
end
|
||||
}
|
||||
}
|
||||
end
|
||||
}
|
||||
|
||||
# TODO Add some hooks here
|
||||
|
||||
# Push updates
|
||||
get_base.update(invoice) if is_changed
|
||||
|
||||
Reference in New Issue
Block a user