cats_core 1.0.32 → 1.0.36

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: b481d401018e6fdfdf93be24ee465d117e45b4a888e4e4a0e079f3aa4654009a
4
- data.tar.gz: dae45a28258a5125762192e4bd2579ed2b5c486ea74271dac1437ee4bea5c2b1
3
+ metadata.gz: c909272a932180976b058fc2514d349d48677862c5bee425d97e1ebb1d92f30e
4
+ data.tar.gz: 57060b872361ba7f38b5bffe9522241ccb147bb3fac27b7e593288937a771672
5
5
  SHA512:
6
- metadata.gz: 2404e609083ccfe957927a8a7fbc9355eaa564f2aa2620af2eac779a10457b11661d1db34a8b6bdb27ad3b60ff2ba717dce8e35627688f2590bd2c292d17079f
7
- data.tar.gz: d2748d191c6ac70a5977acf13b3647a0387dcd80dfeaa4dfb03c88244a845b353aeffd25cd6856ba5d1a3c2934ed5a8a85b71ab82e2cdde2f1ddc56afd14ae66
6
+ metadata.gz: af510c6f846701bea55bd995f6ccf3d34500c11c8a23cdac2df2f89f258170c4f93fb31c9242eaf927ed3a24a5e499fdd2c995ca1d2c178d9e39c60364e6d072
7
+ data.tar.gz: 19dff931a8a64a71870263e2193709f541ea530110ac852ef0c751bca2e8739d996c8da2ad53c3465d720ad2167a34ead9c9cca36cd42956db7abecf6b1b37fa
@@ -0,0 +1,11 @@
1
+ module Cats
2
+ module Core
3
+ class SpacesController < ApplicationController
4
+ def available_space
5
+ service = SpaceService.new
6
+ space = service.available_space(params[:id], params[:level])
7
+ render json: { success: true, data: space }
8
+ end
9
+ end
10
+ end
11
+ end
@@ -13,6 +13,7 @@ module Cats
13
13
  delegate(:reference_no, to: :rhn_request, prefix: :rhn, allow_nil: true)
14
14
  delegate(:batch_no, to: :commodity, prefix: true)
15
15
  delegate(:name, to: :source, prefix: true)
16
+ delegate(:location_type, to: :source, prefix: true)
16
17
  end
17
18
  end
18
19
  end
@@ -16,6 +16,7 @@ module Cats
16
16
 
17
17
  delegate(:name, to: :destination, prefix: true)
18
18
  delegate(:reference_no, to: :allocation, prefix: true)
19
+ delegate(:location_type, to: :destination, prefix: true)
19
20
  end
20
21
  end
21
22
  end
@@ -2,11 +2,8 @@ module Cats
2
2
  module Core
3
3
  class Ration < ApplicationRecord
4
4
  belongs_to :program
5
- belongs_to :commodity_category
6
5
 
7
- validates :reference_no, :amount, presence: true
8
- validates :reference_no, uniqueness: true
9
- validates :amount, numericality: { greater_than: 0 }
6
+ validates :reference_no, presence: true, uniqueness: true
10
7
  end
11
8
  end
12
9
  end
@@ -0,0 +1,11 @@
1
+ module Cats
2
+ module Core
3
+ class RationItem < ApplicationRecord
4
+ belongs_to :commodity_category
5
+ belongs_to :ration
6
+ belongs_to :unit_of_measure
7
+
8
+ validates :amount, presence: true, numericality: { greater_than: 0 }
9
+ end
10
+ end
11
+ end
@@ -22,6 +22,8 @@ module Cats
22
22
  validate :validate_coordinates, :validate_dimensions, :validate_distance_from_wall, :validate_overlap,
23
23
  :validate_space_between_stack
24
24
 
25
+ after_save :update_store_space
26
+
25
27
  def validate_coordinates
26
28
  return unless store.present? && length.present? && width.present? && start_x.present? && start_y.present?
27
29
 
@@ -99,6 +101,21 @@ module Cats
99
101
 
100
102
  true
101
103
  end
104
+
105
+ def update_store_space
106
+ return unless length_previously_changed? || width_previously_changed? || stack_status_previously_changed?
107
+
108
+ old_area = if length_previously_was.nil? && width_previously_was.nil?
109
+ 0
110
+ else
111
+ length_previously_was * width_previously_was
112
+ end
113
+
114
+ store.available_space += old_area
115
+ store.available_space -= length * width unless stack_status == DESTROYED
116
+
117
+ store.save
118
+ end
102
119
  end
103
120
  end
104
121
  end
@@ -15,6 +15,7 @@ module Cats
15
15
  allow_nil: true
16
16
  validate :validate_location
17
17
 
18
+ before_create :update_usable_space
18
19
  after_save :update_store_keeper
19
20
 
20
21
  def validate_location
@@ -27,6 +28,12 @@ module Cats
27
28
  "#{store_keeper.first_name} #{store_keeper.last_name}"
28
29
  end
29
30
 
31
+ def update_usable_space
32
+ self.usable_space = (length - 2) * (width - 2)
33
+ self.usable_space -= (gangway_length * gangway_width) if has_gangway
34
+ self.available_space = self.usable_space
35
+ end
36
+
30
37
  def update_store_keeper
31
38
  return unless store_keeper_id_previously_changed?
32
39
 
@@ -0,0 +1,40 @@
1
+ module Cats
2
+ module Core
3
+ class SpaceService
4
+ HUB = 'Hub'.freeze
5
+ WAREHOUSE = 'Warehouse'.freeze
6
+ STORE = 'Store'.freeze
7
+
8
+ def available_space(id, level)
9
+ case level
10
+ when HUB
11
+ warehouse_ids = Cats::Core::Location.find(id).children.map(&:id)
12
+ stores = Cats::Core::Store.joins(:warehouse)
13
+ .where(
14
+ cats_core_locations: {
15
+ location_type: Cats::Core::Location::WAREHOUSE,
16
+ id: warehouse_ids
17
+ }
18
+ ).group_by(&:warehouse_id)
19
+ wh_details = []
20
+ stores.each do |key, value|
21
+ total_space = value.inject(0) { |sum, val| sum + val.available_space }
22
+ details = value.map { |val| { store_id: val.id, total_space: val.available_space } }
23
+ wh_details << { warehouse_id: key, total_space: total_space, details: details }
24
+ end
25
+ hub_space = wh_details.inject(0) { |sum, val| sum + val[:total_space] }
26
+ space = { hub_id: id, total_space: hub_space, details: wh_details }
27
+ when WAREHOUSE
28
+ stores = Cats::Core::Store.where(warehouse_id: id)
29
+ details = stores.map { |store| { store_id: store.id, total_space: store.available_space } }
30
+ total_space = stores.inject(0) { |sum, val| sum + val.available_space }
31
+ space = { warehouse_id: id, total_space: total_space, details: details }
32
+ when STORE
33
+ store = Cats::Core::Store.find(id)
34
+ space = { store_id: store.id, total_space: store.available_space }
35
+ end
36
+ space
37
+ end
38
+ end
39
+ end
40
+ end
data/config/routes.rb CHANGED
@@ -28,6 +28,20 @@ Cats::Core::Engine.routes.draw do
28
28
  get 'children'
29
29
  end
30
30
  end
31
+
32
+ get '/hubs/:id/space',
33
+ to: 'spaces#available_space',
34
+ as: :hub_space,
35
+ defaults: { level: Cats::Core::SpaceService::HUB }
36
+ get '/warehousess/:id/space',
37
+ to: 'spaces#available_space',
38
+ as: :warehouse_space,
39
+ defaults: { level: Cats::Core::SpaceService::WAREHOUSE }
40
+ get '/store/:id/space',
41
+ to: 'spaces#available_space',
42
+ as: :store_space,
43
+ defaults: { level: Cats::Core::SpaceService::STORE }
44
+
31
45
  resources :commodity_categories, except: %i[destroy] do
32
46
  member do
33
47
  get 'children'
@@ -6,11 +6,6 @@ class CreateCatsCoreRations < ActiveRecord::Migration[6.1]
6
6
  null: false,
7
7
  index: { name: 'program_on_ration_indx' },
8
8
  foreign_key: { to_table: :cats_core_programs }
9
- t.references :commodity_category,
10
- null: false,
11
- index: { name: 'cc_on_ration_indx' },
12
- foreign_key: { to_table: :cats_core_commodity_categories }
13
- t.float :amount, null: false
14
9
  t.boolean :current, null: false, default: true
15
10
 
16
11
  t.timestamps
@@ -0,0 +1,21 @@
1
+ class CreateCatsCoreRationItems < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :cats_core_ration_items do |t|
4
+ t.references :commodity_category,
5
+ null: false,
6
+ index: { name: 'cc_on_ration_indx' },
7
+ foreign_key: { to_table: :cats_core_commodity_categories }
8
+ t.references :ration,
9
+ null: false,
10
+ index: { name: 'ri_on_ration_indx' },
11
+ foreign_key: { to_table: :cats_core_rations }
12
+ t.references :unit_of_measure,
13
+ null: false,
14
+ index: { name: 'uom_on_ration_indx' },
15
+ foreign_key: { to_table: :cats_core_unit_of_measures }
16
+ t.float :amount, null: false
17
+
18
+ t.timestamps
19
+ end
20
+ end
21
+ end
@@ -5,6 +5,8 @@ class CreateCatsCoreStores < ActiveRecord::Migration[6.1]
5
5
  t.float :length, null: false
6
6
  t.float :width, null: false
7
7
  t.float :height, null: false
8
+ t.float :usable_space, null: false
9
+ t.float :available_space, null: false
8
10
  t.boolean :temporary, null: false, default: false
9
11
  t.boolean :has_gangway, null: false, default: false
10
12
  t.float :gangway_length
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.0.32'.freeze
3
+ VERSION = '1.0.36'.freeze
4
4
  end
5
5
  end
@@ -5,6 +5,11 @@ FactoryBot.define do
5
5
  ancestry { nil }
6
6
  end
7
7
 
8
+ factory :hub, parent: :location, class: 'Cats::Core::Location' do
9
+ location_type { Cats::Core::Location::HUB }
10
+ parent
11
+ end
12
+
8
13
  factory :warehouse, parent: :location, class: 'Cats::Core::Location' do
9
14
  location_type { Cats::Core::Location::WAREHOUSE }
10
15
  parent
@@ -0,0 +1,8 @@
1
+ FactoryBot.define do
2
+ factory :ration_item, class: 'Cats::Core::RationItem' do
3
+ commodity_category
4
+ ration
5
+ amount { 150 }
6
+ unit_of_measure
7
+ end
8
+ end
@@ -2,8 +2,6 @@ FactoryBot.define do
2
2
  factory :ration, class: 'Cats::Core::Ration' do
3
3
  reference_no { FFaker::Name.name }
4
4
  program
5
- commodity_category
6
- amount { 1.5 }
7
5
  current { false }
8
6
  end
9
7
  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.0.32
4
+ version: 1.0.36
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-09 00:00:00.000000000 Z
11
+ date: 2021-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers
@@ -224,6 +224,7 @@ files:
224
224
  - app/controllers/cats/core/menus_controller.rb
225
225
  - app/controllers/cats/core/notifications_controller.rb
226
226
  - app/controllers/cats/core/roles_controller.rb
227
+ - app/controllers/cats/core/spaces_controller.rb
227
228
  - app/controllers/cats/core/unit_of_measures_controller.rb
228
229
  - app/controllers/cats/core/users_controller.rb
229
230
  - app/jobs/cats/core/application_job.rb
@@ -249,6 +250,7 @@ files:
249
250
  - app/models/cats/core/program.rb
250
251
  - app/models/cats/core/purchase_order.rb
251
252
  - app/models/cats/core/ration.rb
253
+ - app/models/cats/core/ration_item.rb
252
254
  - app/models/cats/core/receipt.rb
253
255
  - app/models/cats/core/receipt_transaction.rb
254
256
  - app/models/cats/core/rhn_request.rb
@@ -271,6 +273,7 @@ files:
271
273
  - app/serializers/cats/core/unit_of_measure_serializer.rb
272
274
  - app/services/cats/core/menu_service.rb
273
275
  - app/services/cats/core/notification_service.rb
276
+ - app/services/cats/core/space_service.rb
274
277
  - app/services/cats/core/token_auth_service.rb
275
278
  - config/routes.rb
276
279
  - db/migrate/20210715114238_create_cats_core_application_modules.rb
@@ -288,6 +291,7 @@ files:
288
291
  - db/migrate/20210716210905_create_cats_core_suppliers.rb
289
292
  - db/migrate/20210717031108_create_cats_core_donors.rb
290
293
  - db/migrate/20210717031216_create_cats_core_rations.rb
294
+ - db/migrate/20210717031343_create_cats_core_ration_items.rb
291
295
  - db/migrate/20210717031810_create_cats_core_hrps.rb
292
296
  - db/migrate/20210717032024_create_cats_core_hrp_items.rb
293
297
  - db/migrate/20210717032330_create_cats_core_donations.rb
@@ -332,6 +336,7 @@ files:
332
336
  - spec/factories/cats/core/operators.rb
333
337
  - spec/factories/cats/core/programs.rb
334
338
  - spec/factories/cats/core/purchase_orders.rb
339
+ - spec/factories/cats/core/ration_items.rb
335
340
  - spec/factories/cats/core/rations.rb
336
341
  - spec/factories/cats/core/receipt_transactions.rb
337
342
  - spec/factories/cats/core/receipts.rb