cats_core 1.4.34 → 1.4.37
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/dispatch_plan_items_controller.rb +1 -1
- data/app/controllers/cats/core/locations_controller.rb +6 -0
- data/app/controllers/cats/core/round_plans_controller.rb +1 -1
- data/app/models/cats/core/commodity.rb +9 -1
- data/app/models/cats/core/dispatch_plan_item.rb +3 -0
- data/app/serializers/cats/core/dispatch_plan_item_serializer.rb +2 -1
- data/app/serializers/cats/core/dispatch_serializer.rb +1 -1
- data/app/services/cats/core/round_plan_service.rb +19 -6
- data/config/routes.rb +1 -0
- data/db/migrate/20210718043401_create_cats_core_dispatch_plan_items.rb +4 -0
- data/lib/cats/core/version.rb +1 -1
- data/spec/factories/cats/core/dispatch_plan_items.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f2ea0d3a39edea3ab29b38b312d3d2e31e16ba07d54c0f985f5ceb248869fef4
|
|
4
|
+
data.tar.gz: 02e0ba07bbc6bf360a637a215faa26de072c2fe3d955547b9ba68193eca1220e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9c2f4ba51cc505f5320d2dee177e5cfa1e42d72bc8bd0b69b3128141b568354220a3e4b9d681d9412aa740b2ceda1bdc1a118a774f6ff34b1e8656eaff9e08b8
|
|
7
|
+
data.tar.gz: c976d634759281fb71a769495282b74459ed8167eb8c61be21f8566213e7394ee6fd873ba0cc2e3905eb473a56fc8cbdbe427913d40b3e784ca33a9bbcb9296c
|
|
@@ -18,7 +18,7 @@ module Cats
|
|
|
18
18
|
|
|
19
19
|
def model_params
|
|
20
20
|
params.require(:payload).permit(:reference_no, :dispatch_plan_id, :source_id, :destination_id, :quantity,
|
|
21
|
-
:commodity_status, :status, :commodity_id)
|
|
21
|
+
:unit_id, :commodity_status, :status, :commodity_id)
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
end
|
|
@@ -19,6 +19,12 @@ module Cats
|
|
|
19
19
|
render json: { success: true, data: serialize(query.result) }
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
+
def woredas
|
|
23
|
+
region = Location.find(params[:id])
|
|
24
|
+
woredas = Location.where(id: region.descendant_ids, location_type: Location::WOREDA)
|
|
25
|
+
render json: { success: true, data: serialize(woredas) }
|
|
26
|
+
end
|
|
27
|
+
|
|
22
28
|
private
|
|
23
29
|
|
|
24
30
|
def model_params
|
|
@@ -37,7 +37,7 @@ module Cats
|
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
def remove_items
|
|
40
|
-
plan = @service.remove_items(params[:id], remove_params)
|
|
40
|
+
plan = @service.remove_items(params[:id], remove_params[:ids])
|
|
41
41
|
render json: { success: true, data: serialize(plan) }
|
|
42
42
|
rescue StandardError => e
|
|
43
43
|
render json: { success: false, error: e.message }
|
|
@@ -16,7 +16,15 @@ module Cats
|
|
|
16
16
|
# Commodity statuses
|
|
17
17
|
GOOD = 'Good'.freeze
|
|
18
18
|
DAMAGED = 'Damaged'.freeze
|
|
19
|
-
|
|
19
|
+
LEAKAGE = 'Leakage'.freeze
|
|
20
|
+
WET = 'Wet'.freeze
|
|
21
|
+
MOLDY = 'Moldy'.freeze
|
|
22
|
+
INFESTED = 'Infested'.freeze
|
|
23
|
+
INSECT_INFECTED = 'Insect Infected'.freeze
|
|
24
|
+
FAECES_FROM_RODENTS = 'Faeces From Rodents'.freeze
|
|
25
|
+
UNDERWEIGHT_PACKAGE = 'Underweight Package'.freeze
|
|
26
|
+
COMMODITY_STATUSES = [GOOD, DAMAGED, LEAKAGE, WET, MOLDY, INFESTED, INSECT_INFECTED, FAECES_FROM_RODENTS,
|
|
27
|
+
UNDERWEIGHT_PACKAGE].freeze
|
|
20
28
|
|
|
21
29
|
# Arrival Statuses
|
|
22
30
|
AT_SOURCE = 'At Source'.freeze
|
|
@@ -11,6 +11,7 @@ module Cats
|
|
|
11
11
|
belongs_to :destination, class_name: 'Cats::Core::Location'
|
|
12
12
|
belongs_to :dispatch_plan
|
|
13
13
|
belongs_to :commodity
|
|
14
|
+
belongs_to :unit, class_name: 'Cats::Core::UnitOfMeasure'
|
|
14
15
|
|
|
15
16
|
has_many :dispatches
|
|
16
17
|
has_many :hub_authorizations
|
|
@@ -26,6 +27,8 @@ module Cats
|
|
|
26
27
|
delegate(:name, to: :destination, prefix: true)
|
|
27
28
|
delegate(:location_type, to: :source, prefix: true)
|
|
28
29
|
delegate(:location_type, to: :destination, prefix: true)
|
|
30
|
+
delegate(:abbreviation, to: :unit, prefix: true)
|
|
31
|
+
delegate(:shipping_reference, to: :commodity, prefix: true)
|
|
29
32
|
|
|
30
33
|
# Authorize a dispatch plan item if it contains authorization entries
|
|
31
34
|
# under it. A dispatch plan item can be authorized by source hub, or
|
|
@@ -3,7 +3,8 @@ module Cats
|
|
|
3
3
|
class DispatchPlanItemSerializer < ActiveModel::Serializer
|
|
4
4
|
attributes :id, :reference_no, :dispatch_plan_id, :plan_reference_no, :source_id, :source_name, :destination_id,
|
|
5
5
|
:destination_name, :quantity, :source_location_type, :destination_location_type, :commodity_status,
|
|
6
|
-
:status, :commodity_id, :commodity_name, :commodity_batch_no
|
|
6
|
+
:status, :commodity_id, :commodity_name, :commodity_batch_no, :unit_abbreviation,
|
|
7
|
+
:commodity_shipping_reference
|
|
7
8
|
end
|
|
8
9
|
end
|
|
9
10
|
end
|
|
@@ -3,7 +3,7 @@ module Cats
|
|
|
3
3
|
class DispatchSerializer < ActiveModel::Serializer
|
|
4
4
|
attributes :id, :reference_no, :dispatch_plan_item_id, :transporter_id, :transporter_name, :plate_no,
|
|
5
5
|
:driver_name, :driver_phone, :quantity, :remark, :prepared_by_id, :prepared_by_email,
|
|
6
|
-
:dispatch_status, :destination, :auth_details
|
|
6
|
+
:dispatch_status, :destination, :auth_details, :unit_id, :commodity_status
|
|
7
7
|
|
|
8
8
|
def destination
|
|
9
9
|
object.dispatch_plan_item.destination.name
|
|
@@ -7,7 +7,7 @@ module Cats
|
|
|
7
7
|
|
|
8
8
|
raise(StandardError, 'Plan has no plan items.') if round_plan.round_plan_items.count.zero?
|
|
9
9
|
|
|
10
|
-
round_plan.
|
|
10
|
+
clear_needs(round_plan.id)
|
|
11
11
|
|
|
12
12
|
details = []
|
|
13
13
|
rations = round_plan.round_rations
|
|
@@ -32,6 +32,13 @@ module Cats
|
|
|
32
32
|
round_plan
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
+
def clear_needs(plan_id)
|
|
36
|
+
Cats::Core::RoundPlanItemDetail
|
|
37
|
+
.joins(beneficiary_round_plan_item: :round_plan_item)
|
|
38
|
+
.where(cats_core_beneficiary_round_plan_items: { cats_core_round_plan_items: { round_plan_id: plan_id } })
|
|
39
|
+
.delete_all
|
|
40
|
+
end
|
|
41
|
+
|
|
35
42
|
def generate_round_plan(reference_no, rounds, plan_id, region_id)
|
|
36
43
|
round_plan = Cats::Core::RoundPlan.create!(
|
|
37
44
|
plan_id: plan_id,
|
|
@@ -108,7 +115,7 @@ module Cats
|
|
|
108
115
|
.where(beneficiary_round_plan_items: { id: ids })
|
|
109
116
|
raise(StandardError, 'Round plan items should be from the same plan.') if plans.count > 1
|
|
110
117
|
|
|
111
|
-
unless plans.count.positive? &&
|
|
118
|
+
unless plans.count.positive? && plan.id == plans[0].id
|
|
112
119
|
raise(StandardError, 'Round plan items are not from the given round plan.')
|
|
113
120
|
end
|
|
114
121
|
|
|
@@ -139,10 +146,16 @@ module Cats
|
|
|
139
146
|
if plan.plan.program.code == 'PSNP'
|
|
140
147
|
rounds = plan.rounds.count
|
|
141
148
|
item_ids = plan.beneficiary_round_plan_items.pluck('beneficiary_plan_item_id').flatten
|
|
142
|
-
plan_items = BeneficiaryPlanItem.where(id: item_ids)
|
|
143
|
-
invalid = plan_items.select { |pi| pi.rounds - (pi.rounds_served || 0) < rounds }
|
|
144
|
-
|
|
145
|
-
|
|
149
|
+
plan_items = BeneficiaryPlanItem.includes(plan_item: :fdp).where(id: item_ids)
|
|
150
|
+
invalid = plan_items.select { |pi| pi.rounds - (pi.rounds_served || 0) < rounds }.map do |pi|
|
|
151
|
+
pi.plan_item.fdp.name
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
if invalid.count.positive?
|
|
155
|
+
msg = invalid.join(', ')
|
|
156
|
+
error = "The FDPs [#{msg}] exceeded their allowed number of rounds."
|
|
157
|
+
raise(StandardError, error)
|
|
158
|
+
end
|
|
146
159
|
|
|
147
160
|
items = plan_items.each_with_object([]) do |plan_item, res|
|
|
148
161
|
rounds_served = plan_item.rounds_served || 0
|
data/config/routes.rb
CHANGED
|
@@ -39,6 +39,7 @@ Cats::Core::Engine.routes.draw do
|
|
|
39
39
|
end
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
+
get '/regions/:id/woredas', controller: :locations, action: :woredas, as: :region_woredas
|
|
42
43
|
post '/locations/filter', controller: :locations, action: :filter
|
|
43
44
|
resources :locations, except: %i[destroy] do
|
|
44
45
|
member do
|
|
@@ -19,6 +19,10 @@ class CreateCatsCoreDispatchPlanItems < ActiveRecord::Migration[6.1]
|
|
|
19
19
|
index: { name: 'commodity_on_dpi_indx' },
|
|
20
20
|
foreign_key: { to_table: :cats_core_commodities }
|
|
21
21
|
t.float :quantity, null: false
|
|
22
|
+
t.references :unit,
|
|
23
|
+
null: false,
|
|
24
|
+
index: { name: 'unit_on_dpi_indx' },
|
|
25
|
+
foreign_key: { to_table: :cats_core_unit_of_measures }
|
|
22
26
|
t.string :commodity_status, null: false, default: 'Good'
|
|
23
27
|
t.string :status, null: false, default: 'Unauthorized'
|
|
24
28
|
|
data/lib/cats/core/version.rb
CHANGED
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.4.
|
|
4
|
+
version: 1.4.37
|
|
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-06-
|
|
11
|
+
date: 2022-06-07 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: active_model_serializers
|