Sha256: b8787144b029f6251591df5121ab48f2aa3ff787d1358caee49fcdc2a3d5221a

Contents?: true

Size: 1.03 KB

Versions: 14

Compression:

Stored size: 1.03 KB

Contents

module Unidom::Inventory::Concerns::AsInventoryItem

  extend ActiveSupport::Concern

  included do |includer|

    belongs_to :stored, polymorphic: true
    belongs_to :store,  polymorphic: true
    belongs_to :lot,    class_name:  'Unidom::Inventory::Lot'

    has_many :pick_items, class_name: 'Unidom::Inventory::PickItem',              as: :inventory_item
    has_many :variances,  class_name: 'Unidom::Inventory::InventoryItemVariance', as: :inventory_item

    def is_adjusted!(quantity: nil, due_to: nil, at: Time.now, description: nil, instruction: nil)
      if respond_to? :quantity
        increment! :quantity, quantity
      else
        if quantity.nil?
          quantity = -1
          soft_destroy
        else
          raise ArgumentError.new('The quantity should be nil when Inventory Item Variance is adjusted.')
        end
      end
      variances.create! inventory_item: self, reason: due_to, quantity: quantity, description: description, instruction: instruction, opened_at: at
    end

  end

  module ClassMethods
  end

end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
unidom-inventory-2.0 app/models/unidom/inventory/concerns/as_inventory_item.rb
unidom-inventory-1.0.5 app/models/unidom/inventory/concerns/as_inventory_item.rb
unidom-inventory-1.0.4 app/models/unidom/inventory/concerns/as_inventory_item.rb
unidom-inventory-1.0.3 app/models/unidom/inventory/concerns/as_inventory_item.rb
unidom-inventory-1.0.2 app/models/unidom/inventory/concerns/as_inventory_item.rb
unidom-inventory-1.0.1 app/models/unidom/inventory/concerns/as_inventory_item.rb
unidom-inventory-1.0 app/models/unidom/inventory/concerns/as_inventory_item.rb
unidom-inventory-0.8 app/models/unidom/inventory/concerns/as_inventory_item.rb
unidom-inventory-0.7.5 app/models/unidom/inventory/concerns/as_inventory_item.rb
unidom-inventory-0.7.4 app/models/unidom/inventory/concerns/as_inventory_item.rb
unidom-inventory-0.7.3 app/models/unidom/inventory/concerns/as_inventory_item.rb
unidom-inventory-0.7.2 app/models/unidom/inventory/concerns/as_inventory_item.rb
unidom-inventory-0.7.1 app/models/unidom/inventory/concerns/as_inventory_item.rb
unidom-inventory-0.7 app/models/unidom/inventory/concerns/as_inventory_item.rb