Update customer.rb

This commit is contained in:
2016-05-02 10:57:30 -04:00
parent b6f0b35bf0
commit 781a1bfe61

View File

@@ -15,6 +15,8 @@ class Customer < ActiveRecord::Base
has_many :qbo_purchases
has_many :vehicles
before_save :qbo
attr_accessible :name
validates_presence_of :id, :name
@@ -50,6 +52,14 @@ class Customer < ActiveRecord::Base
end
end
# Updates the customer's primary phone number
def primary_phone=(n)
Quickbooks::Model::TelephoneNumber.new
pn.free_form_number = n
@details.primary_phone = pn
push
end
# returns the customer's mobile phone
def mobile_phone
begin
@@ -59,6 +69,14 @@ class Customer < ActiveRecord::Base
end
end
# Updates the custome's mobile phone number
def mobile_phone=(n)
Quickbooks::Model::TelephoneNumber.new
pn.free_form_number = n
@details.mobile_phone = pn
push
end
# returns the customer's notes
def notes
return @details.notes if @details
@@ -68,7 +86,7 @@ class Customer < ActiveRecord::Base
def notes=(s)
customer = get_customer(self.id)
customer.notes = s
get_base.update(customer)
push
end
# returns the bases QBO service for customers
@@ -105,6 +123,23 @@ class Customer < ActiveRecord::Base
private
def push
begin
get_base.update(@details)
rescue
return nil
end
end
def qbo
if new_record?
customer = Quickbooks::Model::Customer.new
customer.display_name = self.name
@details = get_base.create(customer)
self.id = @details.id
end
end
# init details
def get_details
t= Thread.new {