cats_core 1.1.22 → 1.1.26

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: f7535241fdd71214b07a61f4bde93042bf22673e3cddf8819686da1a7ac2b277
4
- data.tar.gz: 5b7b01689834652de56c72f5bf836cf2b8e1b476d432beb72f691c634b38ce8f
3
+ metadata.gz: afdbac967f01ac249e5b68e57337f3e4ff94c491af3ea4f8b01ea7761fbbba20
4
+ data.tar.gz: '05598d3a0b3384d757332bb182519b5b15e592009abdeba5175b258dc6de4678'
5
5
  SHA512:
6
- metadata.gz: 12fb00d72b5c265e1ea938fed3ec613ead395a7f34cdc78e0bf814159167eafa04d4343f1a02b3b8ffbcd840fcbb8524dcdb0bae29804a832cb0345ae61304e4
7
- data.tar.gz: 9460758729591b77bc7108fe3f891f23ac4fed319c3c78a47dd9bb11a9fc349059cadb17ae6b511e2aa36ffc241c2a077042b6e8bfead949f12156dc199bb9dc
6
+ metadata.gz: 57ec66d9b4a9ad69a10652462abaaff539a7812a668b99604dedb1377de777f87082825a210922ae201e00b23feec70f75274cd3856a94f6b81d32e854a4658c
7
+ data.tar.gz: f3c98be6168dea48fa9d20d9e192a9784df76d277a648c00a549f2b0fdb7a587b61296700e3062dfde73c77f98c93b2907b4dee473594d15477ed7dc0108d83c
@@ -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,6 +49,14 @@ module Cats
49
49
  def assign_role
50
50
  role = Cats::Core::Role.find(params[:role_id])
51
51
  @user.roles << role
52
+
53
+ case role.name
54
+ when 'warehouse_manager'
55
+ @user.add_detail(:warehouse, params[:warehouse_id])
56
+ when 'hub_manager'
57
+ @user.add_detail(:hub, params[:hub_id])
58
+ end
59
+
52
60
  data = ActiveModelSerializers::SerializableResource.new(role)
53
61
  render json: { success: true, data: data }
54
62
  end
@@ -56,6 +64,7 @@ module Cats
56
64
  def revoke_role
57
65
  role = Cats::Core::Role.find(params[:role_id])
58
66
  @user.roles.delete(role)
67
+ @user.remove_detail(role.name) if %w[warehouse_manager hub_manager].include?(role.name)
59
68
  data = ActiveModelSerializers::SerializableResource.new(role)
60
69
  render json: { success: true, data: data }
61
70
  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
@@ -31,6 +31,16 @@ module Cats
31
31
  Cats::Core::Location.find_by(id: details['hub'], location_type: Cats::Core::Location::HUB)
32
32
  end
33
33
 
34
+ def add_detail(key, value)
35
+ details[key] = value
36
+ save!
37
+ end
38
+
39
+ def remove_detail(key)
40
+ details.delete(key)
41
+ save!
42
+ end
43
+
34
44
  def validate_phone_number
35
45
  return unless phone_number.present?
36
46
 
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.1.22'.freeze
3
+ VERSION = '1.1.26'.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.22
4
+ version: 1.1.26
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-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers