cats_core 1.4.30 → 1.4.33

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4956ad89bea4861d95aaffc40534eab2b319009d2a10f2762e9b1ee6b68b60e
4
- data.tar.gz: 6d5aaf08e18bb95e8fd09c0957bbfeb982df76c1061f1b001028f1e91a1ac8ff
3
+ metadata.gz: e34b55e4d9cc5537027134594fd2f39946cd9b1001ab3a3d20c24109402a7797
4
+ data.tar.gz: 2437a6f18cab7ce976653738467dd0849182281f2fb1e5b2e832390538adf112
5
5
  SHA512:
6
- metadata.gz: 88a42101e62d3a13b23a905bcc06852115797cd3a0e160ae7204510777cb494b03f108500f7e0c5201439695ac084d737f903c619a4e1fc9d0e926ceec7aa396
7
- data.tar.gz: 7de9d35e696f2b2421cefa54da0e706b0826b3c63389eff498d4e0964f354cf61f7ae3eb4baba80f16b214b405615a2adcd3c2c19f1e97649a6fe4313c7b598f
6
+ metadata.gz: a574e2522a5d9c2ba8257ee18c5217023c23e7b6f5d69dddd9dc0d81f9169a697afc6fde167f4b41a36fd861f78abc7a3b3ad156859a1e49dc1bf412dab771e4
7
+ data.tar.gz: f1d30af5df117fb71047df56a7602024df16270e2531c94e65acf1f77e58fe56f3a895e64c14d6629ae88ce0b48f1a4aa3e3095c2bb5872cda31d44ad0c52a16
@@ -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,7 @@ module Cats
12
12
  private
13
13
 
14
14
  def model_params
15
- params.require(:payload).permit(:receipt_authorization_id, :commodity_status, :quantity, :remark)
15
+ params.require(:payload).permit(:receipt_authorization_id, :commodity_status, :commodity_grade, :quantity, :remark)
16
16
  end
17
17
  end
18
18
  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
@@ -26,6 +26,7 @@ module Cats
26
26
 
27
27
  delegate(:reference_no, to: :plan, prefix: true)
28
28
  delegate(:name, to: :region, prefix: true)
29
+ delegate(:program_code, to: :plan)
29
30
 
30
31
  def request_reference
31
32
  reference_no
@@ -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(:round_plan_items).where(round_plan_items: { id: ids })
100
- raise(StandardError, 'Plan items should be from the same plan.') if plans.count > 1
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
- raise(StandardError, 'Items are not from the given round plan.') unless plan_id == plans[0].id
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::RoundPlanItem.delete_by(id: ids)
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' },
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.4.30'.freeze
3
+ VERSION = '1.4.33'.freeze
4
4
  end
5
5
  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.4.30
4
+ version: 1.4.33
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-31 00:00:00.000000000 Z
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