cats_core 1.3.22 → 1.3.26
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/cats/core/dispatch_plans_controller.rb +4 -9
- data/app/controllers/cats/core/transporters_controller.rb +13 -0
- data/app/models/cats/core/commodity.rb +12 -2
- data/app/models/cats/core/dispatch_plan.rb +7 -3
- data/app/models/cats/core/donation.rb +1 -1
- data/app/models/cats/core/monthly_plan.rb +10 -0
- data/app/models/cats/core/purchase_order.rb +8 -1
- data/app/models/cats/core/rhn_request.rb +10 -0
- data/app/models/concerns/cats/core/dispatchable.rb +15 -0
- data/app/serializers/cats/core/dispatch_plan_serializer.rb +3 -2
- data/app/serializers/cats/core/transporter_serializer.rb +7 -0
- data/app/services/cats/core/dispatch_plan_service.rb +6 -11
- data/config/routes.rb +1 -0
- data/db/migrate/20210717032330_create_cats_core_donations.rb +1 -0
- data/db/migrate/20210717032855_create_cats_core_purchase_orders.rb +6 -0
- data/db/migrate/20210718043328_create_cats_core_dispatch_plans.rb +1 -1
- data/lib/cats/core/version.rb +1 -1
- data/spec/factories/cats/core/dispatch_plans.rb +5 -1
- data/spec/factories/cats/core/donations.rb +1 -0
- data/spec/factories/cats/core/purchase_orders.rb +3 -0
- metadata +9 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f481bcc7803014db0c3db658b15064be22767d067276c5c89dbf783ae38b3af
|
4
|
+
data.tar.gz: 316ad648dcbb23aa8615354922c83c0aa287f6a66f5520fe2bf50ba42d757295
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d4ea070ce7b41661c532d8e5f6b7d9f499ac7d566698681e603c331aef729d2341b70d16df730f5d8d9f0bd947e8c391afe40244de26af2c1428a407a043076
|
7
|
+
data.tar.gz: ee48e5c321a596e34cd9215dfe8b8219e67cbd9c9e8e392dc620a94e68b5220e04795a65267c24063f40b90a5f30f913acab6b82b5770a2b49c649e0719d8cb5
|
@@ -15,15 +15,10 @@ module Cats
|
|
15
15
|
|
16
16
|
def create
|
17
17
|
service = DispatchPlanService.new
|
18
|
-
|
19
|
-
data
|
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, :
|
35
|
+
params.require(:payload).permit(:reference_no, :dispatchable_id, :dispatchable_type, :commodity_id)
|
41
36
|
end
|
42
37
|
end
|
43
38
|
end
|
@@ -14,9 +14,19 @@ module Cats
|
|
14
14
|
|
15
15
|
# Arrival Statuses
|
16
16
|
AT_SOURCE = 'At Source'.freeze
|
17
|
-
|
17
|
+
AT_ORIGIN_PORT = 'At Origin Port'.freeze
|
18
|
+
IN_LOCAL_TRANSIT = 'In Local Transit'.freeze
|
19
|
+
IN_INTERNATIONAL_TRANSIT = 'In International Transit'.freeze
|
20
|
+
AT_DESTINATION_PORT = 'At Destination Port'.freeze
|
18
21
|
ARRIVED = 'Arrived'.freeze
|
19
|
-
ARRIVAL_STATUSES = [
|
22
|
+
ARRIVAL_STATUSES = [
|
23
|
+
AT_SOURCE,
|
24
|
+
AT_ORIGIN_PORT,
|
25
|
+
IN_LOCAL_TRANSIT,
|
26
|
+
IN_INTERNATIONAL_TRANSIT,
|
27
|
+
AT_DESTINATION_PORT,
|
28
|
+
ARRIVED
|
29
|
+
].freeze
|
20
30
|
|
21
31
|
belongs_to :unit_of_measure
|
22
32
|
belongs_to :source, polymorphic: true
|
@@ -5,7 +5,7 @@ module Cats
|
|
5
5
|
APPROVED = 'Approved'.freeze
|
6
6
|
STATUSES = [DRAFT, APPROVED].freeze
|
7
7
|
|
8
|
-
belongs_to :
|
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,12 @@ module Cats
|
|
16
16
|
validates :status, inclusion: { in: STATUSES }
|
17
17
|
|
18
18
|
delegate(:batch_no, :name, :quantity, to: :commodity, prefix: true)
|
19
|
-
delegate(:
|
20
|
-
delegate(:
|
19
|
+
delegate(:request_reference, to: :dispatchable, allow_nil: true)
|
20
|
+
delegate(:request_quantity, to: :dispatchable, allow_nil: true)
|
21
|
+
|
22
|
+
before_save do |plan|
|
23
|
+
plan.upstream = !plan.dispatchable.nil? && plan.dispatchable_type == RhnRequest.name
|
24
|
+
end
|
21
25
|
|
22
26
|
def approve
|
23
27
|
raise(StandardError, 'Dispatch plan already approved.') if status == APPROVED
|
@@ -11,7 +11,7 @@ module Cats
|
|
11
11
|
belongs_to :commodity_category, optional: true
|
12
12
|
belongs_to :unit_of_measure, optional: true
|
13
13
|
|
14
|
-
validates :reference_no, :amount, :donation_type, :donated_on, presence: true
|
14
|
+
validates :reference_no, :amount, :donation_type, :donated_on, :agency, presence: true
|
15
15
|
validates :reference_no, uniqueness: true
|
16
16
|
validates :donation_type, inclusion: { in: DONATION_TYPES }
|
17
17
|
validates :currency, presence: true, if: -> { donation_type == CASH }
|
@@ -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,11 +1,18 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class PurchaseOrder < ApplicationRecord
|
4
|
+
LOCAL = 'Local'.freeze
|
5
|
+
FOREIGN = 'Foreign'.freeze
|
6
|
+
PURCHASE_TYPES = [LOCAL, FOREIGN].freeze
|
7
|
+
|
4
8
|
belongs_to :donation
|
5
9
|
belongs_to :commodity_category
|
10
|
+
belongs_to :unit, class_name: 'Cats::Core::UnitOfMeasure'
|
6
11
|
|
7
|
-
validates :reference_no, :order_date, :supplier, presence: true
|
12
|
+
validates :reference_no, :order_date, :supplier, :quantity, :purchase_type, presence: true
|
8
13
|
validates :reference_no, uniqueness: true
|
14
|
+
validates :purchase_type, inclusion: { in: PURCHASE_TYPES }
|
15
|
+
validates :quantity, numericality: { greater_than: 0 }
|
9
16
|
|
10
17
|
delegate(:name, to: :commodity_category, prefix: true)
|
11
18
|
|
@@ -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, :
|
5
|
-
:
|
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
|
@@ -3,24 +3,19 @@ module Cats
|
|
3
3
|
class DispatchPlanService
|
4
4
|
def approve(plan)
|
5
5
|
plan.approve
|
6
|
-
|
6
|
+
|
7
|
+
plan.dispatchable.allocate if plan.dispatchable_type == 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
|
-
|
22
|
-
|
23
|
-
|
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]
|
@@ -5,6 +5,7 @@ class CreateCatsCoreDonations < ActiveRecord::Migration[6.1]
|
|
5
5
|
t.string :description
|
6
6
|
t.string :donation_type, null: false
|
7
7
|
t.date :donated_on, null: false
|
8
|
+
t.string :agency, null: false
|
8
9
|
t.references :donor,
|
9
10
|
null: false,
|
10
11
|
index: { name: 'donor_on_donation_indx' },
|
@@ -5,6 +5,8 @@ class CreateCatsCorePurchaseOrders < ActiveRecord::Migration[6.1]
|
|
5
5
|
t.date :order_date, null: false
|
6
6
|
t.string :requisition_no
|
7
7
|
t.string :supplier, null: false
|
8
|
+
t.float :quantity, null: false
|
9
|
+
t.string :purchase_type, null: false
|
8
10
|
|
9
11
|
t.references :donation,
|
10
12
|
null: false,
|
@@ -14,6 +16,10 @@ class CreateCatsCorePurchaseOrders < ActiveRecord::Migration[6.1]
|
|
14
16
|
null: false,
|
15
17
|
index: { name: 'po_on_cc_indx' },
|
16
18
|
foreign_key: { to_table: :cats_core_commodity_categories }
|
19
|
+
t.references :unit,
|
20
|
+
null: false,
|
21
|
+
index: { name: 'unit_on_po_indx' },
|
22
|
+
foreign_key: { to_table: :cats_core_unit_of_measures }
|
17
23
|
|
18
24
|
t.timestamps
|
19
25
|
end
|
@@ -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 :
|
7
|
+
t.references :dispatchable, polymorphic: true
|
8
8
|
t.boolean :upstream, null: false, default: false
|
9
9
|
t.references :commodity,
|
10
10
|
null: false,
|
data/lib/cats/core/version.rb
CHANGED
@@ -2,10 +2,14 @@ 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
|
-
|
5
|
+
dispatchable { nil }
|
6
6
|
upstream { false }
|
7
7
|
commodity
|
8
8
|
prepared_by factory: :user
|
9
9
|
approved_by { nil }
|
10
|
+
|
11
|
+
trait :with_rhn do
|
12
|
+
dispatchable { create(:rhn_request) }
|
13
|
+
end
|
10
14
|
end
|
11
15
|
end
|
@@ -4,7 +4,10 @@ FactoryBot.define do
|
|
4
4
|
order_date { Date.today }
|
5
5
|
requisition_no { FFaker::Name.name }
|
6
6
|
supplier { FFaker::Name.name }
|
7
|
+
quantity { 100 }
|
8
|
+
purchase_type { Cats::Core::PurchaseOrder::LOCAL }
|
7
9
|
donation
|
8
10
|
commodity_category
|
11
|
+
unit factory: :unit_of_measure
|
9
12
|
end
|
10
13
|
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.3.
|
4
|
+
version: 1.3.26
|
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-
|
11
|
+
date: 2022-02-05 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.
|
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: []
|