mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2025-11-09 09:24:23 -05:00
Removed after init call back from customer
This commit is contained in:
@@ -18,10 +18,8 @@ class CustomersController < ApplicationController
|
|||||||
|
|
||||||
# display a list of all customers
|
# display a list of all customers
|
||||||
def index
|
def index
|
||||||
Customer.without_callback(:initialize, :after, :pull) do
|
|
||||||
@customers = Customer.paginate(:page => params[:page])
|
@customers = Customer.paginate(:page => params[:page])
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@customer = Customer.new
|
@customer = Customer.new
|
||||||
|
|||||||
@@ -24,10 +24,8 @@ class VehiclesController < ApplicationController
|
|||||||
# return an HTML form for creating a new vehicle
|
# return an HTML form for creating a new vehicle
|
||||||
def new
|
def new
|
||||||
@vehicle = Vehicle.new
|
@vehicle = Vehicle.new
|
||||||
Customer.without_callback(:initialize, :after, :pull) do
|
|
||||||
@customers = Customer.all.order(:name)
|
@customers = Customer.all.order(:name)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
# create a new vehicle
|
# create a new vehicle
|
||||||
def create
|
def create
|
||||||
@@ -55,9 +53,7 @@ class VehiclesController < ApplicationController
|
|||||||
begin
|
begin
|
||||||
@vehicle = Vehicle.find_by_id(params[:id])
|
@vehicle = Vehicle.find_by_id(params[:id])
|
||||||
@customer = @vehicle.customer.id
|
@customer = @vehicle.customer.id
|
||||||
Customer.without_callback(:initialize, :after, :pull) do
|
|
||||||
@customers = Customer.all.order(:name)
|
@customers = Customer.all.order(:name)
|
||||||
end
|
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
render_404
|
render_404
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -19,16 +19,9 @@ class Customer < ActiveRecord::Base
|
|||||||
|
|
||||||
validates_presence_of :id, :name
|
validates_presence_of :id, :name
|
||||||
|
|
||||||
after_initialize :pull
|
|
||||||
|
|
||||||
self.primary_key = :id
|
self.primary_key = :id
|
||||||
|
|
||||||
def all
|
|
||||||
without_callback(:initialize, :after, :pull) do
|
|
||||||
super
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# returns a human readable string
|
# returns a human readable string
|
||||||
def to_s
|
def to_s
|
||||||
return name
|
return name
|
||||||
@@ -36,6 +29,7 @@ class Customer < ActiveRecord::Base
|
|||||||
|
|
||||||
# returns the customer's email
|
# returns the customer's email
|
||||||
def email
|
def email
|
||||||
|
pull unless @details
|
||||||
begin
|
begin
|
||||||
return @details.email_address.address
|
return @details.email_address.address
|
||||||
rescue
|
rescue
|
||||||
@@ -45,6 +39,7 @@ class Customer < ActiveRecord::Base
|
|||||||
|
|
||||||
# returns the customer's primary phone
|
# returns the customer's primary phone
|
||||||
def primary_phone
|
def primary_phone
|
||||||
|
pull unless @details
|
||||||
begin
|
begin
|
||||||
return @details.primary_phone.free_form_number
|
return @details.primary_phone.free_form_number
|
||||||
rescue
|
rescue
|
||||||
@@ -54,6 +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
|
||||||
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
|
||||||
@@ -61,6 +57,7 @@ class Customer < ActiveRecord::Base
|
|||||||
|
|
||||||
# returns the customer's mobile phone
|
# returns the customer's mobile phone
|
||||||
def mobile_phone
|
def mobile_phone
|
||||||
|
pull unless @details
|
||||||
begin
|
begin
|
||||||
return @details.mobile_phone.free_form_number
|
return @details.mobile_phone.free_form_number
|
||||||
rescue
|
rescue
|
||||||
@@ -70,6 +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
|
||||||
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
|
||||||
@@ -77,12 +75,14 @@ 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
|
||||||
display_name = s
|
display_name = s
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
# Magic Method
|
# Magic Method
|
||||||
def method_missing(name, *arguments)
|
def method_missing(name, *arguments)
|
||||||
|
pull unless @details
|
||||||
value = arguments[0]
|
value = arguments[0]
|
||||||
name = name.to_s
|
name = name.to_s
|
||||||
|
|
||||||
@@ -122,12 +122,6 @@ class Customer < ActiveRecord::Base
|
|||||||
#where.not(customers.map(&:id)).destroy_all
|
#where.not(customers.map(&:id)).destroy_all
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.without_callback(*args, &block)
|
|
||||||
Customer.skip_callback(*args)
|
|
||||||
yield
|
|
||||||
Customer.set_callback(*args)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Push the updates
|
# Push the updates
|
||||||
def save_with_push
|
def save_with_push
|
||||||
save_without_push
|
save_without_push
|
||||||
|
|||||||
Reference in New Issue
Block a user