class Skr::Sku
A (S)tock (K)eeping (U)nit (SKU) is the cornerstone of Stockor
At it's simplest form a SKU tracks a resource that the company controlls. It can be manufactured (by combining other SKUs), purchased, stored, and sold.
Although SKUs usually refer to physical item, it may also track intangibles such as “Labor”, “Handling”, or “Freight”
Public Instance Methods
price()
click to toggle source
# File lib/skr/models/sku.rb, line 57 def price uoms.default.price end
rebuild!()
click to toggle source
Rebuilding is sometimes needed for cases where the location's allocation/on order/reserved counts get out of sync with the SalesOrder
counts. This forces recalculation of the cached values
# File lib/skr/models/sku.rb, line 64 def rebuild! sku_locs.each(&:rebuild!) end
Private Instance Methods
create_associated_records()
click to toggle source
Setup the associations after create
# File lib/skr/models/sku.rb, line 79 def create_associated_records if sku_locs.empty? self.sku_locs.create({ sku: self, location: Location.default }) end true # don't cancel save op end
ensure_default_uom_exists()
click to toggle source
If the default uom code was changed, make sure the UOM is actually present on the uoms list
# File lib/skr/models/sku.rb, line 72 def ensure_default_uom_exists if default_uom_code_changed? && uoms.default.nil? errors.add( :default_uom_code, "does not exist on UOMs" ) end end
set_defaults()
click to toggle source
Set the default values for the Sku
if they are not present
# File lib/skr/models/sku.rb, line 87 def set_defaults if self.default_vendor.blank? && self.sku_vendors.any? self.default_vendor = self.sku_vendors.at(0).vendor end self.uoms << Uom.ea if self.uoms.empty? self.can_backorder = Skr.config.skus_backorder_default if self.can_backorder.nil? self.gl_asset_account ||= GlAccount.default_for(:asset) self.default_uom_code ||= self.uoms.first.code true # don't cancel save op end