mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2025-11-08 08:54:23 -05:00
Update qbo_invoice.rb
This commit is contained in:
@@ -12,8 +12,6 @@ class QboInvoice < ActiveRecord::Base
|
|||||||
unloadable
|
unloadable
|
||||||
|
|
||||||
has_and_belongs_to_many :issues
|
has_and_belongs_to_many :issues
|
||||||
#, :association_foreign_key => 'qbo_invoice_id', :class_name => 'QboInvoice', :join_table => 'issues_qbo_invoices'
|
|
||||||
|
|
||||||
attr_accessible :doc_number
|
attr_accessible :doc_number
|
||||||
validates_presence_of :doc_number
|
validates_presence_of :doc_number
|
||||||
self.primary_key = :id
|
self.primary_key = :id
|
||||||
@@ -23,9 +21,6 @@ class QboInvoice < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.sync
|
def self.sync
|
||||||
#Pull the invoices from the quickbooks server
|
|
||||||
#invoices = get_base.service.all
|
|
||||||
|
|
||||||
last = Qbo.first.last_sync
|
last = Qbo.first.last_sync
|
||||||
|
|
||||||
query = "SELECT Id, DocNumber FROM Invoice"
|
query = "SELECT Id, DocNumber FROM Invoice"
|
||||||
@@ -39,14 +34,8 @@ class QboInvoice < ActiveRecord::Base
|
|||||||
|
|
||||||
# Update the invoice table
|
# Update the invoice table
|
||||||
invoices.each { | invoice |
|
invoices.each { | invoice |
|
||||||
qbo_invoice = find_or_create_by(id: invoice.id)
|
sync_by_id invoice.id
|
||||||
qbo_invoice.doc_number = invoice.doc_number
|
|
||||||
qbo_invoice.id = invoice.id
|
|
||||||
qbo_invoice.save!
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#remove deleted invoices
|
|
||||||
#where.not(invoices.map(&:id)).destroy_all
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.sync_by_id(id)
|
def self.sync_by_id(id)
|
||||||
@@ -74,17 +63,22 @@ class QboInvoice < ActiveRecord::Base
|
|||||||
# 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|
|
||||||
# VIN
|
# VIN
|
||||||
if cf.name.eql? "VIN"
|
begin
|
||||||
vin = Vehicle.find(i.vehicles_id).vin
|
if cf.name.eql? "VIN"
|
||||||
cf.string_value = vin if i.vehicles_id if not cf.string_value.to_s.eql? vin
|
vin = Vehicle.find(i.vehicles_id).vin
|
||||||
break
|
break if vin.blank?
|
||||||
|
cf.string_value = vin if not cf.string_value.to_s.eql? vin
|
||||||
|
break
|
||||||
|
end
|
||||||
|
rescue
|
||||||
|
#do nothing
|
||||||
end
|
end
|
||||||
|
|
||||||
# Custom Values
|
# Custom Values
|
||||||
begin
|
begin
|
||||||
value = i.custom_values.find_by(custom_field_id: CustomField.find_by_name(cf.name).id)
|
value = i.custom_values.find_by(custom_field_id: CustomField.find_by_name(cf.name).id)
|
||||||
if value
|
if not value.value.to_s.blank?
|
||||||
if not cf.string_value.to_s.eql? value.value.to_s and not value.value.to_s.blank?
|
if not cf.string_value.to_s.eql? value.value.to_s
|
||||||
cf.string_value = value.value.to_s
|
cf.string_value = value.value.to_s
|
||||||
is_changed = true
|
is_changed = true
|
||||||
end
|
end
|
||||||
@@ -101,7 +95,6 @@ class QboInvoice < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.update(id)
|
def self.update(id)
|
||||||
# Update the item table
|
|
||||||
invoice = get_base.service.fetch_by_id(id)
|
invoice = get_base.service.fetch_by_id(id)
|
||||||
qbo_invoice = find_or_create_by(id: id)
|
qbo_invoice = find_or_create_by(id: id)
|
||||||
qbo_invoice.doc_number = invoice.doc_number
|
qbo_invoice.doc_number = invoice.doc_number
|
||||||
|
|||||||
Reference in New Issue
Block a user