cats_core 1.4.31 → 1.4.34
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/commodities_controller.rb +1 -1
- data/app/controllers/cats/core/receipts_controller.rb +2 -1
- data/app/controllers/cats/core/stores_controller.rb +32 -0
- data/app/models/cats/core/commodity.rb +7 -0
- data/app/models/cats/core/plan.rb +2 -0
- data/app/models/cats/core/receipt.rb +1 -0
- data/app/models/cats/core/round_plan.rb +1 -0
- data/app/serializers/cats/core/commodity_serializer.rb +1 -1
- data/app/serializers/cats/core/receipt_authorization_serializer.rb +2 -1
- data/app/serializers/cats/core/receipt_serializer.rb +1 -1
- data/app/serializers/cats/core/round_plan_serializer.rb +2 -1
- data/app/serializers/cats/core/store_serializer.rb +11 -0
- data/app/services/cats/core/round_plan_service.rb +38 -9
- data/config/routes.rb +5 -0
- data/db/migrate/20210717033223_create_cats_core_commodities.rb +1 -0
- data/db/migrate/20210727105834_create_cats_core_receipts.rb +1 -0
- data/db/migrate/20220107125025_create_cats_core_round_plan_items.rb +1 -1
- data/lib/cats/core/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 451e4ed5c952d795035700cc1ac97bed84f711c284e15d510214df6a012df397
|
4
|
+
data.tar.gz: 7725d50aaa4dadfdb5aacf79e6bb733e156dbf78968ea61a4652481a1850fc5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d87b3ce53a8e899335e469edd698311bf9324c5ac5fda72b681d236a512882a16800b5092108627fc3ceb8ea9933b06f1b0ba2da8346fbf07dc29da8f5ea9a5
|
7
|
+
data.tar.gz: cec2931e3d2edb587e58b263bec7ba52f2ce31756f50cb0fe13d0c54be242024452c67d9c5a39185faa923df5db8fab0a6b9e13b7e6e4fd65cc186679e1be8d9
|
@@ -19,7 +19,7 @@ module Cats
|
|
19
19
|
private
|
20
20
|
|
21
21
|
def model_params
|
22
|
-
params.require(:payload).permit(:batch_no, :description, :unit_of_measure_id, :source_id,
|
22
|
+
params.require(:payload).permit(:batch_no, :description, :unit_of_measure_id, :source_id, :commodity_grade,
|
23
23
|
:source_type, :quantity, :best_use_before, :volume_per_metric_ton,
|
24
24
|
:arrival_status, :shipping_reference)
|
25
25
|
end
|
@@ -12,7 +12,8 @@ module Cats
|
|
12
12
|
private
|
13
13
|
|
14
14
|
def model_params
|
15
|
-
params.require(:payload).permit(:receipt_authorization_id, :commodity_status, :
|
15
|
+
params.require(:payload).permit(:receipt_authorization_id, :commodity_status, :commodity_grade, :quantity,
|
16
|
+
:remark)
|
16
17
|
end
|
17
18
|
end
|
18
19
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Cats
|
2
|
+
module Core
|
3
|
+
class StoresController < ApplicationController
|
4
|
+
include Common
|
5
|
+
|
6
|
+
def index
|
7
|
+
stores = Cats::Core::Store.where(warehouse_id: params[:id])
|
8
|
+
render json: { success: true, data: serialize(stores) }
|
9
|
+
end
|
10
|
+
|
11
|
+
def filter
|
12
|
+
query = Store.ransack(params[:q])
|
13
|
+
render json: { success: true, data: serialize(query.result) }
|
14
|
+
end
|
15
|
+
|
16
|
+
def stores_for_hub
|
17
|
+
warehouses = Cats::Core::Location.find(params[:id]).children
|
18
|
+
ids = warehouses.map(&:id)
|
19
|
+
stores = Cats::Core::Store.where(warehouse_id: ids)
|
20
|
+
render json: { success: true, data: serialize(stores) }
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def model_params
|
26
|
+
params.require('payload').permit(:id, :code, :name, :length, :width, :height, :temporary, :has_gangway,
|
27
|
+
:gangway_length, :gangway_width, :gangway_corner_dist, :warehouse_id,
|
28
|
+
:store_keeper_id)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -7,6 +7,12 @@ module Cats
|
|
7
7
|
ALLOCATED = 'Allocated'.freeze
|
8
8
|
STATUSES = [DRAFT, APPROVED, ALLOCATED].freeze
|
9
9
|
|
10
|
+
# Grades
|
11
|
+
GRADE1 = 'Grade1'.freeze
|
12
|
+
GRADE2 = 'Grade2'.freeze
|
13
|
+
GRADE3 = 'Grade3'.freeze
|
14
|
+
COMMODITY_GRADES = [GRADE1, GRADE2, GRADE3].freeze
|
15
|
+
|
10
16
|
# Commodity statuses
|
11
17
|
GOOD = 'Good'.freeze
|
12
18
|
DAMAGED = 'Damaged'.freeze
|
@@ -37,6 +43,7 @@ module Cats
|
|
37
43
|
validates :volume_per_metric_ton, numericality: { greater_than: 0, allow_nil: true }
|
38
44
|
validates :arrival_status, presence: true, inclusion: { in: ARRIVAL_STATUSES }
|
39
45
|
validates :status, presence: true, inclusion: { in: STATUSES }
|
46
|
+
validates :commodity_grade, inclusion: { in: COMMODITY_GRADES }, allow_nil: true
|
40
47
|
validate :validate_updateability, on: :update
|
41
48
|
|
42
49
|
delegate(:abbreviation, to: :unit_of_measure, prefix: 'unit')
|
@@ -20,6 +20,8 @@ module Cats
|
|
20
20
|
has_many :beneficiary_plan_items, through: :plan_items
|
21
21
|
has_many :plan_item_details, through: :beneficiary_plan_items
|
22
22
|
|
23
|
+
delegate(:code, to: :program, prefix: true)
|
24
|
+
|
23
25
|
validates :reference_no, :year, :status, presence: true
|
24
26
|
validates :total_days, :rounds, presence: true, numericality: { greater_than: 0 }
|
25
27
|
validates :season, presence: true, inclusion: { in: SEASONS }
|
@@ -4,6 +4,7 @@ module Cats
|
|
4
4
|
belongs_to :receipt_authorization
|
5
5
|
|
6
6
|
validates :commodity_status, presence: true, inclusion: { in: Commodity::COMMODITY_STATUSES }
|
7
|
+
validates :commodity_grade, inclusion: { in: Commodity::COMMODITY_GRADES }, allow_nil: true
|
7
8
|
validates :quantity, presence: true, numericality: { greater_than: 0 }
|
8
9
|
end
|
9
10
|
end
|
@@ -3,7 +3,7 @@ module Cats
|
|
3
3
|
class CommoditySerializer < ActiveModel::Serializer
|
4
4
|
attributes :id, :name, :batch_no, :description, :unit_of_measure_id, :unit_abbreviation, :source_id,
|
5
5
|
:source_type, :source_reference_no, :quantity, :best_use_before, :volume_per_metric_ton,
|
6
|
-
:arrival_status, :status, :shipping_reference
|
6
|
+
:arrival_status, :status, :shipping_reference, :commodity_grade
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
@@ -2,7 +2,8 @@ module Cats
|
|
2
2
|
module Core
|
3
3
|
class ReceiptAuthorizationSerializer < ActiveModel::Serializer
|
4
4
|
attributes :id, :dispatch_id, :dispatch_reference_no, :store_id, :store_name, :quantity, :received_quantity,
|
5
|
-
:remark, :status, :authorized_by_id, :authorizer_full_name, :auth_details
|
5
|
+
:remark, :status, :authorized_by_id, :authorizer_full_name, :auth_details, :plate_no, :driver_name,
|
6
|
+
:dispatch_status
|
6
7
|
end
|
7
8
|
end
|
8
9
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class ReceiptSerializer < ActiveModel::Serializer
|
4
|
-
attributes :id, :receipt_authorization_id, :commodity_status, :quantity, :remark
|
4
|
+
attributes :id, :receipt_authorization_id, :commodity_status, :commodity_grade, :quantity, :remark
|
5
5
|
end
|
6
6
|
end
|
7
7
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class RoundPlanSerializer < ActiveModel::Serializer
|
4
|
-
attributes :id, :reference_no, :status, :plan_id, :plan_reference_no, :region_id, :region_name, :rounds
|
4
|
+
attributes :id, :reference_no, :status, :plan_id, :plan_reference_no, :region_id, :region_name, :rounds,
|
5
|
+
:program_code
|
5
6
|
end
|
6
7
|
end
|
7
8
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Cats
|
2
|
+
module Core
|
3
|
+
class StoreSerializer < ActiveModel::Serializer
|
4
|
+
attributes :id, :code, :name, :store_keeper_name, :store_keeper_phone_number, :length, :width, :height,
|
5
|
+
:temporary, :has_gangway, :gangway_length, :gangway_width, :gangway_corner_dist, :warehouse_id,
|
6
|
+
:store_keeper_id
|
7
|
+
|
8
|
+
has_many :stacks
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -48,12 +48,10 @@ module Cats
|
|
48
48
|
quantity: ration.quantity,
|
49
49
|
unit_of_measure_id: ration.unit_of_measure_id,
|
50
50
|
round_plan_id: round_plan.id,
|
51
|
-
no_of_days: ration.no_of_days
|
52
|
-
created_at: Date.today,
|
53
|
-
updated_at: Date.today
|
51
|
+
no_of_days: ration.no_of_days
|
54
52
|
}
|
55
53
|
end
|
56
|
-
Cats::Core::RoundRation.insert_all!(round_rations)
|
54
|
+
Cats::Core::RoundRation.insert_all!(round_rations, record_timestamps: true)
|
57
55
|
plan_items = Cats::Core::PlanItem.where(plan_id: plan_id, region_id: region_id)
|
58
56
|
ben_plan_items = Cats::Core::BeneficiaryPlanItem.where(plan_item: plan_items)
|
59
57
|
round_plan_items = plan_items.map do |plan_item|
|
@@ -87,8 +85,18 @@ module Cats
|
|
87
85
|
round_plan
|
88
86
|
end
|
89
87
|
|
88
|
+
# This method deletes beneficiary round plan items based on the selection of the
|
89
|
+
# user in a given round.
|
90
|
+
#
|
91
|
+
# Params:
|
92
|
+
# plan_id => The id of the round plan.
|
93
|
+
# ids => A list of beneficiary round plan item ids to delete.
|
94
|
+
#
|
95
|
+
# When deleting the selected beneficiary round plan items, if the corresponding
|
96
|
+
# round plan item becomes empty, then it too should be deleted.
|
97
|
+
#
|
90
98
|
def remove_items(plan_id, ids)
|
91
|
-
raise(StandardError, 'No plan items specified.') if ids.count.zero?
|
99
|
+
raise(StandardError, 'No beneficiary plan items specified.') if ids.count.zero?
|
92
100
|
|
93
101
|
begin
|
94
102
|
plan = Cats::Core::RoundPlan.find(plan_id)
|
@@ -96,12 +104,33 @@ module Cats
|
|
96
104
|
raise(StandardError, 'Round plan not found.') unless plan
|
97
105
|
end
|
98
106
|
|
99
|
-
plans = Cats::Core::RoundPlan.includes(:
|
100
|
-
|
107
|
+
plans = Cats::Core::RoundPlan.includes(:beneficiary_round_plan_items)
|
108
|
+
.where(beneficiary_round_plan_items: { id: ids })
|
109
|
+
raise(StandardError, 'Round plan items should be from the same plan.') if plans.count > 1
|
101
110
|
|
102
|
-
|
111
|
+
unless plans.count.positive? && plan_id == plans[0].id
|
112
|
+
raise(StandardError, 'Round plan items are not from the given round plan.')
|
113
|
+
end
|
114
|
+
|
115
|
+
to_delete = Cats::Core::BeneficiaryRoundPlanItem.where(id: ids)
|
116
|
+
keys = to_delete.map(&:round_plan_item_id).uniq
|
117
|
+
|
118
|
+
item_counts = Cats::Core::BeneficiaryRoundPlanItem.where(round_plan_item_id: keys)
|
119
|
+
.group(:round_plan_item_id).count
|
120
|
+
|
121
|
+
delete_hash = {}
|
122
|
+
keys.each { |k| delete_hash[k] = [] }
|
123
|
+
to_delete.each { |td| delete_hash[td.round_plan_item_id] << td.id }
|
124
|
+
|
125
|
+
parent_ids = []
|
126
|
+
child_ids = []
|
127
|
+
delete_hash.each_key do |key|
|
128
|
+
child_ids += delete_hash[key]
|
129
|
+
parent_ids << key if delete_hash[key].count == item_counts[key]
|
130
|
+
end
|
103
131
|
|
104
|
-
Cats::Core::
|
132
|
+
Cats::Core::BeneficiaryRoundPlanItem.delete_by(id: child_ids) if child_ids.count.positive?
|
133
|
+
Cats::Core::RoundPlanItem.delete_by(id: parent_ids) if parent_ids.count.positive?
|
105
134
|
plan
|
106
135
|
end
|
107
136
|
|
data/config/routes.rb
CHANGED
@@ -169,4 +169,9 @@ Cats::Core::Engine.routes.draw do
|
|
169
169
|
get '/receipts/:id/stacks', controller: :stacks, action: :receipt_stacks, as: :receipt_stacks
|
170
170
|
get '/dispatches/:id/stacks', controller: :stacks, action: :dispatch_stacks, as: :dispatch_stacks
|
171
171
|
resources :stacks, only: %i[show index create update]
|
172
|
+
|
173
|
+
get '/warehouses/:id/stores', controller: :stores, action: :index, as: :stores_warehouse
|
174
|
+
get '/hubs/:id/stores', controller: :stores, action: :stores_for_hub, as: :stores_hub
|
175
|
+
resources :stores, only: %i[index show create update]
|
176
|
+
post '/stores/filter', controller: :stores, action: :filter
|
172
177
|
end
|
@@ -14,6 +14,7 @@ class CreateCatsCoreCommodities < ActiveRecord::Migration[6.1]
|
|
14
14
|
t.string :arrival_status, null: false, default: 'At Source'
|
15
15
|
t.boolean :approved, null: false, default: false
|
16
16
|
t.string :shipping_reference
|
17
|
+
t.string :commodity_grade
|
17
18
|
|
18
19
|
t.timestamps
|
19
20
|
end
|
@@ -6,6 +6,7 @@ class CreateCatsCoreReceipts < ActiveRecord::Migration[7.0]
|
|
6
6
|
index: { name: 'ra_on_receipts_indx' },
|
7
7
|
foreign_key: { to_table: :cats_core_receipt_authorizations }
|
8
8
|
t.string :commodity_status, null: false
|
9
|
+
t.string :commodity_grade
|
9
10
|
t.float :quantity, null: false
|
10
11
|
t.string :remark
|
11
12
|
|
@@ -4,7 +4,7 @@ class CreateCatsCoreRoundPlanItems < ActiveRecord::Migration[6.1]
|
|
4
4
|
t.references :round_plan,
|
5
5
|
null: false,
|
6
6
|
index: { name: 'mp_on_mpi_indx' },
|
7
|
-
foreign_key: { to_table: :cats_core_round_plans }
|
7
|
+
foreign_key: { to_table: :cats_core_round_plans, on_delete: :cascade }
|
8
8
|
t.references :region,
|
9
9
|
null: false,
|
10
10
|
index: { name: 'region_on_round_plan_items_indx' },
|
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.34
|
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-05
|
11
|
+
date: 2022-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_model_serializers
|
@@ -252,6 +252,7 @@ files:
|
|
252
252
|
- app/controllers/cats/core/routes_controller.rb
|
253
253
|
- app/controllers/cats/core/spaces_controller.rb
|
254
254
|
- app/controllers/cats/core/stacks_controller.rb
|
255
|
+
- app/controllers/cats/core/stores_controller.rb
|
255
256
|
- app/controllers/cats/core/transporters_controller.rb
|
256
257
|
- app/controllers/cats/core/unit_conversions_controller.rb
|
257
258
|
- app/controllers/cats/core/unit_of_measures_controller.rb
|
@@ -348,6 +349,7 @@ files:
|
|
348
349
|
- app/serializers/cats/core/round_plan_serializer.rb
|
349
350
|
- app/serializers/cats/core/route_serializer.rb
|
350
351
|
- app/serializers/cats/core/stack_serializer.rb
|
352
|
+
- app/serializers/cats/core/store_serializer.rb
|
351
353
|
- app/serializers/cats/core/transporter_serializer.rb
|
352
354
|
- app/serializers/cats/core/unit_conversion_serializer.rb
|
353
355
|
- app/serializers/cats/core/unit_of_measure_serializer.rb
|