cats_core 1.3.14 → 1.3.16
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 +2 -1
- data/app/controllers/cats/core/dispatch_plans_controller.rb +9 -6
- data/app/models/cats/core/dispatch_plan.rb +6 -0
- data/app/models/cats/core/dispatch_plan_item.rb +1 -0
- data/app/models/cats/core/rhn_request.rb +7 -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/db/migrate/20210718043328_create_cats_core_dispatch_plans.rb +4 -0
- data/db/migrate/20210718043401_create_cats_core_dispatch_plan_items.rb +1 -0
- data/lib/cats/core/version.rb +1 -1
- data/spec/factories/cats/core/dispatch_plan_items.rb +1 -0
- data/spec/factories/cats/core/dispatch_plans.rb +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ad7f2aaa0c106926140445109463f49c20ef3c4d7336de19a4f99abe4152b48
|
4
|
+
data.tar.gz: ffb46327fe5ab23994d9ada4ab2d8cbdcfba90f7f44436a8f95b87bb8e9fc21d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7ec684441796002b858da2a27ae38eecc14dea715682ea44f361434af24324236ddcd1ecd178dca5b9f44e99442341b6a667e43a0de9afafe12f37b21619628
|
7
|
+
data.tar.gz: 8887e74996a6a483da128576e049b630d20c0deb097d6e309a96be5421e11794b4e2033b8a25ee26f08fcb8de40e0a9e592336f4b97b79a1e71461364c0215bd
|
@@ -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,8 @@ 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, :commodity_id
|
14
|
+
params.require(:payload).permit(:dispatch_plan_id, :source_id, :destination_id, :quantity, :commodity_id,
|
15
|
+
:commodity_status)
|
15
16
|
end
|
16
17
|
end
|
17
18
|
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,18 @@ 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, to: :commodity, prefix: true)
|
19
|
+
delegate(:name, to: :commodity, prefix: true)
|
20
|
+
delegate(:quantity, to: :commodity, prefix: true)
|
21
|
+
delegate(:reference_no, to: :request, prefix: true, allow_nil: true)
|
22
|
+
|
17
23
|
def approve
|
18
24
|
raise(StandardError, 'Dispatch plan already approved.') if status == APPROVED
|
19
25
|
|
@@ -7,6 +7,7 @@ module Cats
|
|
7
7
|
belongs_to :dispatch_plan
|
8
8
|
has_many :dispatches
|
9
9
|
|
10
|
+
validates :commodity_status, presence: true, inclusion: { in: Cats::Core::Commodity::COMMODITY_STATUSES }
|
10
11
|
validates :quantity, presence: true, numericality: { greater_than: 0 }
|
11
12
|
|
12
13
|
delegate(:reference_no, to: :dispatch_plan, prefix: :plan, allow_nil: true)
|
@@ -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
|
@@ -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
|
+
send_notification(plan)
|
7
|
+
plan
|
8
|
+
end
|
9
|
+
|
10
|
+
def create(params, user)
|
11
|
+
plan = Cats::Core::DispatchPlan.new(params)
|
12
|
+
raise 'Commodity is not assigned for plan.' unless plan.commodity_id || plan.request_id
|
13
|
+
|
14
|
+
unless plan.commodity_id
|
15
|
+
request = Cats::Core::RhnRequest.find(plan.request_id)
|
16
|
+
plan.commodity_id = request.commodity_id
|
17
|
+
plan.request_type = 'Cats::Core::RhnRequest'
|
18
|
+
end
|
19
|
+
plan.prepared_by = user
|
20
|
+
result = plan.save
|
21
|
+
plan.request.allocate if result && plan.request_id
|
22
|
+
|
23
|
+
[result, plan]
|
24
|
+
end
|
25
|
+
end
|
6
26
|
end
|
7
27
|
end
|
@@ -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,
|
@@ -18,6 +18,7 @@ class CreateCatsCoreDispatchPlanItems < ActiveRecord::Migration[6.1]
|
|
18
18
|
index: { name: 'dpi_on_destination_indx'},
|
19
19
|
foreign_key: { to_table: :cats_core_locations }
|
20
20
|
t.float :quantity, null: false
|
21
|
+
t.string :commodity_status, null: false, default: 'Good'
|
21
22
|
|
22
23
|
t.timestamps
|
23
24
|
end
|
data/lib/cats/core/version.rb
CHANGED