cats_core 1.0.31 → 1.0.35
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/spaces_controller.rb +11 -0
- data/app/controllers/cats/core/unit_of_measures_controller.rb +49 -0
- data/app/models/cats/core/allocation.rb +1 -0
- data/app/models/cats/core/allocation_item.rb +1 -0
- data/app/models/cats/core/stack.rb +17 -0
- data/app/models/cats/core/store.rb +7 -0
- data/app/serializers/cats/core/unit_of_measure_serializer.rb +3 -0
- data/app/services/cats/core/space_service.rb +40 -0
- data/config/routes.rb +15 -0
- data/db/migrate/20210717140855_create_cats_core_stores.rb +2 -0
- data/lib/cats/core/version.rb +1 -1
- data/spec/factories/cats/core/locations.rb +5 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b2945064c03295f5dcd5971f0e6ce570b50e4616166030f17fa5a6bd869d5cd
|
4
|
+
data.tar.gz: 3a6e091d8830f0d30ef67285547b64e2fa327e3efbbaad99449daf4cce0c67fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58327459e7bbf5c43a08787c53d7ad8b9e08a7b8b6453e1ed06493e173a45cac45d82f0cdf3ddfbd5b6c106df31932e0ac637a0a3dd35a2d9493dc56ee1ad37a
|
7
|
+
data.tar.gz: 3065d7e0fceee9696d93851cb6c35be27fef7e3fd0779e783a490f8fe548eed6dc96348fe1be64be7f318fb845417ad0bbc23f1d0551cdcb4e56a1d669b3bc8a
|
@@ -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
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Cats
|
2
|
+
module Core
|
3
|
+
class UnitOfMeasuresController < ApplicationController
|
4
|
+
before_action :set_unit_of_measure, only: %i[show update]
|
5
|
+
|
6
|
+
def index
|
7
|
+
data = ActiveModelSerializers::SerializableResource.new(Cats::Core::UnitOfMeasure.all)
|
8
|
+
render json: { success: true, data: data }
|
9
|
+
end
|
10
|
+
|
11
|
+
def show
|
12
|
+
data = ActiveModelSerializers::SerializableResource.new(@unit_of_measure)
|
13
|
+
render json: { success: true, data: data }
|
14
|
+
end
|
15
|
+
|
16
|
+
def create
|
17
|
+
obj = Cats::Core::UnitOfMeasure.new(model_params)
|
18
|
+
if obj.save
|
19
|
+
data = ActiveModelSerializers::SerializableResource.new(obj)
|
20
|
+
render json: { success: true, data: data }, status: :created
|
21
|
+
else
|
22
|
+
render json: { success: false, error: obj.errors.full_messages[0] }, status: :unprocessable_entity
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def update
|
27
|
+
if @unit_of_measure.update(model_params)
|
28
|
+
data = ActiveModelSerializers::SerializableResource.new(@unit_of_measure)
|
29
|
+
render json: { success: true, data: data }
|
30
|
+
else
|
31
|
+
render json: {
|
32
|
+
success: false,
|
33
|
+
error: @unit_of_measure.errors.full_messages[0]
|
34
|
+
}, status: :unprocessable_entity
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def set_unit_of_measure
|
41
|
+
@unit_of_measure = Cats::Core::UnitOfMeasure.find(params[:id])
|
42
|
+
end
|
43
|
+
|
44
|
+
def model_params
|
45
|
+
params.require(:payload).permit(:abbreviation, :name, :unit_type)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
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
|
@@ -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,10 +28,25 @@ 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'
|
34
48
|
end
|
35
49
|
end
|
36
50
|
resources :currencies, except: %i[destroy]
|
51
|
+
resources :unit_of_measures, except: %i[destroy]
|
37
52
|
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
|
data/lib/cats/core/version.rb
CHANGED
@@ -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
|
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.
|
4
|
+
version: 1.0.35
|
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-
|
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,8 @@ 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
|
228
|
+
- app/controllers/cats/core/unit_of_measures_controller.rb
|
227
229
|
- app/controllers/cats/core/users_controller.rb
|
228
230
|
- app/jobs/cats/core/application_job.rb
|
229
231
|
- app/models/cats/core/allocation.rb
|
@@ -267,8 +269,10 @@ files:
|
|
267
269
|
- app/serializers/cats/core/currency_serializer.rb
|
268
270
|
- app/serializers/cats/core/location_serializer.rb
|
269
271
|
- app/serializers/cats/core/role_menu_serializer.rb
|
272
|
+
- app/serializers/cats/core/unit_of_measure_serializer.rb
|
270
273
|
- app/services/cats/core/menu_service.rb
|
271
274
|
- app/services/cats/core/notification_service.rb
|
275
|
+
- app/services/cats/core/space_service.rb
|
272
276
|
- app/services/cats/core/token_auth_service.rb
|
273
277
|
- config/routes.rb
|
274
278
|
- db/migrate/20210715114238_create_cats_core_application_modules.rb
|