cats_core 1.3.13 → 1.3.18
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 +4 -4
- data/app/controllers/cats/core/access_controller.rb +2 -1
- data/app/controllers/cats/core/dispatch_plan_items_controller.rb +1 -1
- data/app/controllers/cats/core/dispatch_plans_controller.rb +9 -6
- data/app/controllers/cats/core/dispatches_controller.rb +1 -1
- data/app/models/cats/core/dispatch_plan.rb +4 -0
- data/app/models/cats/core/dispatch_plan_item.rb +2 -2
- data/app/models/cats/core/monthly_plan.rb +1 -0
- data/app/models/cats/core/monthly_plan_item.rb +2 -0
- data/app/models/cats/core/monthly_plan_item_detail.rb +1 -1
- data/app/models/cats/core/plan.rb +3 -1
- data/app/models/cats/core/rhn_request.rb +7 -1
- data/app/notifications/cats/core/dispatch_notification.rb +1 -1
- data/app/serializers/cats/core/dispatch_plan_item_serializer.rb +1 -1
- data/app/serializers/cats/core/dispatch_plan_serializer.rb +2 -1
- data/app/services/cats/core/dispatch_plan_service.rb +25 -5
- data/app/services/cats/core/dispatch_service.rb +1 -1
- data/db/migrate/20210718043328_create_cats_core_dispatch_plans.rb +4 -0
- data/db/migrate/20210718043401_create_cats_core_dispatch_plan_items.rb +1 -4
- data/db/migrate/{20220107224630_create_cats_core_monthly_rations.rb → 20220107124630_create_cats_core_monthly_rations.rb} +0 -0
- data/db/migrate/20220107132433_create_cats_core_monthly_plan_item_details.rb +3 -3
- data/lib/cats/core/version.rb +1 -1
- data/spec/factories/cats/core/dispatch_plan_items.rb +1 -1
- data/spec/factories/cats/core/dispatch_plans.rb +1 -0
- data/spec/factories/cats/core/monthly_plan_item_details.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 551532d2140d05f61a268ef27a1e2b8b9a7abb9f084dc808f161962d7f319b19
|
4
|
+
data.tar.gz: 78e9e7fd69241d39c84542d5160041df4ab2c697c60ea6cd9cd719182d7de43c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a48bca9d45e6cfc5ea41bd5657d8142aafde2cc8fb3da40d37f2ba1a306bf98c3b6f403a15996579c5f4fb0b73d26aee6f92a6ffa30696f5f61f4dec5fa6f13c
|
7
|
+
data.tar.gz: ac88009a158bd3596389611e60e558eaf6bc1f99f7686955b7ae1e1987376d153bd7a21f0c67ae6bfec474907f7a0748f8a5b2636bfbbbb7fe271c0db2d83ba8
|
@@ -15,7 +15,8 @@ module Cats
|
|
15
15
|
end
|
16
16
|
|
17
17
|
payload = {
|
18
|
-
id: user.id, email: user.email, first_name: user.first_name, last_name: user.last_name, roles: roles
|
18
|
+
id: user.id, email: user.email, first_name: user.first_name, last_name: user.last_name, roles: roles,
|
19
|
+
details: user.details
|
19
20
|
}
|
20
21
|
jwt = Cats::Core::TokenAuthService.issue(payload)
|
21
22
|
render json: { token: jwt, user: payload }
|
@@ -11,7 +11,7 @@ module Cats
|
|
11
11
|
private
|
12
12
|
|
13
13
|
def model_params
|
14
|
-
params.require(:payload).permit(:dispatch_plan_id, :source_id, :destination_id, :quantity, :
|
14
|
+
params.require(:payload).permit(:dispatch_plan_id, :source_id, :destination_id, :quantity, :commodity_status)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
@@ -14,13 +14,16 @@ module Cats
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def create
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
21
22
|
else
|
22
|
-
render json: { success: false, error:
|
23
|
+
render json: { success: false, error: data[1].errors.full_messages[0] }, status: :unprocessable_entity
|
23
24
|
end
|
25
|
+
rescue StandardError => e
|
26
|
+
render json: { success: false, error: e.message }
|
24
27
|
end
|
25
28
|
|
26
29
|
def approve
|
@@ -34,7 +37,7 @@ module Cats
|
|
34
37
|
private
|
35
38
|
|
36
39
|
def model_params
|
37
|
-
params.require(:payload).permit(:reference_no, :request_id)
|
40
|
+
params.require(:payload).permit(:reference_no, :request_id, :commodity_id)
|
38
41
|
end
|
39
42
|
end
|
40
43
|
end
|
@@ -8,12 +8,16 @@ module Cats
|
|
8
8
|
belongs_to :request, 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
|
+
belongs_to :commodity
|
11
12
|
|
12
13
|
has_many :dispatch_plan_items
|
13
14
|
|
14
15
|
validates :reference_no, presence: true, uniqueness: true
|
15
16
|
validates :status, inclusion: { in: STATUSES }
|
16
17
|
|
18
|
+
delegate(:batch_no, :name, :quantity, to: :commodity, prefix: true)
|
19
|
+
delegate(:reference_no, to: :request, prefix: true, allow_nil: true)
|
20
|
+
|
17
21
|
def approve
|
18
22
|
raise(StandardError, 'Dispatch plan already approved.') if status == APPROVED
|
19
23
|
|
@@ -1,16 +1,16 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class DispatchPlanItem < ApplicationRecord
|
4
|
-
belongs_to :commodity
|
5
4
|
belongs_to :source, class_name: 'Cats::Core::Location'
|
6
5
|
belongs_to :destination, class_name: 'Cats::Core::Location'
|
7
6
|
belongs_to :dispatch_plan
|
8
7
|
has_many :dispatches
|
9
8
|
|
9
|
+
validates :commodity_status, presence: true, inclusion: { in: Cats::Core::Commodity::COMMODITY_STATUSES }
|
10
10
|
validates :quantity, presence: true, numericality: { greater_than: 0 }
|
11
11
|
|
12
12
|
delegate(:reference_no, to: :dispatch_plan, prefix: :plan, allow_nil: true)
|
13
|
-
delegate(:
|
13
|
+
delegate(:commodity_batch_no, :commodity_name, to: :dispatch_plan)
|
14
14
|
delegate(:name, to: :source, prefix: true)
|
15
15
|
delegate(:name, to: :destination, prefix: true)
|
16
16
|
delegate(:location_type, to: :source, prefix: true)
|
@@ -9,11 +9,13 @@ module Cats
|
|
9
9
|
|
10
10
|
BELG = 'Belg'.freeze
|
11
11
|
MEHER = 'Meher'.freeze
|
12
|
-
|
12
|
+
ANNUAL = 'Annual'.freeze
|
13
|
+
SEASONS = [BELG, MEHER, ANNUAL].freeze
|
13
14
|
|
14
15
|
belongs_to :program
|
15
16
|
belongs_to :ration, optional: true
|
16
17
|
has_many :plan_items
|
18
|
+
has_many :plan_item_details, through: :plan_items
|
17
19
|
|
18
20
|
validates :reference_no, :year, :status, presence: true
|
19
21
|
validates :season, presence: true, inclusion: { in: SEASONS }
|
@@ -3,7 +3,8 @@ module Cats
|
|
3
3
|
class RhnRequest < ApplicationRecord
|
4
4
|
DRAFT = 'Draft'.freeze
|
5
5
|
APPROVED = 'Approved'.freeze
|
6
|
-
|
6
|
+
ALLOCATED = 'Allocated'.freeze
|
7
|
+
STATUSES = [DRAFT, APPROVED, ALLOCATED].freeze
|
7
8
|
|
8
9
|
belongs_to :commodity
|
9
10
|
|
@@ -35,6 +36,11 @@ module Cats
|
|
35
36
|
self.status = APPROVED
|
36
37
|
save!
|
37
38
|
end
|
39
|
+
|
40
|
+
def allocate
|
41
|
+
self.status = ALLOCATED
|
42
|
+
save!
|
43
|
+
end
|
38
44
|
end
|
39
45
|
end
|
40
46
|
end
|
@@ -7,7 +7,7 @@ module Cats
|
|
7
7
|
|
8
8
|
def message
|
9
9
|
dispatch = params[:dispatch]
|
10
|
-
commodity = dispatch.dispatch_plan_item.commodity
|
10
|
+
commodity = dispatch.dispatch_plan_item.dispatch_plan.commodity
|
11
11
|
title = "Dispatch Notification - #{commodity.name}"
|
12
12
|
date = Date.today
|
13
13
|
body = <<~BODY
|
@@ -2,7 +2,7 @@ module Cats
|
|
2
2
|
module Core
|
3
3
|
class DispatchPlanItemSerializer < ActiveModel::Serializer
|
4
4
|
attributes :id, :dispatch_plan_id, :plan_reference_no, :source_id, :source_name, :destination_id,
|
5
|
-
:destination_name, :quantity, :source_location_type, :destination_location_type
|
5
|
+
:destination_name, :quantity, :source_location_type, :destination_location_type, :commodity_status
|
6
6
|
end
|
7
7
|
end
|
8
8
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class DispatchPlanSerializer < ActiveModel::Serializer
|
4
|
-
attributes :id, :reference_no, :status, :request_id, :
|
4
|
+
attributes :id, :reference_no, :status, :request_id, :commodity_id, :commodity_name, :commodity_batch_no,
|
5
|
+
:commodity_quantity, :request_reference_no, :upstream
|
5
6
|
end
|
6
7
|
end
|
7
8
|
end
|
@@ -1,7 +1,27 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module Cats
|
2
|
+
module Core
|
3
|
+
class DispatchPlanService
|
4
|
+
def approve(plan)
|
5
|
+
plan.approve
|
6
|
+
plan.request.allocate if plan.request_id
|
7
|
+
# send_notification(plan)
|
8
|
+
plan
|
9
|
+
end
|
10
|
+
|
11
|
+
def create(params, user)
|
12
|
+
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
|
+
plan.prepared_by = user
|
21
|
+
result = plan.save
|
22
|
+
|
23
|
+
[result, plan]
|
24
|
+
end
|
25
|
+
end
|
6
26
|
end
|
7
27
|
end
|
@@ -10,7 +10,7 @@ module Cats
|
|
10
10
|
store = Cats::Core::Store.find_by(code: 'SUP-STORE')
|
11
11
|
raise(StandardError, 'Supplier store does not exist.') unless store
|
12
12
|
|
13
|
-
commodity = plan_item.commodity
|
13
|
+
commodity = plan_item.dispatch_plan.commodity
|
14
14
|
stack = store.stacks.find_by(commodity: commodity)
|
15
15
|
|
16
16
|
raise(StandardError, 'Commodity not found in supplier store.') unless stack
|
@@ -6,6 +6,10 @@ class CreateCatsCoreDispatchPlans < ActiveRecord::Migration[6.1]
|
|
6
6
|
t.string :status, null: false, default: 'Draft'
|
7
7
|
t.references :request, polymorphic: true
|
8
8
|
t.boolean :upstream, null: false, default: false
|
9
|
+
t.references :commodity,
|
10
|
+
null: false,
|
11
|
+
index: { name: 'commodity_on_dp_indx' },
|
12
|
+
foreign_key: { to_table: :cats_core_commodities }
|
9
13
|
|
10
14
|
t.references :prepared_by,
|
11
15
|
null: false,
|
@@ -5,10 +5,6 @@ class CreateCatsCoreDispatchPlanItems < ActiveRecord::Migration[6.1]
|
|
5
5
|
null: false,
|
6
6
|
index: { name: 'dpi_on_dp_indx' },
|
7
7
|
foreign_key: { to_table: :cats_core_dispatch_plans }
|
8
|
-
t.references :commodity,
|
9
|
-
null: false,
|
10
|
-
index: { name: 'dpi_on_commodity_indx' },
|
11
|
-
foreign_key: { to_table: :cats_core_commodities }
|
12
8
|
t.references :source,
|
13
9
|
null: false,
|
14
10
|
index: { name: 'dpi_on_source_indx' },
|
@@ -18,6 +14,7 @@ class CreateCatsCoreDispatchPlanItems < ActiveRecord::Migration[6.1]
|
|
18
14
|
index: { name: 'dpi_on_destination_indx'},
|
19
15
|
foreign_key: { to_table: :cats_core_locations }
|
20
16
|
t.float :quantity, null: false
|
17
|
+
t.string :commodity_status, null: false, default: 'Good'
|
21
18
|
|
22
19
|
t.timestamps
|
23
20
|
end
|
File without changes
|
@@ -5,10 +5,10 @@ class CreateCatsCoreMonthlyPlanItemDetails < ActiveRecord::Migration[6.1]
|
|
5
5
|
null: false,
|
6
6
|
index: { name: 'mpi_on_mpid_indx' },
|
7
7
|
foreign_key: { to_table: :cats_core_monthly_plan_items }
|
8
|
-
t.references :
|
8
|
+
t.references :monthly_ration,
|
9
9
|
null: false,
|
10
|
-
index: { name: '
|
11
|
-
foreign_key: { to_table: :
|
10
|
+
index: { name: 'ri_on_mr_indx' },
|
11
|
+
foreign_key: { to_table: :cats_core_monthly_rations }
|
12
12
|
t.float :amount, null: false
|
13
13
|
|
14
14
|
t.timestamps
|
data/lib/cats/core/version.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
FactoryBot.define do
|
2
2
|
factory :dispatch_plan_item, class: 'Cats::Core::DispatchPlanItem' do
|
3
|
-
commodity
|
4
3
|
source factory: :location
|
5
4
|
destination factory: :location
|
6
5
|
dispatch_plan
|
7
6
|
quantity { 100 }
|
7
|
+
commodity_status { Cats::Core::Commodity::GOOD }
|
8
8
|
end
|
9
9
|
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.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henock L.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-01-
|
11
|
+
date: 2022-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_model_serializers
|
@@ -385,9 +385,9 @@ files:
|
|
385
385
|
- db/migrate/20211229160129_create_cats_core_commodity_substitutions.rb
|
386
386
|
- db/migrate/20220103152802_create_cats_core_tenderers.rb
|
387
387
|
- db/migrate/20220107121752_create_cats_core_monthly_plans.rb
|
388
|
+
- db/migrate/20220107124630_create_cats_core_monthly_rations.rb
|
388
389
|
- db/migrate/20220107125025_create_cats_core_monthly_plan_items.rb
|
389
390
|
- db/migrate/20220107132433_create_cats_core_monthly_plan_item_details.rb
|
390
|
-
- db/migrate/20220107224630_create_cats_core_monthly_rations.rb
|
391
391
|
- lib/cats/core.rb
|
392
392
|
- lib/cats/core/engine.rb
|
393
393
|
- lib/cats/core/version.rb
|