Sha256: 751cae2b89b10a3bac7a7bc243b20fdc138052de0677257e8fa4dbc00b5f01de
Contents?: true
Size: 1.61 KB
Versions: 3
Compression:
Stored size: 1.61 KB
Contents
module Skr class Uom < Skr::Model belongs_to :sku, :inverse_of=>:uoms validates :price, :numericality=>true, :allow_nil=>false validates :sku, :presence=>true, :on=>:update validates :code, :presence=>true validates :size, :numericality => true, :length=>{:minimum=>1} validates :weight, :height, :width, :depth, :numericality=>{:greater_than=>0.1}, :allow_nil=>true export_methods :combined_uom, mandatory: true scope :with_combined_uom, lambda { | *args | compose_query_using_detail_view(view: 'skr_combined_uom') }, export: true def combined_uom if self.size.nil? || self.code.nil? '' elsif 1 == self.size self.code else "#{self.code}/#{self.size}" end end def has_dimensions? ! self.dimensions.include?(nil) end def dimensions [ width, height, depth ] end def volume if has_dimensions? dimensions.inject(:*) else nil end end def blank? self.code.blank? || self.size.to_i == 0 end def self.ea Uom.new({ :code=>'EA',:size=>1, :price=>0.0 }) end export_scope :for_sku_loc, lambda{ | sku_loc_id = nil | if sku_loc_id Skr::Uom.joins(sku: [:sku_locs]).where(Skr::SkuLoc.table_name => {id: sku_loc_id}) else Skr::Uom.none end } end end # Skr module
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
stockor-0.4.0 | lib/skr/models/uom.rb |
stockor-0.3.0 | lib/skr/models/uom.rb |
stockor-0.2 | lib/skr/models/uom.rb |