cats_core 1.3.20 → 1.3.24

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: 9e298fc271839d6ddb95ce6fc876b1b6438e31fb15c94049ffc6e36431670330
4
- data.tar.gz: 3a8d54022afad56f01b5be2433cbcf28154cf8a7ba7eee5390a3c3265d139037
3
+ metadata.gz: 2531c2f89fe44de09ddf14fd923e8d990a3e1926775eea0962b5a3d4787d7457
4
+ data.tar.gz: ec9cbed2a69e8f62884556108dbbc1ab448a360a7273fe2843f3fb754a3982c4
5
5
  SHA512:
6
- metadata.gz: 7cc8eb81b7edd12b5676d45c67b84d16fd8cb869cf5ad515736a3584a8c3dd4bf8274e3364c35b4bced831e9c0e94edcb124cfb1bfc22c551db36fd4c0f16456
7
- data.tar.gz: 2e9555de096c8a8c22295ff8ef0247de401a2906862800fa31b8e1f4f49dbdb2cac88751941f84d28a4217390bdcd3698790ade35d4fab75eea6e09fd79544c6
6
+ metadata.gz: 52d97959257855990865164a5f63ff2b529b17c97995de5c30ee658ae169ec8a77c3b3ff52a459b658e6dd4f93757ff1db4b64e2c33fb5de004dcd5106b688b6
7
+ data.tar.gz: 64edb99aecf7615a963971661748cdef7d62faf0d7450dcdebf0b2ffb1100373ce60a8aa79f261ed884542812530c60f1b8cefcdb4e5f21a59e0c296dec07ed5
@@ -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
 
@@ -9,6 +9,7 @@ module Cats
9
9
  validates :beneficiaries, presence: true, numericality: { greater_than: 0 }
10
10
 
11
11
  delegate(:reference_no, to: :monthly_plan, prefix: 'plan')
12
+ delegate(:woreda_name, to: :plan_item)
12
13
  end
13
14
  end
14
15
  end
@@ -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, :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,7 @@
1
+ module Cats
2
+ module Core
3
+ class TransporterSerializer < ActiveModel::Serializer
4
+ attributes :id, :code, :name, :address, :contact_phone
5
+ end
6
+ end
7
+ 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.20'.freeze
3
+ VERSION = '1.3.24'.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.20
4
+ version: 1.3.24
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-17 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: []