cats_core 1.4.25 → 1.4.26

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: ad828e18f9f084f3c2e0343af564a1f1cc4832e935c9eec068503f4293442b87
4
- data.tar.gz: 8e0520ff2a6df1e2b4dd3f726a60aef02ef45915158c72c73ccbc74a9ae2786d
3
+ metadata.gz: 67116f414334d42cf370f7a2ec48cf137bd1ac0c8d1345e0ce5c99f8fc87c57c
4
+ data.tar.gz: 0fc96065462743887b84a6bc750f97d52bd1f047a32c71fa1b70bb3eda9148cb
5
5
  SHA512:
6
- metadata.gz: cc1d8fc0861a5f8c46734cbbf029608625e8734d31361cf924834769166cc6d429f247b169b299616a5bedcf9dffd0cdc2ad4960e4caa502757a1a98cfd55865
7
- data.tar.gz: '0850a3f89b88aea548765a78f46a8d4cac259642dc3f8c15837ab54c1d5c7911b311b8b55719972fe19312cf614d07042652376556a134ea2e20c8b1f7227fc1'
6
+ metadata.gz: 148225081058c17d1435f7888da4076ecfacb458a37154e64fd5eabe1fb3470cc3ff4fcafa696db893eb3d3a70ad90920cb25b408723fd4140b3a6e1f70d02ea
7
+ data.tar.gz: a7ee6bc61afe79bfbb22d65a02852ea00a0872971c023fd0783f30de6f33b59eb47a4807887b239aa8e54996eca58924fdae8321c73c1af2db078e193f39067d
@@ -17,6 +17,23 @@ module Cats
17
17
  render json: { success: false, error: e.message }
18
18
  end
19
19
 
20
+ def stack
21
+ service = AuthorizationService.new
22
+ authorization = ReceiptAuthorization.find(params[:id])
23
+ authorization = service.stack(authorization.id)
24
+ render json: { success: true, data: serialize(authorization) }
25
+ rescue StandardError => e
26
+ render json: { success: false, error: e.message }
27
+ end
28
+
29
+ def storekeeper_authorizations
30
+ storekeeper = User.find(params[:id])
31
+ status = params[:status]
32
+ stores = storekeeper.stores
33
+ authorizations = ReceiptAuthorization.where(store: stores, status: status)
34
+ render json: { success: true, data: serialize(authorizations) }
35
+ end
36
+
20
37
  private
21
38
 
22
39
  def model_params
@@ -5,11 +5,10 @@ module Cats
5
5
  APPROVED = 'Approved'.freeze
6
6
  READY_TO_START = 'Ready to Start'.freeze
7
7
  STARTED = 'Started'.freeze
8
- ARRIVED = 'Arrived'.freeze
9
- UNLOADED = 'Unloaded'.freeze
10
8
  RECEIVED = 'Received'.freeze
9
+ STACKED = 'Stacked'.freeze
11
10
 
12
- DISPATCH_STATUSES = [DRAFT, APPROVED, READY_TO_START, STARTED, ARRIVED, UNLOADED, RECEIVED].freeze
11
+ DISPATCH_STATUSES = [DRAFT, APPROVED, READY_TO_START, STARTED, RECEIVED, STACKED].freeze
13
12
 
14
13
  belongs_to :prepared_by, class_name: 'Cats::Core::User'
15
14
  belongs_to :transporter
@@ -73,12 +72,24 @@ module Cats
73
72
  save!
74
73
  end
75
74
 
75
+ def receive
76
+ raise(StandardError, 'Dispatch is not started.') unless dispatch_status == Dispatch::STARTED
77
+
78
+ self.dispatch_status = RECEIVED
79
+ save!
80
+ end
81
+
82
+ def stack
83
+ self.dispatch_status = STACKED
84
+ save!
85
+ end
86
+
76
87
  def self.search_commodity(batch_no)
77
88
  commodity = Commodity.find_by(batch_no: batch_no)
78
89
  dispatches = Dispatch.includes(:dispatch_transactions)
79
90
  .joins(:transporter)
80
91
  .where(
81
- dispatch_status: [APPROVED, STARTED, ARRIVED, UNLOADED]
92
+ dispatch_status: [APPROVED, STARTED]
82
93
  )
83
94
  dispatches.map do |dispatch|
84
95
  {
@@ -18,8 +18,28 @@ module Cats
18
18
  authorization.save!
19
19
  raise(StandardError, 'Pin has expired.')
20
20
  end
21
+
21
22
  authorization.driver_confirmed = true
22
23
  authorization.save!
24
+ statuses = authorization.dispatch.receipt_authorizations.map(&:driver_confirmed).uniq
25
+ authorization.dispatch.receive if statuses.length == 1 && statuses[0]
26
+
27
+ authorization
28
+ end
29
+
30
+ def stack(authorization_id)
31
+ authorization = ReceiptAuthorization.find(authorization_id)
32
+ unless authorization.dispatch.dispatch_status == Dispatch::RECEIVED
33
+ raise(StandardError, 'Dispatch is not received.')
34
+ end
35
+
36
+ total = authorization.transactions.sum(:quantity)
37
+ if total != authorization.received_quantity
38
+ raise(StandardError, 'Received quantity is not the same as quantity to be stacked.')
39
+ end
40
+
41
+ authorization.transactions.each(&:commit)
42
+ authorization.dispatch.stack
23
43
  authorization
24
44
  end
25
45
  end
@@ -34,13 +34,10 @@ module Cats
34
34
  end
35
35
  end
36
36
 
37
- def receipt_stacks(receipt)
38
- location = receipt.dispatch.dispatch_plan_item.destination
39
- warehouses = location.children
40
- stores = Store.where(warehouse: warehouses)
41
-
42
- commodity = receipt.dispatch.dispatch_plan_item.commodity
43
- Stack.where(commodity: commodity, store: stores)
37
+ def receipt_stacks(authorization_id)
38
+ authorization = ReceiptAuthorization.find(authorization_id)
39
+ commodity = authorization.dispatch.dispatch_plan_item.commodity
40
+ Stack.where(commodity: commodity, store_id: authorization.store_id)
44
41
  end
45
42
 
46
43
  def dispatch_stacks(dispatch)
data/config/routes.rb CHANGED
@@ -119,10 +119,16 @@ Cats::Core::Engine.routes.draw do
119
119
  end
120
120
 
121
121
  get(
122
- '/storekeeper/:id/authorizations',
122
+ '/storekeeper/:id/dispatch_authorizations',
123
123
  controller: :dispatch_authorizations,
124
124
  action: :storekeeper_authorizations,
125
- as: :storekeeper_authorizations
125
+ as: :storekeeper_dispatch_authorizations
126
+ )
127
+ get(
128
+ '/storekeeper/:id/receipt_authorizations',
129
+ controller: :receipt_authorizations,
130
+ action: :storekeeper_authorizations,
131
+ as: :storekeeper_receipt_authorizations
126
132
  )
127
133
  resources :receipt_authorizations, except: %i[index destroy] do
128
134
  member do
@@ -130,6 +136,7 @@ Cats::Core::Engine.routes.draw do
130
136
  get 'lost', controller: :lost_commodities, action: :index
131
137
  get 'receipts', controller: :receipts, action: :index
132
138
  post 'confirm', controller: :receipt_authorizations, action: :confirm
139
+ post 'stack'
133
140
  end
134
141
  end
135
142
 
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.4.25'.freeze
3
+ VERSION = '1.4.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.4.25
4
+ version: 1.4.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: 2022-05-29 00:00:00.000000000 Z
11
+ date: 2022-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers