More progress

This commit is contained in:
2016-05-30 09:30:33 -04:00
parent ba152e69d2
commit 6e7ec44188
2 changed files with 24 additions and 30 deletions

View File

@@ -15,7 +15,7 @@ class Customer < ActiveRecord::Base
has_many :qbo_purchases has_many :qbo_purchases
has_many :vehicles has_many :vehicles
attr_accessible :name, :notes, :email, :primary_phone, :mobile_phone attr_accessible :name
validates_presence_of :id, :name validates_presence_of :id, :name
@@ -49,7 +49,7 @@ class Customer < ActiveRecord::Base
# Updates the customer's primary phone number # Updates the customer's primary phone number
def primary_phone=(n) def primary_phone=(n)
pull unless @details pull unless @details
Quickbooks::Model::TelephoneNumber.new pn = Quickbooks::Model::TelephoneNumber.new
pn.free_form_number = n pn.free_form_number = n
@details.primary_phone = pn @details.primary_phone = pn
end end
@@ -67,7 +67,7 @@ class Customer < ActiveRecord::Base
# Updates the custome's mobile phone number # Updates the custome's mobile phone number
def mobile_phone=(n) def mobile_phone=(n)
pull unless @details pull unless @details
Quickbooks::Model::TelephoneNumber.new pn = Quickbooks::Model::TelephoneNumber.new
pn.free_form_number = n pn.free_form_number = n
@details.mobile_phone = pn @details.mobile_phone = pn
end end
@@ -75,27 +75,25 @@ class Customer < ActiveRecord::Base
# Updates Both local DB name & QBO display_name # Updates Both local DB name & QBO display_name
def name=(s) def name=(s)
pull unless @details pull unless @details
display_name = s @details.display_name = s
super super
end end
# Magic Method # Magic Method
def method_missing(name, *arguments) def method_missing(n, *arguments)
pull unless @details pull unless @details
value = arguments[0] value = arguments[0]
name = name.to_s method_name = n.to_s
#if @detils.respond_to?(n)
# if the method's name ends with '=' # if the method's name ends with '='
if name[-1, 1] == "=" if method_name[-1, 1] == "="
method_name = name[0..-2] @details.method(method_name).call(value)
@details[method_name] = value
else else
begin return @details.method(method_name).call
return @details[name]
rescue
return nil
end
end end
#else
# super
#end
end end
# proforms a bruteforce sync operation # proforms a bruteforce sync operation
@@ -126,16 +124,14 @@ class Customer < ActiveRecord::Base
# Push the updates # Push the updates
def save_with_push def save_with_push
save_without_push
begin begin
#tries ||= 3
@details = Qbo.get_base(:customer).service.update(@details) @details = Qbo.get_base(:customer).service.update(@details)
raise "QBO Fault" if @details.fault? #raise "QBO Fault" if @details.fault?
update_column(:id, @details.id) self.id = @details.id
rescue Exception => e rescue Exception => e
#retry unless (tries -= 1).zero?
errors.add(e.message) errors.add(e.message)
end end
save_without_push
end end
alias_method :save_without_push, :save alias_method :save_without_push, :save

View File

@@ -16,16 +16,14 @@ class IssuesFormHookListener < Redmine::Hook::ViewListener
f = context[:form] f = context[:form]
# Check to see if there is a quickbooks user attached to the issue # Check to see if there is a quickbooks user attached to the issue
@@selected_customer = context[:issue].customer ? context[:issue].customer.id : nil @selected_customer = context[:issue].customer ? context[:issue].customer.id : nil
selected_item = context[:issue].qbo_item ? context[:issue].qbo_item.id : nil selected_item = context[:issue].qbo_item ? context[:issue].qbo_item.id : nil
selected_invoice = context[:issue].qbo_invoice ? context[:issue].qbo_invoice.id : nil selected_invoice = context[:issue].qbo_invoice ? context[:issue].qbo_invoice.id : nil
selected_estimate = context[:issue].qbo_estimate ? context[:issue].qbo_estimate.id : nil selected_estimate = context[:issue].qbo_estimate ? context[:issue].qbo_estimate.id : nil
# Load customer information without callbacks # Load customer information without callbacks
Customer.without_callback(:initialize, :after, :pull) do @customer = Customer.find_by_id(@selected_customer) if @selected_customer
@@customer = Customer.find_by_id(@@selected_customer) if @@selected_customer @select_customer = f.select :customer_id, Customer.all.pluck(:name, :id).sort, :selected => @selected_customer, include_blank: true
@@select_customer = f.select :customer_id, Customer.all.pluck(:name, :id).sort, :selected => @@selected_customer, include_blank: true
end
# Generate the drop down list of quickbooks items # Generate the drop down list of quickbooks items
select_item = f.select :qbo_item_id, QboItem.all.pluck(:name, :id).sort, :selected => selected_item, include_blank: true select_item = f.select :qbo_item_id, QboItem.all.pluck(:name, :id).sort, :selected => selected_item, include_blank: true
@@ -36,10 +34,10 @@ class IssuesFormHookListener < Redmine::Hook::ViewListener
# Generate the drop down list of quickbooks extimates # Generate the drop down list of quickbooks extimates
select_estimate = f.select :qbo_estimate_id, QboEstimate.all.pluck(:doc_number, :id).sort! {|x, y| y <=> x}, :selected => selected_estimate, include_blank: true select_estimate = f.select :qbo_estimate_id, QboEstimate.all.pluck(:doc_number, :id).sort! {|x, y| y <=> x}, :selected => selected_estimate, include_blank: true
vehicles = @@customer.vehicles.pluck(:name, :id).sort! if context[:issue].customer vehicles = @customer.vehicles.pluck(:name, :id).sort! if context[:issue].customer
vehicles = Vehicle.all.order(:name) if not vehicles vehicles = Vehicle.all.order(:name) if not vehicles
vehicle = f.select :vehicles_id, vehicles, include_blank: true, :selected => vehicle vehicle = f.select :vehicles_id, vehicles, include_blank: true, :selected => vehicle
return "<p>#{@@select_customer}</p> <p>#{select_item}</p> <p>#{select_invoice}</p> <p>#{select_estimate}</p> <p>#{vehicle}</p>" return "<p>#{@select_customer}</p> <p>#{select_item}</p> <p>#{select_invoice}</p> <p>#{select_estimate}</p> <p>#{vehicle}</p>"
end end
end end