Update customer.rb

This commit is contained in:
2016-04-29 08:43:14 -04:00
parent cb07f397e0
commit ed27fc559d

View File

@@ -24,10 +24,8 @@ class Customer < ActiveRecord::Base
# returns true if the customer is active # returns true if the customer is active
def active? def active?
mutex.synchronize do
return @details.active? if @details return @details.active? if @details
end end
end
# returns a human readable string # returns a human readable string
def to_s def to_s
@@ -37,9 +35,7 @@ class Customer < ActiveRecord::Base
# returns the customer's email # returns the customer's email
def email def email
begin begin
mutex.synchronize do
return @details.email_address.address return @details.email_address.address
end
rescue rescue
return nil return nil
end end
@@ -48,9 +44,7 @@ class Customer < ActiveRecord::Base
# returns the customer's primary phone # returns the customer's primary phone
def primary_phone def primary_phone
begin begin
mutex.synchronize do
return @details.primary_phone.free_form_number return @details.primary_phone.free_form_number
end
rescue rescue
return nil return nil
end end
@@ -59,9 +53,7 @@ class Customer < ActiveRecord::Base
# returns the customer's mobile phone # returns the customer's mobile phone
def mobile_phone def mobile_phone
begin begin
mutex.synchronize do
return @details.mobile_phone.free_form_number return @details.mobile_phone.free_form_number
end
rescue rescue
return nil return nil
end end
@@ -69,10 +61,8 @@ class Customer < ActiveRecord::Base
# returns the customer's notes # returns the customer's notes
def notes def notes
mutex.synchronize do
return @details.notes if @details return @details.notes if @details
end end
end
# updates the customer's notes in QBO # updates the customer's notes in QBO
def notes=(s) def notes=(s)
@@ -117,24 +107,21 @@ class Customer < ActiveRecord::Base
# init details # init details
def get_details def get_details
Thread.new { t= Thread.new {
if self.id if self.id
mutex.synchronize do
@details = get_customer(self.id) @details = get_customer(self.id)
end end
end
} }
t.join
end end
# update's the customers name if updated # update's the customers name if updated
def update def update
begin begin
mutex.synchronize do
if not self.name == @detils.display_name if not self.name == @detils.display_name
self.name = @details.display_name self.name = @details.display_name
self.save self.save
end end
end
rescue rescue
return nil return nil
end end