Update customer.rb

This commit is contained in:
2016-05-11 11:38:41 -04:00
parent aba1cdf6d9
commit 936a48f205

View File

@@ -20,7 +20,8 @@ class Customer < ActiveRecord::Base
attr_accessible :name, :skip_details attr_accessible :name, :skip_details
validates_presence_of :id, :name validates_presence_of :id, :name
after_initialize :get_details after_initialize :pull
after_save :push
self.primary_key = :id self.primary_key = :id
@@ -57,7 +58,6 @@ class Customer < ActiveRecord::Base
Quickbooks::Model::TelephoneNumber.new Quickbooks::Model::TelephoneNumber.new
pn.free_form_number = n pn.free_form_number = n
@details.primary_phone = pn @details.primary_phone = pn
push
end end
# returns the customer's mobile phone # returns the customer's mobile phone
@@ -74,7 +74,11 @@ class Customer < ActiveRecord::Base
Quickbooks::Model::TelephoneNumber.new Quickbooks::Model::TelephoneNumber.new
pn.free_form_number = n pn.free_form_number = n
@details.mobile_phone = pn @details.mobile_phone = pn
push end
def name=(s)
@details.display_name = s if @details
self.name = s
end end
# returns the customer's notes # returns the customer's notes
@@ -85,7 +89,6 @@ class Customer < ActiveRecord::Base
# updates the customer's notes in QBO # updates the customer's notes in QBO
def notes=(s) def notes=(s)
@details.notes = s if @details @details.notes = s if @details
push
end end
# proforms a bruteforce sync operation # proforms a bruteforce sync operation
@@ -124,7 +127,6 @@ class Customer < ActiveRecord::Base
if name[-1, 1] == "=" if name[-1, 1] == "="
method_name = name[0..-2] method_name = name[0..-2]
@details[method_name] = value @details[method_name] = value
push
else else
begin begin
return @details[name] return @details[name]
@@ -140,7 +142,7 @@ class Customer < ActiveRecord::Base
def push def push
begin begin
tries ||= 3 tries ||= 3
get_base.update(@details) Qbo.get_base(:customer).service.update(@details)
rescue rescue
retry unless (tries -= 1).zero? retry unless (tries -= 1).zero?
end end
@@ -155,8 +157,8 @@ class Customer < ActiveRecord::Base
end end
end end
# init details # pull details
def get_details def pull
begin begin
tries ||= 3 tries ||= 3
@details = get_customer(self.id) @details = get_customer(self.id)