mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2025-11-09 09:24:23 -05:00
Merge branch 'master' of github.com:rickbarrette/redmine_qbo
This commit is contained in:
@@ -75,8 +75,9 @@ class QboController < ApplicationController
|
|||||||
entities = data['eventNotifications'][0]['dataChangeEvent']['entities']
|
entities = data['eventNotifications'][0]['dataChangeEvent']['entities']
|
||||||
|
|
||||||
entities.each do |entity|
|
entities.each do |entity|
|
||||||
puts entity['name']
|
if entity['name'].eql? "Customer"
|
||||||
puts entity['id']
|
Customer.sync(entity['id'].to_i)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# The webhook doesn't require a response but let's make sure
|
# The webhook doesn't require a response but let's make sure
|
||||||
|
|||||||
@@ -140,6 +140,26 @@ class Customer < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# proforms a bruteforce sync operation
|
||||||
|
# This needs to be simplified
|
||||||
|
def self.sync(id)
|
||||||
|
service = Qbo.get_base(:customer).service
|
||||||
|
|
||||||
|
customer = service.find_by_id(id)
|
||||||
|
qbo_customer = Customer.find_or_create_by(id: customer.id)
|
||||||
|
if customer.active?
|
||||||
|
if not qbo_customer.name.eql? customer.display_name
|
||||||
|
qbo_customer.name = customer.display_name
|
||||||
|
qbo_customer.id = customer.id
|
||||||
|
qbo_customer.save_without_push
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if not qbo_customer.new_record?
|
||||||
|
qbo_customer.delete
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Push the updates
|
# Push the updates
|
||||||
def save_with_push
|
def save_with_push
|
||||||
begin
|
begin
|
||||||
|
|||||||
Reference in New Issue
Block a user