Added qbo_sync flag

This commit is contained in:
2026-03-13 08:33:18 -04:00
parent c87e18810b
commit 2bcb1840a4
5 changed files with 19 additions and 4 deletions

View File

@@ -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) },

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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)
@@ -79,6 +86,10 @@ class QboBaseModel < ActiveRecord::Base
!!skip_qbo_push !!skip_qbo_push
end end
def self.qbo_sync(push: true)
self.qbo_push_enabled = push
end
private private
# Log messages with a standarized prefix # Log messages with a standarized prefix