Sha256: 5461d1553b838fd408b021c0d1b2a1b97796d602d3e52e6fd549e705ac79b4ee

Contents?: true

Size: 1.72 KB

Versions: 8

Compression:

Stored size: 1.72 KB

Contents

module Skr
    module Concerns

        module Sku

            module Locations
                # Attempt to find a {SkuLoc} record and create it if not found
                def find_or_create_for( location )
                    location_id = location.is_a?(Numeric) ? location : location.id
                    for_location(location) || create!({ :location_id=>location_id })
                end

                def for_location( location )
                    location_id = location.is_a?(Numeric) ? location : location.id
                    detect{ |l| l.location_id==location_id }
                end

                def default
                    loc_id = Location.default.id
                    detect{ |sl| sl.location_id == loc_id }
                end
            end

            module Vendors
                def default
                    vendid = self.proxy_association.owner.default_vendor_id
                    detect{ |sv| sv.vendor_id == vendid }
                end
                def for_vendor( vendor )
                    vendor_id = vendor.is_a?(Numeric) ? vendor : vendor.id
                    detect{ |v| v.vendor_id==vendor_id }
                end
            end

            module Uoms
                def default
                    code = self.proxy_association.owner.default_uom_code
                    with_code( code )
                end

                # Return the uom with code.  Since the UOM's are probably already loaded
                # for the SKU, it makes sense to search over the in-memory collection
                # vs hitting the DB again.
                def with_code( code )
                    detect{|uom| uom.code == code }
                end

            end
        end

    end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
stockor-0.5.0 lib/skr/concerns/sku_extensions.rb
stockor-0.4.0 lib/skr/concerns/sku_extensions.rb
stockor-0.3.0 lib/skr/concerns/sku_extensions.rb
stockor-0.2 lib/skr/concerns/sku_extensions.rb
stockor-0.1.9 lib/skr/concerns/sku_extensions.rb
stockor-0.1.8 lib/skr/concerns/sku_extensions.rb
stockor-0.1.7 lib/skr/concerns/sku_extensions.rb
stockor-core-0.2 lib/skr/concerns/sku_extensions.rb