Sha256: 1ac8457d3c7d5b2a65ff5a70b707f3a0aa550cdee1e9a3d3aabe2bfefe78f707

Contents?: true

Size: 1.34 KB

Versions: 7

Compression:

Stored size: 1.34 KB

Contents

module Skr

    # Is a record of an inventory receipt
    # A {PurchaseOrder} can have one or more of them

    class PoReceipt < Skr::Model

        has_visible_id
        has_sku_loc_lines
        has_gl_transaction

        belongs_to :purchase_order, export: true
        belongs_to :vendor,   export: true
        belongs_to :location, export: true

        has_one :gl_transaction, :as=>:source

        has_many :lines, :class_name=>'Skr::PorLine', export: { writable: true }, inverse_of: :po_receipt

        validates :freight,        numericality: true
        validates :purchase_order, :location, presence: true

        before_create  :record_freight, if: ->{ freight.nonzero? }
        after_create   :logit

        def purchase_order=(po)
            super
            self.location   ||= purchase_order.location
            self.vendor     = purchase_order.vendor
        end

        private

        def attributes_for_gl_transaction
            {   location: location, source: self,
                description: "PO RECPT #{self.visible_id}" }
        end

        def logit
        end

        def record_freight
            GlTransaction.current.add_posting( amount: self.freight,
              debit: GlAccount.default_for( :inventory_receipts_clearing ),
              credit: vendor.gl_freight_account
            )
        end

    end

end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
stockor-0.3.0 lib/skr/models/po_receipt.rb
stockor-0.2 lib/skr/models/po_receipt.rb
stockor-0.1.9 lib/skr/models/po_receipt.rb
stockor-0.1.8 lib/skr/models/po_receipt.rb
stockor-0.1.7 lib/skr/models/po_receipt.rb
stockor-0.1.5 lib/skr/models/po_receipt.rb
stockor-core-0.2 lib/skr/po_receipt.rb