Sha256: ea174190e1096cd5a794d059afc367ed94026f0bbc127b8628b458bda7847204
Contents?: true
Size: 801 Bytes
Versions: 2
Compression:
Stored size: 801 Bytes
Contents
module Comable class Stock < ActiveRecord::Base include Decoratable belongs_to :product, class_name: Comable::Product.name, foreign_key: Comable::Product.table_name.singularize.foreign_key scope :activated, -> { where.not(product_id_num: nil) } scope :unsold, -> { where('quantity > ?', 0) } scope :soldout, -> { where('quantity <= ?', 0) } delegate :price, to: :product delegate :sku?, to: :product def unsold? return false if product_id_num.nil? return false if quantity.nil? quantity > 0 end def soldout? !unsold? end def decrement_quantity! with_lock do # TODO: カラムマッピングのdecrementメソッドへの対応 update_attributes!(quantity: quantity.pred) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
comable-0.0.2 | app/models/comable/stock.rb |
comable-0.0.1 | app/models/comable/stock.rb |