cats_core 1.1.3 → 1.1.7

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: b37b40530cf4eeccf1ae2e3b5c8eb03bd2691196ce628ee9596a855054016de5
4
+ data.tar.gz: d1e0b7ed6c38bcefcfb3c44e4efa6389de0502de25c677725ac9473cd0eeb414
5
5
  SHA512:
6
- metadata.gz: 1b3dbbd8c4da02cb692bf9eae19d6e653ced98de74f54a6a9cae9c6c0dddbe2dfd7fb7b5ec4d1881445e0cf159a2e093111b2acc25dd72309b2c183ff6f94c5b
7
- data.tar.gz: 05ad4779c0d90d975fc172c4c98c6729e3ff45092953408c31f4cdade4b01dae94eaf655dc857d793e6064770a3a44b93127e62b31ee890633871a509998768a
6
+ metadata.gz: f3f2d8888ba178611b3b09ac19dc201ee5a7971cfd72171cea12c58e97c0ef4ef65c3713a524e8e712f9495fea15b21edb56d6578a780a9f9b1512808e7dc6f3
7
+ data.tar.gz: cdef99c802223c7094242ed4781ade0d9dc970b86dabc9ce9d17e9babb0b8c1e232440564a26a23d643c83c30777353f2de9673b90dd7e65f171b213db0b101b
@@ -4,7 +4,7 @@ module Cats
4
4
  include Common
5
5
 
6
6
  before_action :set_service, only: %i[create_receipt_authorization approve start search confirm]
7
- before_action :set_dispatch, only: %i[approve start confirm]
7
+ before_action :set_dispatch, only: %i[approve start confirm commodity]
8
8
 
9
9
  def index
10
10
  dispatches = Cats::Core::Dispatch.where(allocation_item_id: params[:id])
@@ -56,6 +56,11 @@ module Cats
56
56
  render json: { success: true, data: serialize(data) }
57
57
  end
58
58
 
59
+ def commodity
60
+ data = @dispatch.allocation_item.allocation.commodity
61
+ render json: { success: true, data: serialize(data) }
62
+ end
63
+
59
64
  private
60
65
 
61
66
  def set_service
@@ -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
@@ -5,6 +5,16 @@ module Cats
5
5
 
6
6
  validates :reference_no, presence: true, uniqueness: true
7
7
  validates :gift_date, presence: true
8
+
9
+ after_create :update_donation
10
+
11
+ def update_donation
12
+ donation = self.donation
13
+ return if donation.active
14
+
15
+ donation.active = true
16
+ donation.save!
17
+ end
8
18
  end
9
19
  end
10
20
  end
@@ -8,6 +8,16 @@ module Cats
8
8
  validates :reference_no, uniqueness: true
9
9
 
10
10
  delegate(:name, to: :commodity_category, prefix: true)
11
+
12
+ after_create :update_donation
13
+
14
+ def update_donation
15
+ donation = self.donation
16
+ return if donation.active
17
+
18
+ donation.active = true
19
+ donation.save!
20
+ end
11
21
  end
12
22
  end
13
23
  end
@@ -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,9 @@
1
+ module Cats
2
+ module Core
3
+ class CommoditySerializer < ActiveModel::Serializer
4
+ attributes :id, :batch_no, :description, :unit_of_measure_id, :unit_of_measure_abbreviation, :source_id,
5
+ :source_type, :source_reference_no, :quantity, :best_use_before, :volume_per_metric_ton,
6
+ :commodity_category_id, :commodity_category_name, :arrival_status, :approved
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  class LocationSerializer < ActiveModel::Serializer
2
- attributes :id, :name, :location_type, :description, :parent_id
2
+ attributes :id, :code, :name, :location_type, :description, :parent_id
3
3
  end
@@ -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
@@ -60,11 +60,18 @@ Cats::Core::Engine.routes.draw do
60
60
  resources :dispatches, except: %i[index destroy] do
61
61
  member do
62
62
  get 'receipts', controller: :receipts, action: :index
63
+ get 'commodity'
63
64
  post 'approve'
64
65
  post 'start'
65
66
  post 'confirm'
66
67
  end
67
68
  end
68
69
  resources :dispatch_transactions, except: %i[new edit destroy]
69
- resources :receipts, except: %i[index new edit destroy]
70
+ resources :receipts, except: %i[index new edit destroy] do
71
+ member do
72
+ post 'start_stacking'
73
+ post 'stack'
74
+ end
75
+ end
76
+ resources :receipt_transactions, except: %i[new edit destroy]
70
77
  end
@@ -25,6 +25,7 @@ class CreateCatsCoreDonations < ActiveRecord::Migration[6.1]
25
25
  null: true,
26
26
  index: { name: 'uom_on_donation_indx' },
27
27
  foreign_key: { to_table: :cats_core_unit_of_measures }
28
+ t.boolean :active, null: false, default: false
28
29
 
29
30
  t.timestamps
30
31
  end
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.1.3'.freeze
3
+ VERSION = '1.1.7'.freeze
4
4
  end
5
5
  end
@@ -9,5 +9,6 @@ FactoryBot.define do
9
9
  currency { nil }
10
10
  commodity_category
11
11
  unit_of_measure
12
+ active { false }
12
13
  end
13
14
  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.7
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-29 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
@@ -272,16 +273,19 @@ files:
272
273
  - app/models/cats/core/user.rb
273
274
  - app/notifications/cats/core/simple_notification.rb
274
275
  - app/serializers/cats/core/commodity_category_serializer.rb
276
+ - app/serializers/cats/core/commodity_serializer.rb
275
277
  - app/serializers/cats/core/currency_serializer.rb
276
278
  - app/serializers/cats/core/dispatch_serializer.rb
277
279
  - app/serializers/cats/core/dispatch_transaction_serializer.rb
278
280
  - app/serializers/cats/core/location_serializer.rb
279
281
  - app/serializers/cats/core/receipt_serializer.rb
282
+ - app/serializers/cats/core/receipt_transaction_serializer.rb
280
283
  - app/serializers/cats/core/role_menu_serializer.rb
281
284
  - app/serializers/cats/core/unit_of_measure_serializer.rb
282
285
  - app/services/cats/core/dispatch_service.rb
283
286
  - app/services/cats/core/menu_service.rb
284
287
  - app/services/cats/core/notification_service.rb
288
+ - app/services/cats/core/receipt_service.rb
285
289
  - app/services/cats/core/space_service.rb
286
290
  - app/services/cats/core/token_auth_service.rb
287
291
  - config/routes.rb