Class: RawgentoModels::LocalProduct

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/rawgento_models/local_product.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.all_hiddenObject



26
27
28
# File 'lib/rawgento_models/local_product.rb', line 26

def self.all_hidden
  unscoped.where("active = ? OR hidden = ?", false, true)
end

Instance Method Details

#first_stock_recordObject



34
35
36
# File 'lib/rawgento_models/local_product.rb', line 34

def first_stock_record
  stock_items.order(created_at: :asc).first
end


38
39
40
41
42
43
44
45
# File 'lib/rawgento_models/local_product.rb', line 38

def link_suggestions limit=10
  guesses = []
  guesses << RemoteProduct.supplied_by(self.supplier).where(name: self.name).to_a
  guesses << RemoteProduct.supplied_by(self.supplier).where("lower(name) like ?",
                                                            "%#{self.name.downcase[0..self.name.size/2]}%")
             .limit(limit).to_a
  guesses.flatten.uniq
end

#out_of_stock_days_since(date) ⇒ Object



30
31
32
# File 'lib/rawgento_models/local_product.rb', line 30

def out_of_stock_days_since date
  stock_items.where("qty <= ? AND date >= ?", 0, date).count
end