cats_core 1.1.39 → 1.1.40
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/models/cats/core/allocation.rb +5 -1
- data/app/models/cats/core/commodity.rb +53 -6
- data/app/models/cats/core/rhn_request.rb +1 -1
- data/app/models/cats/core/stack.rb +4 -2
- data/app/serializers/cats/core/commodity_serializer.rb +1 -1
- data/db/migrate/20211030133752_add_status_to_cats_core_commodities.rb +6 -0
- data/lib/cats/core/version.rb +1 -1
- data/spec/factories/cats/core/allocations.rb +5 -1
- data/spec/factories/cats/core/commodities.rb +1 -1
- data/spec/factories/cats/core/rhn_requests.rb +5 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2c955101b31607adc7eec1388f6f4c172181ffd78a2e514b5c220130899b4f3
|
4
|
+
data.tar.gz: f99a81794245cd12120a3b5dac7cd04a6f8a89ef7ca96dbce409b341629172c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b80445e45187d6590c0219cba05d11defbea0d298f79cb0f3c7c8fc82705e17ef6abc1223181c8ae6dca44138aa4b46a4d3aaa9f7732c7efb5d92ba6aeeff76e
|
7
|
+
data.tar.gz: 1a3efcd95681646652dd285f6f96f1ba28da6ba6214f32db735ff8f4571de66c28c68342843c9a347cb4f70e2a6078800ef4eff27898d675cabf79e80037b72e
|
@@ -57,7 +57,7 @@ module Cats
|
|
57
57
|
def validate_commodity_status
|
58
58
|
return unless commodity
|
59
59
|
|
60
|
-
errors.add(:commodity, 'should be approved first.') unless commodity.
|
60
|
+
errors.add(:commodity, 'should be approved first.') unless commodity.status == Commodity::APPROVED
|
61
61
|
end
|
62
62
|
|
63
63
|
def approve
|
@@ -68,6 +68,10 @@ module Cats
|
|
68
68
|
|
69
69
|
self.allocation_status = Allocation::APPROVED
|
70
70
|
save!
|
71
|
+
|
72
|
+
# If the commodity is all allocated, then we should
|
73
|
+
# set its status to allocated.
|
74
|
+
commodity.allocate
|
71
75
|
end
|
72
76
|
end
|
73
77
|
end
|
@@ -1,7 +1,11 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class Commodity < ApplicationRecord
|
4
|
-
|
4
|
+
# Statuses
|
5
|
+
DRAFT = 'Draft'.freeze
|
6
|
+
APPROVED = 'Approved'.freeze
|
7
|
+
ALLOCATED = 'Allocated'.freeze
|
8
|
+
STATUSES = [DRAFT, APPROVED, ALLOCATED].freeze
|
5
9
|
|
6
10
|
# Commodity statuses
|
7
11
|
GOOD = 'Good'.freeze
|
@@ -17,23 +21,66 @@ module Cats
|
|
17
21
|
belongs_to :unit_of_measure
|
18
22
|
belongs_to :source, polymorphic: true
|
19
23
|
|
24
|
+
has_many :allocations
|
25
|
+
|
20
26
|
validates :best_use_before, presence: true
|
21
27
|
validates :batch_no, presence: true, uniqueness: true
|
22
28
|
validates :quantity, presence: true, numericality: { greater_than: 0 }
|
23
29
|
validates :volume_per_metric_ton, numericality: { greater_than: 0, allow_nil: true }
|
24
30
|
validates :arrival_status, presence: true, inclusion: { in: ARRIVAL_STATUSES }
|
31
|
+
validates :status, presence: true, inclusion: { in: STATUSES }
|
25
32
|
|
26
33
|
delegate(:abbreviation, to: :unit_of_measure, prefix: true)
|
27
34
|
delegate(:reference_no, to: :source, prefix: true)
|
28
35
|
|
29
|
-
def
|
30
|
-
|
36
|
+
def name
|
37
|
+
source.commodity_category.name
|
38
|
+
end
|
39
|
+
|
40
|
+
def approve
|
41
|
+
raise(StandardError, 'Commodity already approved.') if status == APPROVED
|
42
|
+
|
43
|
+
Cats::Core::Commodity.transaction do
|
44
|
+
self.status = APPROVED
|
45
|
+
save!
|
46
|
+
store = Cats::Core::Store.find_by(code: 'SUP-STORE')
|
47
|
+
raise(StandardError, 'Supplier store does not exist.') unless store
|
31
48
|
|
32
|
-
|
49
|
+
Cats::Core::Stack.create!(
|
50
|
+
code: batch_no,
|
51
|
+
store: store,
|
52
|
+
commodity: self,
|
53
|
+
quantity: quantity,
|
54
|
+
commodity_status: GOOD,
|
55
|
+
stack_status: Stack::ALLOCATED,
|
56
|
+
length: 100,
|
57
|
+
width: 100,
|
58
|
+
height: 10,
|
59
|
+
start_x: 1,
|
60
|
+
start_y: 1
|
61
|
+
)
|
62
|
+
true
|
63
|
+
end
|
64
|
+
false
|
33
65
|
end
|
34
66
|
|
35
|
-
def
|
36
|
-
|
67
|
+
def allocate(ignore_errors: true)
|
68
|
+
statuses = Allocation.where(commodity_id: id).map(&:allocation_status).uniq
|
69
|
+
unless statuses.count == 1 && statuses[0] == APPROVED
|
70
|
+
return if ignore_errors
|
71
|
+
|
72
|
+
raise(StandardError, 'There are allocations in "Draft" state.')
|
73
|
+
end
|
74
|
+
|
75
|
+
quantity = allocations.sum(:quantity)
|
76
|
+
unless quantity == self.quantity
|
77
|
+
return if ignore_errors
|
78
|
+
|
79
|
+
raise(StandardError, 'Total allocations quantity is not the same as commodity quantity.')
|
80
|
+
end
|
81
|
+
|
82
|
+
self.status = ALLOCATED
|
83
|
+
save!
|
37
84
|
end
|
38
85
|
end
|
39
86
|
end
|
@@ -18,7 +18,7 @@ module Cats
|
|
18
18
|
def validate_commodity_status
|
19
19
|
return unless commodity
|
20
20
|
|
21
|
-
errors.add(:commodity, 'should be approved first.') unless commodity.
|
21
|
+
errors.add(:commodity, 'should be approved first.') unless commodity.status == Commodity::APPROVED
|
22
22
|
end
|
23
23
|
|
24
24
|
def validate_quantity
|
@@ -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, unless: -> { store && store.code == 'SUP-STORE' }
|
24
24
|
|
25
|
+
delegate :batch_no, to: :commodity, prefix: true
|
26
|
+
|
25
27
|
after_save :update_store_space
|
26
28
|
|
27
29
|
def validate_coordinates
|
@@ -58,8 +60,8 @@ module Cats
|
|
58
60
|
return unless store.present? && length.present? && width.present? && start_x.present? && start_y.present?
|
59
61
|
|
60
62
|
rule = stacking_rules
|
61
|
-
if start_x < rule.distance_from_wall || store.length - (
|
62
|
-
store.width - (
|
63
|
+
if start_x < rule.distance_from_wall || store.length - (start_x + length) < rule.distance_from_wall ||
|
64
|
+
store.width - (start_y + width) < rule.distance_from_wall || start_y < rule.distance_from_wall
|
63
65
|
errors.add(:base,
|
64
66
|
message: "The stack must be placed #{rule.distance_from_wall} meter away from a store wall")
|
65
67
|
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_of_measure_abbreviation, :source_id,
|
5
5
|
:source_type, :source_reference_no, :quantity, :best_use_before, :volume_per_metric_ton,
|
6
|
-
:arrival_status, :
|
6
|
+
:arrival_status, :status
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
data/lib/cats/core/version.rb
CHANGED
@@ -2,7 +2,11 @@ FactoryBot.define do
|
|
2
2
|
factory :allocation, class: 'Cats::Core::Allocation' do
|
3
3
|
reference_no { FFaker::Name.name }
|
4
4
|
rhn_request { nil }
|
5
|
-
commodity
|
5
|
+
commodity do
|
6
|
+
c = create(:commodity)
|
7
|
+
c.approve
|
8
|
+
c
|
9
|
+
end
|
6
10
|
source factory: :location
|
7
11
|
quantity { 50 }
|
8
12
|
commodity_status { Cats::Core::Commodity::GOOD }
|
@@ -1,7 +1,11 @@
|
|
1
1
|
FactoryBot.define do
|
2
2
|
factory :rhn_request, class: 'Cats::Core::RhnRequest' do
|
3
3
|
reference_no { FFaker::Name.name }
|
4
|
-
commodity
|
4
|
+
commodity do
|
5
|
+
c = create(:commodity)
|
6
|
+
c.approve
|
7
|
+
c
|
8
|
+
end
|
5
9
|
quantity { 100 }
|
6
10
|
request_date { Date.today }
|
7
11
|
requested_by { FFaker::Name.name }
|
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.1.
|
4
|
+
version: 1.1.40
|
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-10-
|
11
|
+
date: 2021-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_model_serializers
|
@@ -346,6 +346,7 @@ files:
|
|
346
346
|
- db/migrate/20210814175406_create_cats_core_stack_transactions.rb
|
347
347
|
- db/migrate/20211002050739_create_cats_core_notification_rules.rb
|
348
348
|
- db/migrate/20211024063240_add_status_to_cats_core_rhn_requests.rb
|
349
|
+
- db/migrate/20211030133752_add_status_to_cats_core_commodities.rb
|
349
350
|
- lib/cats/core.rb
|
350
351
|
- lib/cats/core/engine.rb
|
351
352
|
- lib/cats/core/version.rb
|