unidom-inventory 0.6 → 0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 59116b8cfb8504d2ff15c7ff9afa640d77542afc
4
- data.tar.gz: 9df508c0df726dfb5b350d36dadea5a21bbae35a
3
+ metadata.gz: 35d04ff352b48b18c1a0d73de2221a123e203b62
4
+ data.tar.gz: 0a05c18f72d67c5a0d3b874b44bf23f0fce24a52
5
5
  SHA512:
6
- metadata.gz: f24af042b909c72252e548c4958894850108f9cc8097db04d2e33ea81650e00b0a14ab64351174f11ab5e2fdfb65f3e93e5faa4d98a14b831070dc36faacd821
7
- data.tar.gz: 49e7eca834921f0c1e8663c58301256ae87e6be4936f67f0b7200900e7fe648b323812c1d2a8102f70c64fbe1f9945ca4ea300076894447541e757709928e061
6
+ metadata.gz: b57410f0fe3215aebcbcaf07b0963e2ee93f8d32975c7bd2a339be7658ccf6d29687ce47493175ec3d1b207b47284e8db5d368c93a73214a5ff5f4833ed5c4d0
7
+ data.tar.gz: dd5f8cc480b4a8f3be19540efa99654e2f2bf926466cc7e2cece7f80a85a7f87a0775ab850eee63c2e07b8a227bcbe228bbcec92b70f826de0e2bc6bea54fff9
data/README.md CHANGED
@@ -50,9 +50,9 @@ pick_item = pick_list.items.create! inventory_item: grouped_inventory_item, q
50
50
  item_issuing = Unidom::Inventory::ItemIssuing.create! pick_item: pick_item, inventory_item: grouped_inventory_item, target_item: nil
51
51
  # target_item could be nil or any model like: shipment item or order item
52
52
 
53
- variance = Unidom::Inventory::InventoryItemVariance.create! inventory_item: grouped_inventory_item, reason: nil, opened_at: Time.now
53
+ Unidom::Inventory::InventoryItemVariance.adjust! @inventory_item, quantity: 1, due_to: nil, at: Time.now, description: nil, instruction: nil
54
54
  # or the following source code do the exact same thing.
55
- grouped_inventory_item.variances.create! quantity: 10, reason: nil, opened_at: Time.now
55
+ grouped_inventory_item.is_adjusted! 10, due_to: nil, at: Time.now, description: nil, instruction: nil
56
56
  ```
57
57
 
58
58
 
@@ -65,21 +65,22 @@ include Unidom::Inventory::AsInventoryItem
65
65
 
66
66
  ### As Inventory Item concern
67
67
 
68
- The As Inventory Item concern do the following tasks for the includer automatically:
68
+ The As Inventory Item concern do the following tasks for the includer automatically:
69
69
  1. Define the belongs_to :stored macro as: ``belongs_to :stored, polymorphic: true``
70
70
  2. Define the belongs_to :store macro as: ``belongs_to :store, polymorphic: true``
71
71
  3. Define the belongs_to :lot macro as: ``belongs_to :lot, class_name: 'Unidom::Inventory::Lot'``
72
- 4. Define the has_many :pick_items macro as: ``has_many :pick_items, class_name: 'Unidom::Inventory::PickItem', as: :inventory_item``
73
- 5. Define the has_many :variances macro as: ``has_many :variances, class_name: 'Unidom::Inventory::InventoryItemVariance', as: :inventory_item``
72
+ 4. Define the has_many :pick_items macro as: ``has_many :pick_items, class_name: 'Unidom::Inventory::PickItem', as: :inventory_item``
73
+ 5. Define the has_many :variances macro as: ``has_many :variances, class_name: 'Unidom::Inventory::InventoryItemVariance', as: :inventory_item``
74
+ 6. Define the #is_adjusted! method as: ``is_adjusted!(quantity, due_to: nil, at: Time.now, description: nil, instruction: nil)``
74
75
 
75
76
  ### As Store concern
76
77
 
77
- The As Store concern do the following tasks for the includer automatically:
78
+ The As Store concern do the following tasks for the includer automatically:
78
79
  1. Define the has_many :grouped_inventory_items macro as: ``has_many :grouped_inventory_items, class_name: 'Unidom::Inventory::GroupedInventoryItem', foreign_key: :store_id``
79
80
  2. Define the has_many :serialized_inventory_items macro as: ``has_many :serialized_inventory_items, class_name: 'Unidom::Inventory::SerializedInventoryItem', foreign_key: :store_id``
80
81
 
81
82
  ### As Stored concern
82
83
 
83
- The As Stored concern do the following tasks for the includer automatically:
84
+ The As Stored concern do the following tasks for the includer automatically:
84
85
  1. Define the has_many :grouped_inventory_items macro as: ``has_many :grouped_inventory_items, class_name: 'Unidom::Inventory::GroupedInventoryItem', foreign_key: :stored_id``
85
86
  2. Define the has_many :serialized_inventory_items macro as: ``has_many :serialized_inventory_items, class_name: 'Unidom::Inventory::SerializedInventoryItem', foreign_key: :stored_id``
@@ -11,6 +11,20 @@ module Unidom::Inventory::Concerns::AsInventoryItem
11
11
  has_many :pick_items, class_name: 'Unidom::Inventory::PickItem', as: :inventory_item
12
12
  has_many :variances, class_name: 'Unidom::Inventory::InventoryItemVariance', as: :inventory_item
13
13
 
14
+ def is_adjusted!(quantity: nil, due_to: nil, at: Time.now, description: nil, instruction: nil)
15
+ if respond_to? :quantity
16
+ increment! :quantity, quantity
17
+ else
18
+ if quantity.nil?
19
+ quantity = -1
20
+ soft_destroy
21
+ else
22
+ raise ArgumentError.new('The quantity should be nil when Inventory Item Variance is adjusted.')
23
+ end
24
+ end
25
+ variances.create! inventory_item: self, reason: due_to, quantity: quantity, description: description, instruction: instruction, opened_at: at
26
+ end
27
+
14
28
  end
15
29
 
16
30
  module ClassMethods
@@ -17,4 +17,18 @@ class Unidom::Inventory::InventoryItemVariance < ActiveRecord::Base
17
17
  scope :inventory_item_is, ->(inventory_item) { where inventory_item: inventory_item }
18
18
  scope :caused_by, ->(reason) { where reason: reason }
19
19
 
20
+ def self.adjust!(inventory_item, quantity: nil, due_to: nil, at: Time.now, description: nil, instruction: nil)
21
+ if inventory_item.respond_to? :quantity
22
+ inventory_item.increment! :quantity, quantity
23
+ else
24
+ if quantity.nil?
25
+ quantity = -1
26
+ inventory_item.soft_destroy
27
+ else
28
+ raise ArgumentError.new('The quantity should be -1 when Inventory Item Variance adjusts a Serialized Inventory Item.')
29
+ end
30
+ end
31
+ create! inventory_item: inventory_item, reason: due_to, quantity: quantity, description: description, instruction: instruction, opened_at: at
32
+ end
33
+
20
34
  end
@@ -1,5 +1,5 @@
1
1
  module Unidom
2
2
  module Inventory
3
- VERSION = '0.6'.freeze
3
+ VERSION = '0.7'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unidom-inventory
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.6'
4
+ version: '0.7'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Topbit Du
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-10 00:00:00.000000000 Z
11
+ date: 2016-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: unidom-common