mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2026-04-02 08:21:57 -04:00
Added qbo_sync flag
This commit is contained in:
@@ -19,6 +19,7 @@ class Customer < QboBaseModel
|
|||||||
validates_presence_of :name
|
validates_presence_of :name
|
||||||
before_validation :normalize_phone_numbers
|
before_validation :normalize_phone_numbers
|
||||||
self.primary_key = :id
|
self.primary_key = :id
|
||||||
|
qbo_sync push: true
|
||||||
|
|
||||||
acts_as_searchable columns: %w[name phone_number mobile_phone_number ],
|
acts_as_searchable columns: %w[name phone_number mobile_phone_number ],
|
||||||
scope: ->(_context) { left_joins(:project) },
|
scope: ->(_context) { left_joins(:project) },
|
||||||
|
|||||||
@@ -13,5 +13,6 @@ class Employee < QboBaseModel
|
|||||||
has_many :users
|
has_many :users
|
||||||
validates_presence_of :id, :name
|
validates_presence_of :id, :name
|
||||||
self.primary_key = :id
|
self.primary_key = :id
|
||||||
|
qbo_sync push: false
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -14,6 +14,7 @@ class Estimate < QboBaseModel
|
|||||||
belongs_to :customer
|
belongs_to :customer
|
||||||
validates_presence_of :doc_number, :id
|
validates_presence_of :doc_number, :id
|
||||||
self.primary_key = :id
|
self.primary_key = :id
|
||||||
|
qbo_sync push: false
|
||||||
|
|
||||||
# returns a human readable string
|
# returns a human readable string
|
||||||
def to_s
|
def to_s
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ class Invoice < QboBaseModel
|
|||||||
validates :id, presence: true, uniqueness: true
|
validates :id, presence: true, uniqueness: true
|
||||||
validates :doc_number, :txn_date, presence: true
|
validates :doc_number, :txn_date, presence: true
|
||||||
self.primary_key = :id
|
self.primary_key = :id
|
||||||
|
qbo_sync push: false
|
||||||
|
|
||||||
# Return the invoice's document number as its string representation
|
# Return the invoice's document number as its string representation
|
||||||
def to_s
|
def to_s
|
||||||
|
|||||||
@@ -14,10 +14,10 @@ class QboBaseModel < ActiveRecord::Base
|
|||||||
|
|
||||||
self.abstract_class = true
|
self.abstract_class = true
|
||||||
validates_presence_of :id
|
validates_presence_of :id
|
||||||
|
class_attribute :qbo_push_enabled, default: true
|
||||||
attr_accessor :skip_qbo_push
|
attr_accessor :skip_qbo_push
|
||||||
before_validation :push_to_qbo, on: :create
|
before_validation :push_to_qbo, on: :create, if: :push_to_qbo?
|
||||||
after_commit :push_to_qbo, on: :update, unless: :skip_qbo_push?
|
after_commit :push_to_qbo, on: :update, if: :push_to_qbo?
|
||||||
|
|
||||||
# Returns the details of the entity.
|
# Returns the details of the entity.
|
||||||
# If the details have already been fetched, it returns the cached version.
|
# If the details have already been fetched, it returns the cached version.
|
||||||
@@ -55,6 +55,13 @@ class QboBaseModel < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def push_to_qbo?
|
||||||
|
log "qbo_push_enabled #{self.class.qbo_push_enabled}"
|
||||||
|
log "skip_qbo_push #{skip_qbo_push}"
|
||||||
|
|
||||||
|
self.class.qbo_push_enabled && skip_qbo_push != true
|
||||||
|
end
|
||||||
|
|
||||||
# Repsonds to missing methods by delegating to the QBO entity calss if the method is defined there.
|
# Repsonds to missing methods by delegating to the QBO entity calss if the method is defined there.
|
||||||
# This allows for dynamic access to any attributes or methods of the QBO customer without having to explicitly define them in the Subclass model, providing flexibility and reducing boilerplate code.
|
# This allows for dynamic access to any attributes or methods of the QBO customer without having to explicitly define them in the Subclass model, providing flexibility and reducing boilerplate code.
|
||||||
def respond_to_missing?(method_name, include_private = false)
|
def respond_to_missing?(method_name, include_private = false)
|
||||||
@@ -76,7 +83,11 @@ class QboBaseModel < ActiveRecord::Base
|
|||||||
# Flag used to update local without pushing to QBO.
|
# Flag used to update local without pushing to QBO.
|
||||||
# This is used to prevent loops with the webhook
|
# This is used to prevent loops with the webhook
|
||||||
def skip_qbo_push?
|
def skip_qbo_push?
|
||||||
!!skip_qbo_push
|
!!skip_qbo_push
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.qbo_sync(push: true)
|
||||||
|
self.qbo_push_enabled = push
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
Reference in New Issue
Block a user