cats_core 1.1.23 → 1.1.27

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: 4af6924e969566f74cdb292747651afd308688bc78b8ae4a1f984c9899bc17c8
4
- data.tar.gz: 78efc6656b32a0455345b69e35d11d0a599707b61da25c68177e77c1184c3598
3
+ metadata.gz: 2ccbe595a5539e596c53112adcf86365ae6001df0fb47ebd51dad59ce5c3429c
4
+ data.tar.gz: 85d16f249aaa79b9b6dd84a813f694cf2cfec498932670a21df5b308aae1b207
5
5
  SHA512:
6
- metadata.gz: 48502a731da0f5ebf90a0497b86a8585a3af825b3905936e4701bb2ec991766028630be363c9ec6d79d585f3156753b77736e4fb53b14c9f78231b1242c69ba3
7
- data.tar.gz: 306057c32ef4f4a6636aaf6321a5b80f682465de990cad4c10977928b6dde075b02923bdb4d14195e3bb4774d08843772cb7978cee6b4f1427480ae84c001cd0
6
+ metadata.gz: f354c929384af4351df0bd1c29286a298ef2ab94eae44571eebe876f3179b7a6975dcef33bda0c66ef0b97169ca640fa065a4fb6e1d88b02af8bc7f57fa15900
7
+ data.tar.gz: a360e9958396935694d2e4cbd08cca4170105f818b19c29e5cdca6c37ebbee5c5d48395f9ba8588ba782421883565798377e3d5bb2ce0218cd53dda0cffc8089
@@ -8,6 +8,27 @@ module Cats
8
8
  render json: { success: true, data: serialize(transactions) }
9
9
  end
10
10
 
11
+ def create
12
+ p = model_params
13
+
14
+ # Look for a transaction with the same destination as incoming
15
+ transaction = Cats::Core::ReceiptTransaction.find_by(
16
+ source_id: p[:source_id],
17
+ destination_id: p[:destination_id]
18
+ )
19
+ if transaction
20
+ transaction.quantity += p[:quantity]
21
+ else
22
+ transaction = Cats::Core::ReceiptTransaction.new(p)
23
+ end
24
+
25
+ if transaction.save
26
+ render json: { success: true, data: serialize(transaction) }, status: :created
27
+ else
28
+ render json: { success: false, error: transaction.errors.full_messages[0] }, status: :unprocessable_entity
29
+ end
30
+ end
31
+
11
32
  private
12
33
 
13
34
  def model_params
@@ -49,9 +49,11 @@ module Cats
49
49
  def assign_role
50
50
  role = Cats::Core::Role.find(params[:role_id])
51
51
  @user.roles << role
52
- if role.name == 'warehouse_manager'
52
+
53
+ case role.name
54
+ when 'warehouse_manager'
53
55
  @user.add_detail(:warehouse, params[:warehouse_id])
54
- elsif role.name =='hub_manager'
56
+ when 'hub_manager'
55
57
  @user.add_detail(:hub, params[:hub_id])
56
58
  end
57
59
 
@@ -62,6 +64,7 @@ module Cats
62
64
  def revoke_role
63
65
  role = Cats::Core::Role.find(params[:role_id])
64
66
  @user.roles.delete(role)
67
+ @user.remove_detail(role.name) if %w[warehouse_manager hub_manager].include?(role.name)
65
68
  data = ActiveModelSerializers::SerializableResource.new(role)
66
69
  render json: { success: true, data: data }
67
70
  end
@@ -5,6 +5,16 @@ module Cats
5
5
  belongs_to :destination, class_name: 'Cats::Core::Stack'
6
6
 
7
7
  delegate(:code, to: :destination, prefix: true)
8
+
9
+ def commit
10
+ ReceiptTransaction.transaction do
11
+ destination.quantity += quantity
12
+ destination.stack_status = Cats::Core::Stack::ALLOCATED
13
+ destination.save
14
+ self.status = COMMITTED
15
+ save!
16
+ end
17
+ end
8
18
  end
9
19
  end
10
20
  end
@@ -18,6 +18,9 @@ module Cats
18
18
  return unless quantity.present? && source.present?
19
19
 
20
20
  total = self.class.where(source: source).sum(:quantity)
21
+
22
+ total -= quantity_was if id
23
+
21
24
  diff = source.quantity - total
22
25
  errors.add(:quantity, "total is higher than source quantity (Max = #{diff}).") if quantity > diff
23
26
  end
@@ -36,6 +36,11 @@ module Cats
36
36
  save!
37
37
  end
38
38
 
39
+ def remove_detail(key)
40
+ details.delete(key)
41
+ save!
42
+ end
43
+
39
44
  def validate_phone_number
40
45
  return unless phone_number.present?
41
46
 
@@ -17,14 +17,7 @@ module Cats
17
17
  end
18
18
 
19
19
  receipt.status = Cats::Core::Receipt::STACKED
20
- stacks = receipt.receipt_transactions.map(&:destination)
21
- stacks.each { |stack| stack.stack_status = Cats::Core::Stack::ALLOCATED }
22
-
23
- Cats::Core::Receipt.transaction do
24
- receipt.receipt_transactions.each(&:commit)
25
- stacks.each(&:save!)
26
- receipt.save!
27
- end
20
+ receipt.receipt_transactions.each(&:commit)
28
21
  receipt
29
22
  end
30
23
  end
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.1.23'.freeze
3
+ VERSION = '1.1.27'.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.23
4
+ version: 1.1.27
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-05 00:00:00.000000000 Z
11
+ date: 2021-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers