cats_core 1.1.3 → 1.1.4

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: 20f6349c8a17610b338d05e2fa64a35d76bf0f3737f898ed9ab4d58d76053085
4
- data.tar.gz: 74f16a28eaaf4608b0b2d1935331d8837f49cc805511412df57f902c6d421349
3
+ metadata.gz: 63d1bc4e2e97985bc79c49007a2d826b43caec3b8fc31eca51fa4f588d22e10f
4
+ data.tar.gz: d4d08836b88121d75bd29fb711975726285b9ab5f7b64285ed48349cff51e2e3
5
5
  SHA512:
6
- metadata.gz: 1b3dbbd8c4da02cb692bf9eae19d6e653ced98de74f54a6a9cae9c6c0dddbe2dfd7fb7b5ec4d1881445e0cf159a2e093111b2acc25dd72309b2c183ff6f94c5b
7
- data.tar.gz: 05ad4779c0d90d975fc172c4c98c6729e3ff45092953408c31f4cdade4b01dae94eaf655dc857d793e6064770a3a44b93127e62b31ee890633871a509998768a
6
+ metadata.gz: 6bc9fdab7012e63bcda95512f54f0fe8586c225a8eec25c88dcc3ed6b0634aa21a6a62ba5e6091f21b718f10d9df93eeabdf0a88a62a78891f244dc2c14d3bac
7
+ data.tar.gz: 9ced66786a2d6303d5ea944366cf9357ff9d3a9ab8e4406d2a6c490d8969e0c6431b2265e321a965a2ab10c503bc51e4cbdd40766581f8af6ccf844405f58527
@@ -1,50 +1,20 @@
1
1
  module Cats
2
2
  module Core
3
3
  class LocationsController < ApplicationController
4
- before_action :set_location, only: %i[show update]
4
+ include Common
5
5
 
6
6
  def index
7
7
  locations = Cats::Core::Location.where(location_type: params[:location_type])
8
- data = ActiveModelSerializers::SerializableResource.new(locations)
9
- render json: { success: true, data: data }
10
- end
11
-
12
- def show
13
- data = ActiveModelSerializers::SerializableResource.new(@location)
14
- render json: { success: true, data: data }
8
+ render json: { success: true, data: serialize(locations) }
15
9
  end
16
10
 
17
11
  def children
18
12
  parent = Cats::Core::Location.find(params[:id])
19
- data = ActiveModelSerializers::SerializableResource.new(parent.children)
20
- render json: { success: true, data: data }
21
- end
22
-
23
- def create
24
- obj = Cats::Core::Location.new(model_params)
25
- if obj.save
26
- data = ActiveModelSerializers::SerializableResource.new(obj)
27
- render json: { success: true, data: data }, status: :created
28
- else
29
- render json: { success: false, error: obj.errors.full_messages[0] }, status: :unprocessable_entity
30
- end
31
- end
32
-
33
- def update
34
- if @location.update(model_params)
35
- data = ActiveModelSerializers::SerializableResource.new(@location)
36
- render json: { success: true, data: data }
37
- else
38
- render json: { success: false, error: @location.errors.full_messages[0] }, status: :unprocessable_entity
39
- end
13
+ render json: { success: true, data: serialize(parent.children) }
40
14
  end
41
15
 
42
16
  private
43
17
 
44
- def set_location
45
- @location = Cats::Core::Location.find(params[:id])
46
- end
47
-
48
18
  def model_params
49
19
  params.require(:payload).permit(:code, :name, :location_type, :description, :parent_id)
50
20
  end
@@ -0,0 +1,13 @@
1
+ module Cats
2
+ module Core
3
+ class ReceiptTransactionsController < ApplicationController
4
+ include Common
5
+
6
+ private
7
+
8
+ def model_params
9
+ params.require(:payload).permit(:source_id, :destination_id, :transaction_date, :quantity)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -8,6 +8,24 @@ module Cats
8
8
  render json: { success: true, data: serialize(receipts) }
9
9
  end
10
10
 
11
+ def start_stacking
12
+ receipt = Cats::Core::Receipt.find(params[:id])
13
+ service = ReceiptService.new
14
+ result = service.start_stacking(receipt)
15
+ render json: { success: true, data: serialize(result) }
16
+ rescue StandardError => e
17
+ render json: { success: false, error: e.message }
18
+ end
19
+
20
+ def stack
21
+ receipt = Cats::Core::Receipt.find(params[:id])
22
+ service = ReceiptService.new
23
+ result = service.stack(receipt)
24
+ render json: { success: true, data: serialize(result) }
25
+ rescue StandardError => e
26
+ render json: { success: false, error: e.message }
27
+ end
28
+
11
29
  private
12
30
 
13
31
  def model_params
@@ -10,6 +10,7 @@ module Cats
10
10
 
11
11
  belongs_to :dispatch
12
12
  belongs_to :prepared_by, class_name: 'Cats::Core::User'
13
+ has_many :receipt_transactions, foreign_key: :source_id
13
14
 
14
15
  validates :quantity, :commodity_status, :status, presence: true
15
16
  validates :quantity, numericality: { greater_than: 0 }
@@ -0,0 +1,8 @@
1
+ class ReceiptTransactionSerializer < ActiveModel::Serializer
2
+ attributes :id, :source_id, :dispatch_reference, :destination_id, :destination_code, :quantity, :transaction_date,
3
+ :status
4
+
5
+ def dispatch_reference
6
+ object.source.dispatch.reference_no
7
+ end
8
+ end
@@ -0,0 +1,32 @@
1
+ module Cats
2
+ module Core
3
+ class ReceiptService
4
+ def start_stacking(receipt)
5
+ raise(StandardError, 'Receipt should be confirmed.') unless receipt.status == Cats::Core::Receipt::CONFIRMED
6
+
7
+ raise(StandardError, 'There are no stack assignments in receipt.') if receipt.receipt_transactions.count.zero?
8
+
9
+ receipt.status = Cats::Core::Receipt::STACKING
10
+ receipt.save!
11
+ receipt
12
+ end
13
+
14
+ def stack(receipt)
15
+ unless receipt.status == Cats::Core::Receipt::STACKING
16
+ raise(StandardError, 'Receipt should be in stacking state.')
17
+ end
18
+
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
28
+ receipt
29
+ end
30
+ end
31
+ end
32
+ end
data/config/routes.rb CHANGED
@@ -66,5 +66,11 @@ Cats::Core::Engine.routes.draw do
66
66
  end
67
67
  end
68
68
  resources :dispatch_transactions, except: %i[new edit destroy]
69
- resources :receipts, except: %i[index new edit destroy]
69
+ resources :receipts, except: %i[index new edit destroy] do
70
+ member do
71
+ post 'start_stacking'
72
+ post 'stack'
73
+ end
74
+ end
75
+ resources :receipt_transactions, except: %i[new edit destroy]
70
76
  end
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.1.3'.freeze
3
+ VERSION = '1.1.4'.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.3
4
+ version: 1.1.4
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-09-25 00:00:00.000000000 Z
11
+ date: 2021-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers
@@ -225,6 +225,7 @@ files:
225
225
  - app/controllers/cats/core/locations_controller.rb
226
226
  - app/controllers/cats/core/menus_controller.rb
227
227
  - app/controllers/cats/core/notifications_controller.rb
228
+ - app/controllers/cats/core/receipt_transactions_controller.rb
228
229
  - app/controllers/cats/core/receipts_controller.rb
229
230
  - app/controllers/cats/core/roles_controller.rb
230
231
  - app/controllers/cats/core/spaces_controller.rb
@@ -277,11 +278,13 @@ files:
277
278
  - app/serializers/cats/core/dispatch_transaction_serializer.rb
278
279
  - app/serializers/cats/core/location_serializer.rb
279
280
  - app/serializers/cats/core/receipt_serializer.rb
281
+ - app/serializers/cats/core/receipt_transaction_serializer.rb
280
282
  - app/serializers/cats/core/role_menu_serializer.rb
281
283
  - app/serializers/cats/core/unit_of_measure_serializer.rb
282
284
  - app/services/cats/core/dispatch_service.rb
283
285
  - app/services/cats/core/menu_service.rb
284
286
  - app/services/cats/core/notification_service.rb
287
+ - app/services/cats/core/receipt_service.rb
285
288
  - app/services/cats/core/space_service.rb
286
289
  - app/services/cats/core/token_auth_service.rb
287
290
  - config/routes.rb