class Skr::SkuLoc
Next to the {Sku} class, SkuLoc
is the second most integral model in Stockor
. It tracks which Skus are setup in each location and the related quantity information about them
It is also the model that is linked to by other models that need to refer to a sku's location such as the lines on {PurchaseOrder}, Quotes, {SalesOrder}, PickTickets, and Invoices
Public Instance Methods
Adjust the on hand qty. Can only be called while qty is unlocked @example
sl = SkuLoc.first sl.unlock_fields( :qty ) do sl.adjust_qty( 10 ) sl.save! end
@param [Fixnum] qty the amount to adjust the onhand qty by @return [Fixnum] new qty on hand
# File lib/skr/sku_loc.rb, line 50 def adjust_qty( qty ) self.qty += qty end
Allocate the maximum available quantity to {SalesOrder} that are not currrently allocated
# File lib/skr/sku_loc.rb, line 66 def allocate_available_qty! update_so_qty so_lines.unallocated.order(:created_at).each do | sol | sol.sku_loc = self sol.allocate_max_available sol.save break if qty_allocated <= 0 end end
@return [BigDecimal] the value of inventory for {Sku} in this {Location}
# File lib/skr/sku_loc.rb, line 32 def onhand_mac_value qty*mac end
@return [Fixnum] the qty that is not allocated, picking or reserved
# File lib/skr/sku_loc.rb, line 37 def qty_available qty - qty_allocated - qty_picking - qty_reserved end
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/sku_loc.rb, line 57 def rebuild! self.update_attributes({ qty_picking: pt_lines.pt_lines.picking_qty, qty_allocated: self.so_lines.open.allocated.eq_qty_allocated }) end
Private Instance Methods
# File lib/skr/sku_loc.rb, line 78 def fire_after_save_events fire_event(:qty_change) if qty_changed? end
# File lib/skr/sku_loc.rb, line 87 def update_qty_picking( pt=nil ) update_attributes( :qty_picking=> self.pt_lines.picking.ea_picking_qty ) end
Caches the qty of skus that are allocated to sales orders in the {#qty_allocated} field
# File lib/skr/sku_loc.rb, line 83 def update_so_qty( so_line=nil ) self.update_attributes({ qty_allocated: self.so_lines.open.allocated.eq_qty_allocated }) end