cats_core 1.1.40 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c2c955101b31607adc7eec1388f6f4c172181ffd78a2e514b5c220130899b4f3
4
- data.tar.gz: f99a81794245cd12120a3b5dac7cd04a6f8a89ef7ca96dbce409b341629172c3
3
+ metadata.gz: 43b3831ade3f11502d3e9077e5d7fdcb6d8b51d5f18294f45427dc94ff018177
4
+ data.tar.gz: db9049a30b3ca768c64f6648d667bce88912e3500474d547926dcd4465c37627
5
5
  SHA512:
6
- metadata.gz: b80445e45187d6590c0219cba05d11defbea0d298f79cb0f3c7c8fc82705e17ef6abc1223181c8ae6dca44138aa4b46a4d3aaa9f7732c7efb5d92ba6aeeff76e
7
- data.tar.gz: 1a3efcd95681646652dd285f6f96f1ba28da6ba6214f32db735ff8f4571de66c28c68342843c9a347cb4f70e2a6078800ef4eff27898d675cabf79e80037b72e
6
+ metadata.gz: d53062c841953c930d43f0635e1179203182a9f668fe5ca1ee670698eb510034115eda2304cacc6b740b438f2975843ef8c7633b85463c5eb37a5f14b3715f75
7
+ data.tar.gz: 788188ba5bf7e9ccc06ff9816ed5c14340eacc978f6cac56e775c5d848b023d0a03bb325c6cf77e6aa99be9ff0a8006996abf43444ac7ac8155ed68ced76f6e7
@@ -20,7 +20,7 @@ module Cats
20
20
  jwt = Cats::Core::TokenAuthService.issue(payload)
21
21
  render json: { token: jwt, user: payload }
22
22
  else
23
- render json: { error: 'Invalid username or password.' }, status: 400
23
+ render json: { error: 'Invalid password.' }, status: 400
24
24
  end
25
25
  else
26
26
  render json: { error: 'User does not exist.' }, status: 400
@@ -1,43 +1,10 @@
1
1
  module Cats
2
2
  module Core
3
3
  class CurrenciesController < ApplicationController
4
- before_action :set_currency, only: %i[show update]
5
-
6
- def index
7
- data = ActiveModelSerializers::SerializableResource.new(Cats::Core::Currency.all)
8
- render json: { success: true, data: data }
9
- end
10
-
11
- def show
12
- data = ActiveModelSerializers::SerializableResource.new(@currency)
13
- render json: { success: true, data: data }
14
- end
15
-
16
- def create
17
- obj = Cats::Core::Currency.new(model_params)
18
- if obj.save
19
- data = ActiveModelSerializers::SerializableResource.new(obj)
20
- render json: { success: true, data: data }, status: :created
21
- else
22
- render json: { success: false, error: obj.errors.full_messages[0] }, status: :unprocessable_entity
23
- end
24
- end
25
-
26
- def update
27
- if @currency.update(model_params)
28
- data = ActiveModelSerializers::SerializableResource.new(@currency)
29
- render json: { success: true, data: data }
30
- else
31
- render json: { success: false, error: @currency.errors.full_messages[0] }, status: :unprocessable_entity
32
- end
33
- end
4
+ include Common
34
5
 
35
6
  private
36
7
 
37
- def set_currency
38
- @currency = Cats::Core::Currency.find(params[:id])
39
- end
40
-
41
8
  def model_params
42
9
  params.require(:payload).permit(:code, :name)
43
10
  end
@@ -40,13 +40,14 @@ module Cats
40
40
  def approve
41
41
  raise(StandardError, 'Commodity already approved.') if status == APPROVED
42
42
 
43
+ result = false
43
44
  Cats::Core::Commodity.transaction do
44
45
  self.status = APPROVED
45
46
  save!
46
47
  store = Cats::Core::Store.find_by(code: 'SUP-STORE')
47
48
  raise(StandardError, 'Supplier store does not exist.') unless store
48
49
 
49
- Cats::Core::Stack.create!(
50
+ stack = Cats::Core::Stack.create!(
50
51
  code: batch_no,
51
52
  store: store,
52
53
  commodity: self,
@@ -59,9 +60,9 @@ module Cats
59
60
  start_x: 1,
60
61
  start_y: 1
61
62
  )
62
- true
63
+ result = stack.id.positive?
63
64
  end
64
- false
65
+ result
65
66
  end
66
67
 
67
68
  def allocate(ignore_errors: true)
@@ -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
@@ -97,9 +97,9 @@ module Cats
97
97
  # If both conditions fail, it means an overlap exists b/n the two stacks
98
98
 
99
99
  def overlaps?(st1, st2)
100
- return false if st1.start_x > (st2.start_x + st2.width) || st2.start_x > (st1.start_x + st1.width)
100
+ return false if st1.start_x > (st2.start_x + st2.length) || st2.start_x > (st1.start_x + st1.length)
101
101
 
102
- return false if st1.start_y > (st2.start_y + st2.length) || st2.start_y > (st1.start_y + st1.length)
102
+ return false if st1.start_y > (st2.start_y + st2.width) || st2.start_y > (st1.start_y + st1.width)
103
103
 
104
104
  true
105
105
  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.1.40'.freeze
3
+ VERSION = '1.2.3'.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.1.40
4
+ version: 1.2.3
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-10-31 00:00:00.000000000 Z
11
+ date: 2021-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 2.2.3
61
+ version: 2.3.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 2.2.3
68
+ version: 2.3.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: noticed
71
71
  requirement: !ruby/object:Gem::Requirement