Refactored models to use base model

This commit is contained in:
2026-03-12 11:14:45 -04:00
parent ffd8dc6332
commit 4fa8be856a
5 changed files with 112 additions and 153 deletions

View File

@@ -8,45 +8,21 @@
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
class Estimate < ActiveRecord::Base
include Redmine::I18n
class Estimate < QboBaseModel
has_and_belongs_to_many :issues
belongs_to :customer
validates_presence_of :doc_number, :id
self.primary_key = :id
# Returns the last sync time formatted for display. If no sync has occurred, returns a default message.
def self.last_sync
return I18n.t(:label_qbo_never_synced) unless maximum(:updated_at)
format_time(maximum(:updated_at))
end
# returns a human readable string
def to_s
return self[:doc_number]
end
# sync all estimates
def self.sync
EstimateSyncJob.perform_later(full_sync: false)
end
# sync only one estimate
def self.sync_by_id(id)
EstimateSyncJob.perform_later(id: id)
end
# sync only one estimate
def self.sync_by_doc_number(number)
EstimateSyncJob.perform_later(doc_number: number)
end
private
def log(msg)
Rails.logger.info "[Estimate] #{msg}"
end
end
end