cats_core 1.4.16 → 1.4.19
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/routes_controller.rb +23 -0
- data/app/models/cats/core/beneficiary.rb +2 -0
- data/app/models/cats/core/beneficiary_category.rb +2 -0
- data/app/models/cats/core/beneficiary_plan_item.rb +2 -0
- data/app/models/cats/core/transport_order.rb +25 -1
- data/app/models/cats/core/transport_requisition.rb +2 -1
- data/app/models/cats/core/transport_requisition_item.rb +5 -0
- data/config/routes.rb +1 -0
- data/lib/cats/core/version.rb +1 -1
- data/spec/factories/cats/core/routes.rb +1 -0
- data/spec/factories/cats/core/transport_requisitions.rb +2 -1
- 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: 4f2cc951417c8b5c1586ad4deb540c51e54177eac53c54a689f31c35bfbfbb67
|
4
|
+
data.tar.gz: f25cbb325f2eb8b8c9081ec0660b3c3028fe45ee0b7f003c40e96c91cdfebd15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 610169114a8fd878d1fd47b771f55a5bfef3e79c3d660b8148642a8fd9def6e018f4cea2b6cda50ee381970f2bee3e9e98ff5d5f0a3f66436d340b8334e4bf75
|
7
|
+
data.tar.gz: b0d90834aba82fd86dfb53bd6b51a875ff1131c4a3096813d6132efc860915e89ea4dd63c7272518158af8c0d21b355557e055b86d08938e82f063ce743a8f0a
|
@@ -8,11 +8,34 @@ module Cats
|
|
8
8
|
render json: { success: true, data: serialize(query.result) }
|
9
9
|
end
|
10
10
|
|
11
|
+
def bulk_create
|
12
|
+
p = bulk_create_params
|
13
|
+
source = Location.find(p[:source_id])
|
14
|
+
destinations = Location.where(id: p[:destination_ids]).pluck(:id, :name)
|
15
|
+
data = p[:destination_ids].each_with_object([]) do |id, res|
|
16
|
+
destination_name = destinations.find { |d| d[0] == id }[1]
|
17
|
+
res << {
|
18
|
+
region_id: p[:region_id],
|
19
|
+
source_id: p[:source_id],
|
20
|
+
destination_id: id,
|
21
|
+
name: "#{source.name} - #{destination_name}"
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
result = Route.insert_all!(data, record_timestamps: true)
|
26
|
+
routes = Route.where(id: result.rows.flatten)
|
27
|
+
render json: { success: true, data: serialize(routes) }
|
28
|
+
end
|
29
|
+
|
11
30
|
private
|
12
31
|
|
13
32
|
def model_params
|
14
33
|
params.require(:payload).permit(:region_id, :source_id, :destination_id)
|
15
34
|
end
|
35
|
+
|
36
|
+
def bulk_create_params
|
37
|
+
params.require(:payload).permit(:region_id, :source_id, destination_ids: [])
|
38
|
+
end
|
16
39
|
end
|
17
40
|
end
|
18
41
|
end
|
@@ -10,6 +10,8 @@ module Cats
|
|
10
10
|
validates :full_name, :age, :gender, presence: true
|
11
11
|
validates :gender, inclusion: { in: GENDERS }
|
12
12
|
validates :age, numericality: { greater_than: 0, less_than: 100 }
|
13
|
+
|
14
|
+
delegate(:name, to: :beneficiary_category, prefix: true)
|
13
15
|
end
|
14
16
|
end
|
15
17
|
end
|
@@ -13,7 +13,7 @@ module Cats
|
|
13
13
|
|
14
14
|
validates :status, presence: true, inclusion: { in: STATUSES }
|
15
15
|
validates :order_date, presence: true
|
16
|
-
validate :validate_against_requisition
|
16
|
+
validate :validate_against_requisition, :validate_status
|
17
17
|
|
18
18
|
delegate(:full_name, to: :prepared_by, prefix: true)
|
19
19
|
delegate(:full_name, to: :approved_by, prefix: true, allow_nil: true)
|
@@ -26,6 +26,30 @@ module Cats
|
|
26
26
|
|
27
27
|
errors.add(:transport_requisition, 'is not approved.')
|
28
28
|
end
|
29
|
+
|
30
|
+
def validate_status
|
31
|
+
return unless status
|
32
|
+
|
33
|
+
return if status == DRAFT
|
34
|
+
|
35
|
+
return if transport_order_items.count.positive?
|
36
|
+
|
37
|
+
errors.add(:status, 'cannot be set to "APPROVED" because the order has no items.') if status == APPROVED
|
38
|
+
end
|
39
|
+
|
40
|
+
def approve(user)
|
41
|
+
raise(StandardError, 'Transport order is already approved.') if status == APPROVED
|
42
|
+
|
43
|
+
begin
|
44
|
+
self.status = APPROVED
|
45
|
+
self.approved_by = user
|
46
|
+
save!
|
47
|
+
self
|
48
|
+
rescue ActiveRecord::RecordInvalid => e
|
49
|
+
error = e.record.errors.full_messages_for(:status)[0]
|
50
|
+
raise(StandardError, error)
|
51
|
+
end
|
52
|
+
end
|
29
53
|
end
|
30
54
|
end
|
31
55
|
end
|
@@ -26,11 +26,12 @@ module Cats
|
|
26
26
|
quantities.sum
|
27
27
|
end
|
28
28
|
|
29
|
-
def approve
|
29
|
+
def approve(user)
|
30
30
|
raise(StandardError, 'Transport requisition is already approved.') if status == APPROVED
|
31
31
|
|
32
32
|
begin
|
33
33
|
self.status = APPROVED
|
34
|
+
self.approved_by = user
|
34
35
|
save!
|
35
36
|
self
|
36
37
|
rescue ActiveRecord::RecordInvalid => e
|
@@ -9,6 +9,7 @@ module Cats
|
|
9
9
|
|
10
10
|
delegate(:reference_no, to: :transport_requisition, prefix: 'requisition')
|
11
11
|
delegate(:abbreviation, to: :unit, prefix: true)
|
12
|
+
delegate(:source_name, to: :dispatch_plan_item, prefix: false)
|
12
13
|
|
13
14
|
def commodity_name
|
14
15
|
dispatch_plan_item.commodity.source.commodity_category.name
|
@@ -17,6 +18,10 @@ module Cats
|
|
17
18
|
def woreda
|
18
19
|
dispatch_plan_item.destination.name
|
19
20
|
end
|
21
|
+
|
22
|
+
def region
|
23
|
+
dispatch_plan_item.destination.root.name
|
24
|
+
end
|
20
25
|
end
|
21
26
|
end
|
22
27
|
end
|
data/config/routes.rb
CHANGED
@@ -80,6 +80,7 @@ Cats::Core::Engine.routes.draw do
|
|
80
80
|
resources :transporters, except: %i[destroy]
|
81
81
|
|
82
82
|
post '/routes/filter', controller: :routes, action: :filter
|
83
|
+
post '/routes/bulk_create', controller: :routes, action: :bulk_create
|
83
84
|
resources :routes, except: %i[destroy]
|
84
85
|
|
85
86
|
post '/dispatch_plans/filter', controller: :dispatch_plans, action: :filter
|
data/lib/cats/core/version.rb
CHANGED