Class: Skr::SkuLoc
- Defined in:
- lib/skr/models/sku_loc.rb
Overview
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
Instance Method Summary collapse
-
#adjust_qty(qty) ⇒ Fixnum
Adjust the on hand qty.
-
#allocate_available_qty! ⇒ Object
Allocate the maximum available quantity to SalesOrder that are not currrently allocated.
- #onhand_mac_value ⇒ BigDecimal
-
#qty_available ⇒ Fixnum
The qty that is not allocated, picking or reserved.
-
#rebuild! ⇒ Object
Rebuilding is sometimes needed for cases where the location’s allocation/on order/reserved counts get out of sync with the SalesOrder counts.
Instance Method Details
#adjust_qty(qty) ⇒ Fixnum
Adjust the on hand qty. Can only be called while qty is unlocked
50 51 52 |
# File 'lib/skr/models/sku_loc.rb', line 50 def adjust_qty( qty ) self.qty += qty end |
#allocate_available_qty! ⇒ Object
Allocate the maximum available quantity to Skr::SalesOrder that are not currrently allocated
66 67 68 69 70 71 72 73 74 |
# File 'lib/skr/models/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 |
#onhand_mac_value ⇒ BigDecimal
32 33 34 |
# File 'lib/skr/models/sku_loc.rb', line 32 def onhand_mac_value qty*mac end |
#qty_available ⇒ Fixnum
Returns the qty that is not allocated, picking or reserved.
37 38 39 |
# File 'lib/skr/models/sku_loc.rb', line 37 def qty_available qty - qty_allocated - qty_picking - qty_reserved end |
#rebuild! ⇒ Object
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
57 58 59 60 61 62 |
# File 'lib/skr/models/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 |