cats_core 1.3.22 → 1.3.23

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: 3e19b31050b332057df303229d63b57fe37df4608769e70684b9d3f7a35492ec
4
- data.tar.gz: 1254bcbeb26ea89e70f710bdb4429f1e02a3cd80bb913c0ec9f7be5d1f3df42d
3
+ metadata.gz: 1c3f37fca9f63d54dbce888d0beaeb5e3bbd96ac1e1052011433711c2d1b126a
4
+ data.tar.gz: b018b4b1903cb423c01a37eefc6ec109db0757294b5179f3eb1faba0b30dd6e4
5
5
  SHA512:
6
- metadata.gz: 54d98fda12c17f62461414a08f301e2f7b0b6ed5857ff9841cf12c0a03e53b0fa8bf0040bbc389bed789ea5d043fd9d5e401e50a567a9d9b88b8db19ffe3c59a
7
- data.tar.gz: c25d388617ea0f3a694e7b03d5985b9d1fd87ee7a9a08394109ec9eaefd33d0854d70bdcbefbaf99d3713332d071a7be674cd8003327709d6312e923115055d2
6
+ metadata.gz: 047d73951d974a609d6caa7c1d76b1ce156d4c2d47e446fc16821732dfdcf0a017eff53dac8c7f64eae1cec0534e9e4cc651cf46f084fdb81892c64245c170d6
7
+ data.tar.gz: 6e515febfd96c18ab7876fa0ab92c511f34e96c31e3241419b2bd3a2bf5789f65894e958621a16b5a7ae1c35cd00a91640202aaf66213971ba9f0517c29f5b46
@@ -15,15 +15,10 @@ module Cats
15
15
 
16
16
  def create
17
17
  service = DispatchPlanService.new
18
-
19
- data = service.create(model_params, current_user)
20
- if data[0]
21
- render json: { success: true, data: serialize(data[1]) }, status: :created
22
- else
23
- render json: { success: false, error: data[1].errors.full_messages[0] }, status: :unprocessable_entity
24
- end
18
+ plan = service.create(model_params, current_user)
19
+ render json: { success: true, data: serialize(plan) }, status: :created
25
20
  rescue StandardError => e
26
- render json: { success: false, error: e.message }
21
+ render json: { success: false, error: e.message }, status: :unprocessable_entity
27
22
  end
28
23
 
29
24
  def approve
@@ -37,7 +32,7 @@ module Cats
37
32
  private
38
33
 
39
34
  def model_params
40
- params.require(:payload).permit(:reference_no, :request_id, :commodity_id)
35
+ params.require(:payload).permit(:reference_no, :dispatchable_id, :dispatchable_type, :commodity_id)
41
36
  end
42
37
  end
43
38
  end
@@ -0,0 +1,13 @@
1
+ module Cats
2
+ module Core
3
+ class TransportersController < ApplicationController
4
+ include Cats::Core::Common
5
+
6
+ private
7
+
8
+ def model_params
9
+ params.require(:payload).permit(:code, :name, :address, :contact_phone)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -5,7 +5,7 @@ module Cats
5
5
  APPROVED = 'Approved'.freeze
6
6
  STATUSES = [DRAFT, APPROVED].freeze
7
7
 
8
- belongs_to :request, polymorphic: true, optional: true
8
+ belongs_to :dispatchable, polymorphic: true, optional: true
9
9
  belongs_to :prepared_by, class_name: 'Cats::Core::User'
10
10
  belongs_to :approved_by, class_name: 'Cats::Core::User', optional: true
11
11
  belongs_to :commodity
@@ -16,8 +16,8 @@ module Cats
16
16
  validates :status, inclusion: { in: STATUSES }
17
17
 
18
18
  delegate(:batch_no, :name, :quantity, to: :commodity, prefix: true)
19
- delegate(:reference_no, to: :request, prefix: true, allow_nil: true)
20
- delegate(:quantity, to: :request, prefix: true, allow_nil: true)
19
+ delegate(:request_reference, to: :dispatchable, allow_nil: true)
20
+ delegate(:request_quantity, to: :dispatchable, allow_nil: true)
21
21
 
22
22
  def approve
23
23
  raise(StandardError, 'Dispatch plan already approved.') if status == APPROVED
@@ -1,6 +1,8 @@
1
1
  module Cats
2
2
  module Core
3
3
  class MonthlyPlan < ApplicationRecord
4
+ include Dispatchable
5
+
4
6
  belongs_to :plan
5
7
  belongs_to :region, class_name: 'Cats::Core::Location'
6
8
 
@@ -16,6 +18,14 @@ module Cats
16
18
  delegate(:reference_no, to: :plan, prefix: true)
17
19
  delegate(:name, to: :region, prefix: true)
18
20
 
21
+ def request_reference
22
+ reference_no
23
+ end
24
+
25
+ def request_quantity
26
+ nil
27
+ end
28
+
19
29
  def validate_month
20
30
  return unless month
21
31
 
@@ -1,6 +1,8 @@
1
1
  module Cats
2
2
  module Core
3
3
  class RhnRequest < ApplicationRecord
4
+ include Dispatchable
5
+
4
6
  DRAFT = 'Draft'.freeze
5
7
  APPROVED = 'Approved'.freeze
6
8
  ALLOCATED = 'Allocated'.freeze
@@ -16,6 +18,14 @@ module Cats
16
18
 
17
19
  delegate(:batch_no, to: :commodity, prefix: true)
18
20
 
21
+ def request_reference
22
+ reference_no
23
+ end
24
+
25
+ def request_quantity
26
+ quantity
27
+ end
28
+
19
29
  def validate_commodity_status
20
30
  return unless commodity
21
31
 
@@ -0,0 +1,15 @@
1
+ # A concern to represent entities that lead to dispatch plan.
2
+ # All classes including this concern must implement `request_reference()`
3
+ # and `request_quantity()` methods, which will be used to generate
4
+ # reference information in dispatch plan serializer.
5
+ module Cats
6
+ module Core
7
+ module Dispatchable
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ has_many :dispatch_plans, as: :dispatchable
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,8 +1,9 @@
1
1
  module Cats
2
2
  module Core
3
3
  class DispatchPlanSerializer < ActiveModel::Serializer
4
- attributes :id, :reference_no, :status, :request_id, :commodity_id, :commodity_name, :commodity_batch_no,
5
- :commodity_quantity, :request_reference_no, :request_quantity, :upstream
4
+ attributes :id, :reference_no, :status, :dispatchable_id, :dispatchable_type, :request_reference,
5
+ :request_quantity, :commodity_id, :commodity_name, :commodity_batch_no, :commodity_quantity,
6
+ :upstream
6
7
  end
7
8
  end
8
9
  end
@@ -0,0 +1,3 @@
1
+ class TransporterSerializer < ActiveModel::Serializer
2
+ attributes :id, :code, :name, :address, :contact_phone
3
+ end
@@ -3,24 +3,19 @@ module Cats
3
3
  class DispatchPlanService
4
4
  def approve(plan)
5
5
  plan.approve
6
- plan.request.allocate if plan.request_id
6
+
7
+ plan.dispatchable.allocate if plan.dispatchable_type == Cats::Core::RhnRequest.name
7
8
  # send_notification(plan)
8
9
  plan
9
10
  end
10
11
 
11
12
  def create(params, user)
12
13
  plan = Cats::Core::DispatchPlan.new(params)
13
- raise 'Commodity is not assigned for plan.' unless plan.commodity_id || plan.request_id
14
-
15
- unless plan.commodity_id
16
- request = Cats::Core::RhnRequest.find(plan.request_id)
17
- plan.commodity_id = request.commodity_id
18
- plan.request_type = 'Cats::Core::RhnRequest'
19
- end
20
14
  plan.prepared_by = user
21
- result = plan.save
22
-
23
- [result, plan]
15
+ plan.save!
16
+ plan
17
+ rescue ActiveRecord::RecordInvalid
18
+ raise(StandardError, plan.errors.full_messages[0])
24
19
  end
25
20
  end
26
21
  end
data/config/routes.rb CHANGED
@@ -66,6 +66,7 @@ Cats::Core::Engine.routes.draw do
66
66
  end
67
67
  resources :currencies, except: %i[destroy]
68
68
  resources :unit_of_measures, except: %i[destroy]
69
+ resources :transporters, except: %i[destroy]
69
70
 
70
71
  post '/routes/filter', controller: :routes, action: :filter
71
72
  resources :routes, except: %i[destroy]
@@ -4,7 +4,7 @@ class CreateCatsCoreDispatchPlans < ActiveRecord::Migration[6.1]
4
4
  t.string :reference_no, unique: true
5
5
  t.string :description
6
6
  t.string :status, null: false, default: 'Draft'
7
- t.references :request, polymorphic: true
7
+ t.references :dispatchable, polymorphic: true
8
8
  t.boolean :upstream, null: false, default: false
9
9
  t.references :commodity,
10
10
  null: false,
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.3.22'.freeze
3
+ VERSION = '1.3.23'.freeze
4
4
  end
5
5
  end
@@ -2,7 +2,7 @@ FactoryBot.define do
2
2
  factory :dispatch_plan, class: 'Cats::Core::DispatchPlan' do
3
3
  reference_no { FFaker::Name.name }
4
4
  status { Cats::Core::DispatchPlan::DRAFT }
5
- request { nil }
5
+ dispatchable { nil }
6
6
  upstream { false }
7
7
  commodity
8
8
  prepared_by factory: :user
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.3.22
4
+ version: 1.3.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-18 00:00:00.000000000 Z
11
+ date: 2022-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers
@@ -246,6 +246,7 @@ files:
246
246
  - app/controllers/cats/core/roles_controller.rb
247
247
  - app/controllers/cats/core/routes_controller.rb
248
248
  - app/controllers/cats/core/spaces_controller.rb
249
+ - app/controllers/cats/core/transporters_controller.rb
249
250
  - app/controllers/cats/core/unit_of_measures_controller.rb
250
251
  - app/controllers/cats/core/users_controller.rb
251
252
  - app/controllers/concerns/cats/core/common.rb
@@ -306,6 +307,7 @@ files:
306
307
  - app/models/cats/core/transporter.rb
307
308
  - app/models/cats/core/unit_of_measure.rb
308
309
  - app/models/cats/core/user.rb
310
+ - app/models/concerns/cats/core/dispatchable.rb
309
311
  - app/notifications/cats/core/allocation_notification.rb
310
312
  - app/notifications/cats/core/dispatch_notification.rb
311
313
  - app/notifications/cats/core/simple_notification.rb
@@ -322,6 +324,7 @@ files:
322
324
  - app/serializers/cats/core/role_menu_serializer.rb
323
325
  - app/serializers/cats/core/role_serializer.rb
324
326
  - app/serializers/cats/core/route_serializer.rb
327
+ - app/serializers/cats/core/transporter_serializer.rb
325
328
  - app/serializers/cats/core/unit_of_measure_serializer.rb
326
329
  - app/serializers/cats/core/user_serializer.rb
327
330
  - app/services/cats/core/dispatch_plan_service.rb
@@ -455,7 +458,7 @@ metadata:
455
458
  homepage_uri: http://cats.ndrmcapps.org
456
459
  source_code_uri: https://github.com/ndrmc/cats_core
457
460
  changelog_uri: https://github.com/ndrmc/cats_core/CHANGELOG.md
458
- post_install_message:
461
+ post_install_message:
459
462
  rdoc_options: []
460
463
  require_paths:
461
464
  - lib
@@ -470,8 +473,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
470
473
  - !ruby/object:Gem::Version
471
474
  version: '0'
472
475
  requirements: []
473
- rubygems_version: 3.2.32
474
- signing_key:
476
+ rubygems_version: 3.3.3
477
+ signing_key:
475
478
  specification_version: 4
476
479
  summary: Core module for CATS applications
477
480
  test_files: []