mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2025-11-08 17:04:23 -05:00
Simplified all quickbooks inporting
no more loops
This commit is contained in:
@@ -25,12 +25,13 @@ class QboCustomer < ActiveRecord::Base
|
|||||||
|
|
||||||
def self.update_all
|
def self.update_all
|
||||||
customers = get_base.service.all
|
customers = get_base.service.all
|
||||||
|
|
||||||
|
ids = customers.map {|i| i.id}
|
||||||
|
display_names = customers.map {|i| i.display_name}
|
||||||
|
|
||||||
# Update the customer table
|
# Update the customer table
|
||||||
customers.each { |customer|
|
find_or_create_by(id: ids, name: display_names)
|
||||||
qbo_customer = QboCustomer.find_or_create_by(id: customer.id)
|
|
||||||
qbo_customer.name = customer.display_name
|
|
||||||
qbo_customer.save!
|
|
||||||
}
|
|
||||||
#remove deleted customers
|
#remove deleted customers
|
||||||
where.not(customers.map(&:id)).destroy_all
|
where.not(customers.map(&:id)).destroy_all
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -21,12 +21,11 @@ class QboEmployee < ActiveRecord::Base
|
|||||||
def self.update_all
|
def self.update_all
|
||||||
employees = get_base.service.all
|
employees = get_base.service.all
|
||||||
|
|
||||||
# Update the item table
|
ids = employees.map {|i| i.id}
|
||||||
employees.each { |employee|
|
display_names = employees.map {|i| i.display_name}
|
||||||
qbo_employee = QboEmployee.find_or_create_by(id: employee.id)
|
|
||||||
qbo_employee.name = employee.display_name
|
# Update the customer table
|
||||||
qbo_employee.save!
|
find_or_create_by(id: ids, name: display_names)
|
||||||
}
|
|
||||||
|
|
||||||
#remove deleted employees
|
#remove deleted employees
|
||||||
where.not(employees.map(&:id)).destroy_all
|
where.not(employees.map(&:id)).destroy_all
|
||||||
|
|||||||
@@ -21,12 +21,11 @@ class QboEstimate < ActiveRecord::Base
|
|||||||
def self.update_all
|
def self.update_all
|
||||||
estimates = get_base.service.all
|
estimates = get_base.service.all
|
||||||
|
|
||||||
# Update the item table
|
ids = estimates.map {|i| i.id}
|
||||||
estimates.each { |estimate|
|
doc_numbers = estimates.map {|i| i.doc_number}
|
||||||
qbo_estimate = QboEstimate.find_or_create_by(id: estimate.id)
|
|
||||||
qbo_estimate.doc_number = estimate.doc_number
|
# Update the invoice table
|
||||||
qbo_estimate.save!
|
find_or_create_by(id: ids, doc_number: doc_numbers)
|
||||||
}
|
|
||||||
|
|
||||||
#remove deleted estimates
|
#remove deleted estimates
|
||||||
where.not(estimates.map(&:id)).destroy_all
|
where.not(estimates.map(&:id)).destroy_all
|
||||||
|
|||||||
@@ -21,12 +21,11 @@ class QboItem < ActiveRecord::Base
|
|||||||
def self.update_all
|
def self.update_all
|
||||||
items = get_base.service.find_by(:type, "Service")
|
items = get_base.service.find_by(:type, "Service")
|
||||||
|
|
||||||
# Update the item table
|
ids = items.map {|i| i.id}
|
||||||
items.each { |item|
|
names = items.map {|i| i.name}
|
||||||
qbo_item = QboItem.find_or_create_by(id: item.id)
|
|
||||||
qbo_item.name = item.name
|
# Update the invoice table
|
||||||
qbo_item.save!
|
find_or_create_by(id: ids, name: names)
|
||||||
}
|
|
||||||
|
|
||||||
#remove deleted items
|
#remove deleted items
|
||||||
where.not(items.map(&:id)).destroy_all
|
where.not(items.map(&:id)).destroy_all
|
||||||
|
|||||||
Reference in New Issue
Block a user