cats_core 1.0.46 → 1.0.50
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/cats/core/allocation.rb +6 -1
- data/app/models/cats/core/dispatch.rb +15 -1
- data/app/models/cats/core/dispatch_transaction.rb +3 -0
- data/app/models/cats/core/store.rb +2 -1
- data/app/models/cats/core/transaction.rb +9 -0
- data/app/services/cats/core/space_service.rb +38 -7
- data/config/routes.rb +2 -2
- data/db/migrate/20210717140855_create_cats_core_stores.rb +1 -0
- data/db/migrate/20210718042823_create_cats_core_allocations.rb +1 -0
- data/lib/cats/core/version.rb +1 -1
- data/spec/factories/cats/core/allocations.rb +1 -0
- data/spec/factories/cats/core/stores.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b13a3549ac212c8e869ce5aff6b3508787e75af7afaeadba4b0e99f5476b101e
|
4
|
+
data.tar.gz: d4993f0e36936fc4ed18ae9accca173189056c3cddae7fc2f16704f6509bac80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91d4ba5e59ef7da90cf36d6073d20819496bae612eff73cdeccada481293a956311732201b049da61e84ba1c12b1a7464d636202b101f66a49bcf22146211440
|
7
|
+
data.tar.gz: afdceef95b3321eaea7ebad43bd622b814ef268f97b20c5815af07376fc710b338b74a25bc3e81d6c4b366f00e30e6553c2f2dcc38e84685bc670201ce4e4e13
|
@@ -1,14 +1,19 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class Allocation < ApplicationRecord
|
4
|
+
DRAFT = 'Draft'.freeze
|
5
|
+
APPROVED = 'Approved'.freeze
|
6
|
+
ALLOCATION_STATUSES = [DRAFT, APPROVED].freeze
|
7
|
+
|
4
8
|
belongs_to :rhn_request, optional: true
|
5
9
|
belongs_to :commodity
|
6
10
|
belongs_to :source, class_name: 'Cats::Core::Location'
|
7
11
|
|
8
|
-
validates :commodity_status, presence: true
|
12
|
+
validates :commodity_status, :allocation_status, presence: true
|
9
13
|
validates :reference_no, presence: true, uniqueness: true
|
10
14
|
validates :quantity, presence: true, numericality: { greater_than: 0 }
|
11
15
|
validates :commodity_status, inclusion: { in: Cats::Core::Commodity::COMMODITY_STATUSES }
|
16
|
+
validates :allocation_status, inclusion: { in: ALLOCATION_STATUSES }
|
12
17
|
|
13
18
|
delegate(:reference_no, to: :rhn_request, prefix: :rhn, allow_nil: true)
|
14
19
|
delegate(:batch_no, to: :commodity, prefix: true)
|
@@ -4,8 +4,11 @@ module Cats
|
|
4
4
|
DRAFT = 'Draft'.freeze
|
5
5
|
APPROVED = 'Approved'.freeze
|
6
6
|
STARTED = 'Started'.freeze
|
7
|
+
ARRIVED = 'Arrived'.freeze
|
8
|
+
UNLOADED = 'Unloaded'.freeze
|
9
|
+
RECEIVED = 'Received'.freeze
|
7
10
|
|
8
|
-
DISPATCH_STATUSES = [DRAFT, APPROVED, STARTED].freeze
|
11
|
+
DISPATCH_STATUSES = [DRAFT, APPROVED, STARTED, ARRIVED, UNLOADED, RECEIVED].freeze
|
9
12
|
|
10
13
|
belongs_to :prepared_by, class_name: 'Cats::Core::User'
|
11
14
|
belongs_to :transporter
|
@@ -16,9 +19,20 @@ module Cats
|
|
16
19
|
validates :reference_no, uniqueness: true
|
17
20
|
validates :quantity, numericality: { greater_than: 0 }
|
18
21
|
validates :commodity_status, inclusion: { in: Cats::Core::Commodity::COMMODITY_STATUSES }
|
22
|
+
validate :validate_quantity
|
19
23
|
|
20
24
|
delegate(:name, to: :transporter, prefix: true)
|
21
25
|
delegate(:email, to: :prepared_by, prefix: true)
|
26
|
+
|
27
|
+
def validate_quantity
|
28
|
+
return unless quantity && allocation_item
|
29
|
+
|
30
|
+
return unless quantity_changed?
|
31
|
+
|
32
|
+
dispatched = Dispatch.where(allocation_item: allocation_item).sum(:quantity)
|
33
|
+
remaining = allocation_item.quantity - dispatched
|
34
|
+
errors.add(:quantity, "exceeds allocated quantity. Maximum allowed is #{remaining}") if quantity > remaining
|
35
|
+
end
|
22
36
|
end
|
23
37
|
end
|
24
38
|
end
|
@@ -3,6 +3,9 @@ module Cats
|
|
3
3
|
class DispatchTransaction < Transaction
|
4
4
|
belongs_to :source, class_name: 'Cats::Core::Stack'
|
5
5
|
belongs_to :destination, class_name: 'Cats::Core::Dispatch'
|
6
|
+
|
7
|
+
delegate(:code, to: :source, prefix: true)
|
8
|
+
delegate(:reference_no, to: :destination, prefix: true)
|
6
9
|
end
|
7
10
|
end
|
8
11
|
end
|
@@ -5,7 +5,8 @@ module Cats
|
|
5
5
|
belongs_to :store_keeper, class_name: 'Cats::Core::User'
|
6
6
|
has_many :stacks
|
7
7
|
|
8
|
-
validates :name, :length, :width, :height, presence: true
|
8
|
+
validates :code, :name, :length, :width, :height, presence: true
|
9
|
+
validates :code, uniqueness: true
|
9
10
|
validates :length, :width, :height, numericality: { greater_than: 0 }
|
10
11
|
validates :gangway_length, :gangway_width, :gangway_corner_dist, presence: true, if: :has_gangway?
|
11
12
|
validates :gangway_length,
|
@@ -2,6 +2,7 @@ module Cats
|
|
2
2
|
module Core
|
3
3
|
class Transaction < ApplicationRecord
|
4
4
|
self.abstract_class = true
|
5
|
+
after_initialize :set_status
|
5
6
|
|
6
7
|
# Transaction statuses
|
7
8
|
DRAFT = 'Draft'.freeze
|
@@ -25,8 +26,16 @@ module Cats
|
|
25
26
|
destination.quantity += quantity
|
26
27
|
source.save
|
27
28
|
destination.save
|
29
|
+
self.status = COMMITTED
|
30
|
+
save
|
28
31
|
end
|
29
32
|
end
|
33
|
+
|
34
|
+
def set_status
|
35
|
+
return unless new_record?
|
36
|
+
|
37
|
+
self.status = DRAFT
|
38
|
+
end
|
30
39
|
end
|
31
40
|
end
|
32
41
|
end
|
@@ -8,7 +8,9 @@ module Cats
|
|
8
8
|
def available_space(id, level)
|
9
9
|
case level
|
10
10
|
when HUB
|
11
|
-
|
11
|
+
hub = Cats::Core::Location.find(id)
|
12
|
+
warehouses = hub.children
|
13
|
+
warehouse_ids = warehouses.map(&:id)
|
12
14
|
stores = Cats::Core::Store.joins(:warehouse)
|
13
15
|
.where(
|
14
16
|
cats_core_locations: {
|
@@ -19,19 +21,48 @@ module Cats
|
|
19
21
|
wh_details = []
|
20
22
|
stores.each do |key, value|
|
21
23
|
total_space = value.inject(0) { |sum, val| sum + val.available_space }
|
22
|
-
details = value.map
|
23
|
-
|
24
|
+
details = value.map do |val|
|
25
|
+
{ store_id: val.id, code: val.code, name: val.name, total_space: val.available_space }
|
26
|
+
end
|
27
|
+
warehouse = warehouses.find(key)
|
28
|
+
wh_details << {
|
29
|
+
warehouse_id: key,
|
30
|
+
code: warehouse.code,
|
31
|
+
name: warehouse.name,
|
32
|
+
total_space: total_space,
|
33
|
+
details: details
|
34
|
+
}
|
24
35
|
end
|
25
36
|
hub_space = wh_details.inject(0) { |sum, val| sum + val[:total_space] }
|
26
|
-
space = {
|
37
|
+
space = {
|
38
|
+
hub_id: id,
|
39
|
+
code: hub.code,
|
40
|
+
name: hub.name,
|
41
|
+
total_space: hub_space,
|
42
|
+
details: wh_details
|
43
|
+
}
|
27
44
|
when WAREHOUSE
|
45
|
+
warehouse = Cats::Core::Location.find(id)
|
28
46
|
stores = Cats::Core::Store.where(warehouse_id: id)
|
29
|
-
details = stores.map
|
47
|
+
details = stores.map do |store|
|
48
|
+
{ store_id: store.id, code: store.code, name: store.name, total_space: store.available_space }
|
49
|
+
end
|
30
50
|
total_space = stores.inject(0) { |sum, val| sum + val.available_space }
|
31
|
-
space = {
|
51
|
+
space = {
|
52
|
+
warehouse_id: id,
|
53
|
+
code: warehouse.code,
|
54
|
+
name: warehouse.name,
|
55
|
+
total_space: total_space,
|
56
|
+
details: details
|
57
|
+
}
|
32
58
|
when STORE
|
33
59
|
store = Cats::Core::Store.find(id)
|
34
|
-
space = {
|
60
|
+
space = {
|
61
|
+
store_id: store.id,
|
62
|
+
code: store.code,
|
63
|
+
name: store.name,
|
64
|
+
total_space: store.available_space
|
65
|
+
}
|
35
66
|
end
|
36
67
|
space
|
37
68
|
end
|
data/config/routes.rb
CHANGED
@@ -33,11 +33,11 @@ Cats::Core::Engine.routes.draw do
|
|
33
33
|
to: 'spaces#available_space',
|
34
34
|
as: :hub_space,
|
35
35
|
defaults: { level: Cats::Core::SpaceService::HUB }
|
36
|
-
get '/
|
36
|
+
get '/warehouses/:id/space',
|
37
37
|
to: 'spaces#available_space',
|
38
38
|
as: :warehouse_space,
|
39
39
|
defaults: { level: Cats::Core::SpaceService::WAREHOUSE }
|
40
|
-
get '/
|
40
|
+
get '/stores/:id/space',
|
41
41
|
to: 'spaces#available_space',
|
42
42
|
as: :store_space,
|
43
43
|
defaults: { level: Cats::Core::SpaceService::STORE }
|
@@ -16,6 +16,7 @@ class CreateCatsCoreAllocations < ActiveRecord::Migration[6.1]
|
|
16
16
|
foreign_key: { to_table: :cats_core_locations }
|
17
17
|
t.float :quantity, null: false
|
18
18
|
t.string :commodity_status, null: false, default: 'Good'
|
19
|
+
t.string :allocation_status, null: false, default: 'Draft'
|
19
20
|
t.string :remark
|
20
21
|
|
21
22
|
t.timestamps
|
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.0.
|
4
|
+
version: 1.0.50
|
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-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_model_serializers
|