Added removal for deleted entery while syncing

Added Invoices & Estimates to QBO#Index
This commit is contained in:
2016-02-28 12:07:58 -05:00
parent 82a273c0c2
commit ad4ce232b5
7 changed files with 78 additions and 9 deletions

View File

@@ -24,12 +24,24 @@ class QboCustomer < ActiveRecord::Base
end
def self.update_all
service = get_base.service
# Update the customer table
get_base.service.all.each { |customer|
service.all.each { |customer|
qbo_customer = QboCustomer.find_or_create_by(id: customer.id)
qbo_customer.id = customer.id
qbo_customer.name = customer.display_name
qbo_customer.save!
}
#remove deleted customers
all.each { |customer|
begin
service.fetch_by_id(customer.id)
rescue
delete_all(id: customer.id)
end
}
end
end

View File

@@ -19,12 +19,23 @@ class QboEmployee < ActiveRecord::Base
end
def self.update_all
service = get_base.service
# Update the item table
get_base.service.all.each { |employee|
service.all.each { |employee|
qbo_employee = QboEmployee.find_or_create_by(id: employee.id)
qbo_employee.name = employee.display_name
qbo_employee.id = employee.id
qbo_employee.save!
}
#remove deleted employees
all.each { |employee|
begin
service.fetch_by_id(employee.id)
rescue
delete_all(id: employee.id)
end
}
end
end

View File

@@ -19,13 +19,24 @@ class QboEstimate < ActiveRecord::Base
end
def self.update_all
service = get_base.service
# Update the item table
get_base.service.all.each { |estimate|
service.all.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!
}
#remove deleted estimates
all.each { |estimate|
begin
service.fetch_by_id(estimate.id)
rescue
delete_all(id: estimate.id)
end
}
end
def self.update(id)

View File

@@ -19,13 +19,25 @@ class QboInvoice < ActiveRecord::Base
end
def self.update_all
service = get_base.service
# Update the item table
get_base.service.all.each { |invoice|
service.all.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!
}
#remove deleted invoices
all.each { |invoice|
begin
service.fetch_by_id(invoice.id)
rescue
delete_all(id: invoice.id)
end
}
end
def self.update(id)

View File

@@ -19,12 +19,23 @@ class QboItem < ActiveRecord::Base
end
def self.update_all
service = get_base.service
# Update the item table
get_base.service.find_by(:type, "Service").each { |item|
service.find_by(:type, "Service").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!
}
#remove deleted items
all.each { |item|
begin
service.fetch_by_id(item.id)
rescue
delete_all(id: item.id)
end
}
end
end