mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2025-11-09 01:14:23 -05:00
Comments & Such
This commit is contained in:
@@ -10,9 +10,11 @@
|
|||||||
|
|
||||||
class QboCustomer < ActiveRecord::Base
|
class QboCustomer < ActiveRecord::Base
|
||||||
unloadable
|
unloadable
|
||||||
|
|
||||||
has_many :issues
|
has_many :issues
|
||||||
has_many :qbo_purchases
|
has_many :qbo_purchases
|
||||||
has_many :vehicles
|
has_many :vehicles
|
||||||
|
|
||||||
attr_accessible :name
|
attr_accessible :name
|
||||||
validates_presence_of :id, :name
|
validates_presence_of :id, :name
|
||||||
|
|
||||||
@@ -20,38 +22,55 @@ class QboCustomer < ActiveRecord::Base
|
|||||||
|
|
||||||
self.primary_key = :id
|
self.primary_key = :id
|
||||||
|
|
||||||
|
# returns true if the customer is active
|
||||||
def active?
|
def active?
|
||||||
@details.active?
|
@details.active? if @details
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# returns a human readable string
|
||||||
def to_s
|
def to_s
|
||||||
name
|
name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# returns the customer's email
|
||||||
def email
|
def email
|
||||||
@details.primary_email_address
|
@details.primary_email_address if @details
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# returns the customer's primary phone
|
||||||
def primary_phone
|
def primary_phone
|
||||||
@details.primary_phone
|
@details.primary_phone if @details
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# returns the customer's mobile phone
|
||||||
def mobile_phone
|
def mobile_phone
|
||||||
@detail.mobile_phone
|
@detail.mobile_phone if @details
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# returns the customer's notes
|
||||||
def notes
|
def notes
|
||||||
@details.notes
|
@details.notes if @details
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# updates the customer's notes in QBO
|
||||||
|
def notes (s)
|
||||||
|
customer = get_customer(self.id)
|
||||||
|
customer.notes = s
|
||||||
|
get_base.update(customer)
|
||||||
|
end
|
||||||
|
|
||||||
|
# returns the bases QBO service for customers
|
||||||
def get_base
|
def get_base
|
||||||
Qbo.get_base(:customer)
|
Qbo.get_base(:customer)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# returns the QBO customer
|
||||||
def get_customer (id)
|
def get_customer (id)
|
||||||
get_base.service.find_by_id(id)
|
get_base.service.find_by_id(id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# proforms a bruteforce sync operation
|
||||||
|
# This needs to be simplified
|
||||||
def update_all
|
def update_all
|
||||||
customers = get_base.service.all
|
customers = get_base.service.all
|
||||||
|
|
||||||
@@ -59,20 +78,33 @@ class QboCustomer < ActiveRecord::Base
|
|||||||
# Update the customer table
|
# Update the customer table
|
||||||
customers.each { |customer|
|
customers.each { |customer|
|
||||||
qbo_customer = QboCustomer.find_or_create_by(id: customer.id)
|
qbo_customer = QboCustomer.find_or_create_by(id: customer.id)
|
||||||
qbo_customer.name = customer.display_name
|
# only update if diffrent
|
||||||
qbo_customer.id = customer.id
|
if not qbo_customer.name == customer.display_name
|
||||||
qbo_customer.save!
|
qbo_customer.name = customer.display_name
|
||||||
|
qbo_customer.id = customer.id
|
||||||
|
qbo_customer.save!
|
||||||
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
#remove deleted customers
|
# remove deleted customers
|
||||||
where.not(customers.map(&:id)).destroy_all
|
where.not(customers.map(&:id)).destroy_all
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
# init details
|
||||||
def get_details
|
def get_details
|
||||||
@details = get_customer(self.id)
|
if self.id
|
||||||
|
@details = get_customer(self.id)
|
||||||
|
update
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# update's the customers name
|
||||||
|
def update
|
||||||
|
self.name = @details.display_name
|
||||||
|
self.save
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user