Class: Skr::IaLine

Inherits:
Model
  • Object
show all
Defined in:
lib/skr/ia_line.rb

Overview

An Inventory Adjustment Line. Each model contains the SkuLoc, cost, UOM, and qty for a Sku to adjust

An adjustment starts out in the “pending” state, then when it moves to the “applied” state, each line creates an SkuTran record that adjusts the inventory in or out.

Instance Method Summary collapse

Instance Method Details

#adjust_qty!Object

Perform the adjustment. Requires adjusting to be unlocked and #is_applied? must be false

It creates a SkuTran to adjust the inventory, and allocates available qty to the SoLine



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/skr/ia_line.rb', line 84

def adjust_qty!
    if ! is_adjusting_unlocked? || is_applied?
        raise "Unable to apply line, either not approved or previously applied"
    end
    set_cost_from_sku_loc
    Core.logger.debug( "Adjusting #{self.qty} #{combined_uom} of #{sku_code} into stock")
    self.build_sku_tran({
        :origin=>self, :qty => self.qty, :sku_loc=>self.sku_loc,
        origin_description: "IA #{self.inventory_adjustment.visible_id}:#{self.sku.code}",
        cost: total,  uom: self.uom,
        allocate_after_save: true,
        debit_gl_account:  self.inventory_adjustment.reason.,
        credit_gl_account: self.sku.
    })
    self.sku_tran.save unless self.new_record?
    true
end

#ea_qtyObject

The qty for the line expressed in terms of the single UOM



54
55
56
# File 'lib/skr/ia_line.rb', line 54

def ea_qty
    self.uom_size * self.qty
end

#is_applied?Boolean

Returns has the line been applied.

Returns:

  • (Boolean)

    has the line been applied



44
45
46
# File 'lib/skr/ia_line.rb', line 44

def is_applied?
    sku_tran.present?
end

#is_removing_qty?Boolean

Returns is the qty negative?.

Returns:

  • (Boolean)

    is the qty negative?



49
50
51
# File 'lib/skr/ia_line.rb', line 49

def is_removing_qty?
    qty && qty <=0
end

#ledger_costBigDecimal

Returns either the current MAC for the sku’s location or the cost that was manually set.

Returns:

  • (BigDecimal)

    either the current MAC for the sku’s location or the cost that was manually set



65
66
67
68
69
70
71
# File 'lib/skr/ia_line.rb', line 65

def ledger_cost
    if cost_was_set? || is_applied?
        self.cost
    else
        self.sku_loc_mac
    end
end

#set_cost_from_sku_locObject

copies the cost from the sku_loc to the #cost field



74
75
76
77
78
79
# File 'lib/skr/ia_line.rb', line 74

def set_cost_from_sku_loc
    if ! cost_was_set?
        self.cost = self.sku_loc_mac
    end
    true
end

#sku_loc_macBigDecimal

Returns the current moving average cost (mac) on the location, expressed in terms of the UOM.

Returns:

  • (BigDecimal)

    the current moving average cost (mac) on the location, expressed in terms of the UOM



39
40
41
# File 'lib/skr/ia_line.rb', line 39

def sku_loc_mac
    self.sku_loc ? ( self.sku_loc.mac * self.uom_size ) : 0
end

#sku_loc_qtyFixnum

Returns The qty available on the location, expressed in terms of the UOM.

Returns:

  • (Fixnum)

    The qty available on the location, expressed in terms of the UOM



34
35
36
# File 'lib/skr/ia_line.rb', line 34

def sku_loc_qty
    ( self.uom_size && self.sku_loc ) ? BigDecimal.new( self.sku_loc.qty ) / self.uom_size : 0
end

#totalBigDecimal

Returns the total value of the line.

Returns:

  • (BigDecimal)

    the total value of the line



59
60
61
# File 'lib/skr/ia_line.rb', line 59

def total
    self.ledger_cost * self.qty
end