class Skr::PorLine

Public Instance Methods

po_line=(pol) click to toggle source
Calls superclass method
# File lib/skr/models/por_line.rb, line 23
def po_line=(pol)
    super
    %w{ sku_code part_code description uom_code uom_size }.each do | attr |
        self[ attr ] = po_line[ attr ]
    end
    self.sku_loc    = pol.sku_loc
    self.sku_vendor = pol.sku_vendor
    self.uom   = pol.uom
    self.price = pol.price
    self.qty   = pol.qty_unreceived
end

Private Instance Methods

adjust_gl() click to toggle source
# File lib/skr/models/por_line.rb, line 59
def adjust_gl
    diff = price - price_was
    return if diff.zero?

    tran = self.sku_trans.build({ :origin=>self, :qty => 0, :sku_loc=>po_line.sku_loc,
        :credit_gl_account => self.sku.gl_asset_account,
        :uom_size=>self.uom_size, :uom_code=>self.uom_code })

    tran.cost = diff * qty

    tran.debit_gl_account = if voucher.confirmed?
                                voucher.vendor.gl_payables_account
                            else # otherwise it's in the clearing account
                                GlAccount.default_for( :inventory_receipts_clearing )
                            end
    tran.save!

end
adjust_inventory() click to toggle source
# File lib/skr/models/por_line.rb, line 37
def adjust_inventory
    logger.debug( "Receiving #{self.ea_qty} into stock" )
    tran = self.sku_trans.build({
        origin: self, qty: self.qty,
        sku_loc: po_line.sku_loc,
        origin_description: "PO #{self.po_line.purchase_order.visible_id}",
        cost: self.extended_price,  uom: self.uom,
        credit_gl_account: self.sku.gl_asset_account,
        debit_gl_account:  GlAccount.default_for( :inventory_receipts_clearing )
    })
    if self.auto_allocate
        tran.allocate_after_save = true
    end
    true
end
ensure_qty_is_less_than_unreceived() click to toggle source
# File lib/skr/models/por_line.rb, line 53
def ensure_qty_is_less_than_unreceived
    if qty_changed? && po_line && qty > po_line.qty_unreceived
        errors.add(:qty,"#{qty} must be less than unreceived qty of #{po_line.qty_unreceived}")
    end
end