mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2025-11-09 09:24:23 -05:00
Merge branch 'import'
This commit is contained in:
@@ -26,12 +26,18 @@ class QboCustomer < ActiveRecord::Base
|
||||
def self.update_all
|
||||
customers = get_base.service.all
|
||||
|
||||
ids = customers.map {|i| i.id}
|
||||
display_names = customers.map {|i| i.display_name}
|
||||
|
||||
# Update the customer table
|
||||
find_or_create_by(id: ids, name: display_names)
|
||||
delete_all
|
||||
|
||||
transaction do
|
||||
# Update the customer table
|
||||
customers.each { |customer|
|
||||
qbo_customer = QboCustomer.find_or_create_by(id: customer.id)
|
||||
qbo_customer.name = customer.display_name
|
||||
qbo_customer.id = customer.id
|
||||
qbo_customer.save!
|
||||
}
|
||||
end
|
||||
|
||||
#remove deleted customers
|
||||
where.not(customers.map(&:id)).destroy_all
|
||||
end
|
||||
|
||||
@@ -20,12 +20,16 @@ class QboEmployee < ActiveRecord::Base
|
||||
|
||||
def self.update_all
|
||||
employees = get_base.service.all
|
||||
|
||||
ids = employees.map {|i| i.id}
|
||||
display_names = employees.map {|i| i.display_name}
|
||||
|
||||
# Update the customer table
|
||||
find_or_create_by(id: ids, name: display_names)
|
||||
transaction do
|
||||
# Update the item table
|
||||
employees.each { |employee|
|
||||
qbo_employee = find_or_create_by(id: employee.id)
|
||||
qbo_employee.name = employee.display_name
|
||||
qbo_employee.id = employee.id
|
||||
qbo_employee.save!
|
||||
}
|
||||
end
|
||||
|
||||
#remove deleted employees
|
||||
where.not(employees.map(&:id)).destroy_all
|
||||
|
||||
@@ -21,11 +21,15 @@ class QboEstimate < ActiveRecord::Base
|
||||
def self.update_all
|
||||
estimates = get_base.service.all
|
||||
|
||||
ids = estimates.map {|i| i.id}
|
||||
doc_numbers = estimates.map {|i| i.doc_number}
|
||||
|
||||
# Update the invoice table
|
||||
find_or_create_by(id: ids, doc_number: doc_numbers)
|
||||
# Update the item table
|
||||
transaction do
|
||||
estimates.each { |estimate|
|
||||
qbo_estimate = QboEstimate.find_or_create_by(id: estimate.id)
|
||||
qbo_estimate.doc_number = estimate.doc_number
|
||||
qbo_estimate.id = estimate.id
|
||||
qbo_estimate.save!
|
||||
}
|
||||
end
|
||||
|
||||
#remove deleted estimates
|
||||
where.not(estimates.map(&:id)).destroy_all
|
||||
|
||||
@@ -21,11 +21,16 @@ class QboInvoice < ActiveRecord::Base
|
||||
def self.update_all
|
||||
#Pull the invoices from the quickbooks server
|
||||
invoices = get_base.service.all
|
||||
ids = invoices.map {|i| i.id}
|
||||
doc_numbers = invoices.map {|i| i.doc_number}
|
||||
|
||||
# Update the invoice table
|
||||
find_or_create_by(id: ids, doc_number: doc_numbers)
|
||||
transaction do
|
||||
invoices.each { | invoice |
|
||||
qbo_invoice = find_or_create_by(id: invoice.id)
|
||||
qbo_invoice.doc_number = invoice.doc_number
|
||||
qbo_invoice.id = invoice.id
|
||||
qbo_invoice.save!
|
||||
}
|
||||
end
|
||||
|
||||
#remove deleted invoices
|
||||
where.not(invoices.map(&:id)).destroy_all
|
||||
|
||||
@@ -20,12 +20,16 @@ class QboItem < ActiveRecord::Base
|
||||
|
||||
def self.update_all
|
||||
items = get_base.service.find_by(:type, "Service")
|
||||
|
||||
ids = items.map {|i| i.id}
|
||||
names = items.map {|i| i.name}
|
||||
|
||||
# Update the invoice table
|
||||
find_or_create_by(id: ids, name: names)
|
||||
|
||||
transaction do
|
||||
# Update the item table
|
||||
items.each { |item|
|
||||
qbo_item = QboItem.find_or_create_by(id: item.id)
|
||||
qbo_item.name = item.name
|
||||
qbo_item.id = item.id
|
||||
qbo_item.save!
|
||||
}
|
||||
end
|
||||
|
||||
#remove deleted items
|
||||
where.not(items.map(&:id)).destroy_all
|
||||
|
||||
Reference in New Issue
Block a user