cats_core 1.2.0 → 1.2.1

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
  SHA256:
3
- metadata.gz: ed6937d9d787e6b9cd4861aed52c82cddec427a2607f86e6b76ee835dbf66c0b
4
- data.tar.gz: 99f350b323761a10f70058b01cceda92acd6c92d2824f06d011effaad3cd4780
3
+ metadata.gz: bdb1adee3b96e70550ebe13e6e0c8a5fb25003bf9f3e6921547ecc597aa12a53
4
+ data.tar.gz: c358a310a99dfff0bf57002f81ea5e4dfccbc6937ed064908a5693d234c77568
5
5
  SHA512:
6
- metadata.gz: 67d812874a6b1680fff22c83dff0ac53193585ac9136e9753ef28db9f0210cb503d9b0f73c19d73aa45b55f042e2ff4e2787af35ef713a0ed12029c982b789a9
7
- data.tar.gz: bca2a928d539658137bb2b545ab0ea2f98611312e2c4cd8a0dffa3fe415b19b4771dd97a5550631ccc8689817686affdb0c074a93aeb479a78fbca98d4e758c5
6
+ metadata.gz: afc8027a1addee047913baa073b8ac5cdac7a5e8d42b7c1a81f303e7d8b28c51948a478f02b240760513787d28a0f583e800e2f65a8abc7a6e0e64103661a1fb
7
+ data.tar.gz: 0bfb44fbd9f541ea33738cd1a4f5150040cc9d69d2c3afd40ea5b198cc19b3b8361851bcfb5e6ed412cc0afe74e67d372fcf2a914163fdf672dbea96f60b7dfb
@@ -6,6 +6,15 @@ module Cats
6
6
 
7
7
  delegate(:code, to: :source, prefix: true)
8
8
  delegate(:reference_no, to: :destination, prefix: true)
9
+
10
+ def commit
11
+ Transaction.transaction do
12
+ source.quantity -= quantity
13
+ source.save!
14
+ self.status = COMMITTED
15
+ save!
16
+ end
17
+ end
9
18
  end
10
19
  end
11
20
  end
@@ -10,7 +10,7 @@ module Cats
10
10
  ReceiptTransaction.transaction do
11
11
  destination.quantity += quantity
12
12
  destination.stack_status = Cats::Core::Stack::ALLOCATED
13
- destination.save
13
+ destination.save!
14
14
  self.status = COMMITTED
15
15
  save!
16
16
  end
@@ -17,23 +17,16 @@ module Cats
17
17
  def validate_quantity
18
18
  return unless quantity.present? && source.present?
19
19
 
20
- total = self.class.where(source: source).sum(:quantity)
20
+ dispatched = self.class.where(source: source, status: DRAFT).sum(:quantity)
21
21
 
22
- total -= quantity_was if id
22
+ available = source.quantity - dispatched
23
+ available += quantity_was if quantity_was
23
24
 
24
- diff = source.quantity - total
25
- errors.add(:quantity, "total is higher than source quantity (Max = #{diff}).") if quantity > diff
25
+ errors.add(:quantity, "total is higher than source quantity (Max = #{available}).") if quantity > available
26
26
  end
27
27
 
28
28
  def commit
29
- Transaction.transaction do
30
- source.quantity -= quantity
31
- destination.quantity += quantity
32
- source.save
33
- destination.save
34
- self.status = COMMITTED
35
- save!
36
- end
29
+ raise(NotImplementedError, 'Method should be implemented in child classes.')
37
30
  end
38
31
 
39
32
  def skip_quantity_validation
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.2.0'.freeze
3
+ VERSION = '1.2.1'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cats_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-01 00:00:00.000000000 Z
11
+ date: 2021-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers