cats_core 1.4.2 → 1.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/cats/core/unit_conversions_controller.rb +13 -0
- data/app/models/cats/core/dispatch_plan.rb +2 -2
- data/app/models/cats/core/location.rb +3 -1
- data/app/models/cats/core/transport_bid.rb +4 -0
- data/app/models/cats/core/transport_bid_item.rb +1 -0
- data/app/models/cats/core/unit_conversion.rb +25 -0
- data/app/serializers/cats/core/unit_conversion_serializer.rb +7 -0
- data/config/routes.rb +1 -0
- data/db/migrate/20211215124452_create_cats_core_transport_bid_items.rb +4 -0
- data/db/migrate/20220416143416_create_cats_core_unit_conversions.rb +19 -0
- data/lib/cats/core/version.rb +1 -1
- data/spec/factories/cats/core/dispatch_plans.rb +11 -2
- data/spec/factories/cats/core/transport_bid_items.rb +1 -0
- data/spec/factories/cats/core/unit_conversions.rb +7 -0
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2624794cc9a3787caefb212037b9f33f8964e9d5512fcc40a7dbb31fa129009
|
4
|
+
data.tar.gz: 0f2d9b94ca4dc8794fe89928449b6c26cac67a78e2ffffadfa5be8d49baef52c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0f3fc9431f4b011ca5015f9bf288627b51b547d79323e48d1f0221baae4781766b63ab521c23652feda8cd2fefb7f17a2242166ace64875cf4418138dc37c54
|
7
|
+
data.tar.gz: c9b0ec89851d48c0fcc9338dd749364d4a1a66e0a4291085c59f70b73605f5b47b4831cbfd03d01683f0b1ed829309247069f0878b6bc199cf2791936e416978
|
@@ -44,12 +44,12 @@ module Cats
|
|
44
44
|
|
45
45
|
# Raise error if the total dispatch plan quantity is not equal to the
|
46
46
|
# dispatchable quantity
|
47
|
-
if dispatchable && dispatchable.quantity != quantity
|
47
|
+
if dispatchable.instance_of?(RhnRequest) && dispatchable.quantity != quantity
|
48
48
|
raise(StandardError, 'Requested quantity and plan quantity do not match.')
|
49
49
|
end
|
50
50
|
|
51
51
|
self.status = APPROVED
|
52
|
-
dispatchable&.allocate
|
52
|
+
dispatchable&.allocate if dispatchable.instance_of?(RhnRequest)
|
53
53
|
save!
|
54
54
|
end
|
55
55
|
|
@@ -4,11 +4,12 @@ module Cats
|
|
4
4
|
REGION = 'Region'.freeze
|
5
5
|
ZONE = 'Zone'.freeze
|
6
6
|
WOREDA = 'Woreda'.freeze
|
7
|
+
FDP = 'Fdp'.freeze
|
7
8
|
KEBELE = 'Kebele'.freeze
|
8
9
|
HUB = 'Hub'.freeze
|
9
10
|
WAREHOUSE = 'Warehouse'.freeze
|
10
11
|
|
11
|
-
LOCATION_TYPES = [REGION, ZONE, WOREDA, KEBELE, HUB, WAREHOUSE].freeze
|
12
|
+
LOCATION_TYPES = [REGION, ZONE, WOREDA, KEBELE, HUB, WAREHOUSE, FDP].freeze
|
12
13
|
|
13
14
|
has_ancestry
|
14
15
|
|
@@ -23,6 +24,7 @@ module Cats
|
|
23
24
|
ZONE => [REGION],
|
24
25
|
WOREDA => [REGION, ZONE],
|
25
26
|
KEBELE => [REGION, ZONE, WOREDA],
|
27
|
+
FDP => [REGION, ZONE, WOREDA],
|
26
28
|
HUB => [REGION, ZONE, WOREDA, KEBELE],
|
27
29
|
WAREHOUSE => [REGION, ZONE, WOREDA, KEBELE, HUB]
|
28
30
|
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Cats
|
2
|
+
module Core
|
3
|
+
class UnitConversion < ApplicationRecord
|
4
|
+
belongs_to :from, class_name: 'Cats::Core::UnitOfMeasure'
|
5
|
+
belongs_to :to, class_name: 'Cats::Core::UnitOfMeasure'
|
6
|
+
|
7
|
+
validates :factor, presence: true
|
8
|
+
validates :from_id, uniqueness: { scope: :to_id }
|
9
|
+
validates :factor, numericality: { greater_than: 0 }
|
10
|
+
|
11
|
+
delegate(:abbreviation, to: :from, prefix: true)
|
12
|
+
delegate(:abbreviation, to: :to, prefix: true)
|
13
|
+
|
14
|
+
def self.convert(from, to, value)
|
15
|
+
return value if from == to
|
16
|
+
|
17
|
+
conversion = find_by(from: from, to: to)
|
18
|
+
error = "Conversion factor from #{from.abbreviation} to #{to.abbreviation} not found."
|
19
|
+
raise(StandardError, error) unless conversion
|
20
|
+
|
21
|
+
value * conversion.factor
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/config/routes.rb
CHANGED
@@ -74,6 +74,7 @@ Cats::Core::Engine.routes.draw do
|
|
74
74
|
end
|
75
75
|
resources :currencies, except: %i[destroy]
|
76
76
|
resources :unit_of_measures, except: %i[destroy]
|
77
|
+
resources :unit_conversions, except: %i[destroy]
|
77
78
|
|
78
79
|
post '/transporters/filter', controller: :transporters, action: :filter
|
79
80
|
resources :transporters, except: %i[destroy]
|
@@ -10,6 +10,10 @@ class CreateCatsCoreTransportBidItems < ActiveRecord::Migration[6.1]
|
|
10
10
|
index: { name: 'tpi_on_tbi_indx' },
|
11
11
|
foreign_key: { to_table: :cats_core_transport_plan_items }
|
12
12
|
t.float :quantity, null: false
|
13
|
+
t.references :unit,
|
14
|
+
null: false,
|
15
|
+
index: { name: 'unit_on_tbi_indx' },
|
16
|
+
foreign_key: { to_table: :cats_core_unit_of_measures }
|
13
17
|
|
14
18
|
t.timestamps
|
15
19
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class CreateCatsCoreUnitConversions < ActiveRecord::Migration[7.0]
|
2
|
+
def change
|
3
|
+
create_table :cats_core_unit_conversions do |t|
|
4
|
+
t.references :from,
|
5
|
+
null: false,
|
6
|
+
index: { name: 'from_on_uc_indx' },
|
7
|
+
foreign_key: { to_table: :cats_core_unit_of_measures }
|
8
|
+
t.references :to,
|
9
|
+
null: false,
|
10
|
+
index: { name: 'to_on_uc_indx' },
|
11
|
+
foreign_key: { to_table: :cats_core_unit_of_measures }
|
12
|
+
t.float :factor, null: false
|
13
|
+
|
14
|
+
t.timestamps
|
15
|
+
end
|
16
|
+
|
17
|
+
add_index(:cats_core_unit_conversions, [:from_id, :to_id], unique: true)
|
18
|
+
end
|
19
|
+
end
|
data/lib/cats/core/version.rb
CHANGED
@@ -9,11 +9,20 @@ FactoryBot.define do
|
|
9
9
|
approved_by { nil }
|
10
10
|
|
11
11
|
trait :with_rhn do
|
12
|
-
dispatchable
|
12
|
+
dispatchable do
|
13
|
+
disp = create(:rhn_request)
|
14
|
+
disp.approve
|
15
|
+
disp
|
16
|
+
end
|
13
17
|
end
|
14
18
|
|
15
19
|
trait :with_monthly_plan do
|
16
|
-
dispatchable
|
20
|
+
dispatchable do
|
21
|
+
disp = create(:monthly_plan)
|
22
|
+
3.times { create(:monthly_plan_item, monthly_plan: disp) }
|
23
|
+
disp.approve
|
24
|
+
disp
|
25
|
+
end
|
17
26
|
end
|
18
27
|
end
|
19
28
|
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.
|
4
|
+
version: 1.4.3
|
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-04-
|
11
|
+
date: 2022-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_model_serializers
|
@@ -251,6 +251,7 @@ files:
|
|
251
251
|
- app/controllers/cats/core/spaces_controller.rb
|
252
252
|
- app/controllers/cats/core/stacks_controller.rb
|
253
253
|
- app/controllers/cats/core/transporters_controller.rb
|
254
|
+
- app/controllers/cats/core/unit_conversions_controller.rb
|
254
255
|
- app/controllers/cats/core/unit_of_measures_controller.rb
|
255
256
|
- app/controllers/cats/core/users_controller.rb
|
256
257
|
- app/controllers/concerns/cats/core/common.rb
|
@@ -309,6 +310,7 @@ files:
|
|
309
310
|
- app/models/cats/core/transport_plan.rb
|
310
311
|
- app/models/cats/core/transport_plan_item.rb
|
311
312
|
- app/models/cats/core/transporter.rb
|
313
|
+
- app/models/cats/core/unit_conversion.rb
|
312
314
|
- app/models/cats/core/unit_of_measure.rb
|
313
315
|
- app/models/cats/core/user.rb
|
314
316
|
- app/models/concerns/cats/core/dispatchable.rb
|
@@ -332,6 +334,7 @@ files:
|
|
332
334
|
- app/serializers/cats/core/route_serializer.rb
|
333
335
|
- app/serializers/cats/core/stack_serializer.rb
|
334
336
|
- app/serializers/cats/core/transporter_serializer.rb
|
337
|
+
- app/serializers/cats/core/unit_conversion_serializer.rb
|
335
338
|
- app/serializers/cats/core/unit_of_measure_serializer.rb
|
336
339
|
- app/serializers/cats/core/user_serializer.rb
|
337
340
|
- app/services/cats/core/dispatch_plan_service.rb
|
@@ -400,6 +403,7 @@ files:
|
|
400
403
|
- db/migrate/20220107125025_create_cats_core_monthly_plan_items.rb
|
401
404
|
- db/migrate/20220107132433_create_cats_core_monthly_plan_item_details.rb
|
402
405
|
- db/migrate/20220209083928_create_cats_core_hub_authorizations.rb
|
406
|
+
- db/migrate/20220416143416_create_cats_core_unit_conversions.rb
|
403
407
|
- lib/cats/core.rb
|
404
408
|
- lib/cats/core/engine.rb
|
405
409
|
- lib/cats/core/version.rb
|
@@ -457,6 +461,7 @@ files:
|
|
457
461
|
- spec/factories/cats/core/transport_plan_items.rb
|
458
462
|
- spec/factories/cats/core/transport_plans.rb
|
459
463
|
- spec/factories/cats/core/transporters.rb
|
464
|
+
- spec/factories/cats/core/unit_conversions.rb
|
460
465
|
- spec/factories/cats/core/unit_of_measures.rb
|
461
466
|
- spec/factories/cats/core/users.rb
|
462
467
|
homepage: http://cats.ndrmcapps.org
|
@@ -482,7 +487,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
482
487
|
- !ruby/object:Gem::Version
|
483
488
|
version: '0'
|
484
489
|
requirements: []
|
485
|
-
rubygems_version: 3.3.
|
490
|
+
rubygems_version: 3.3.7
|
486
491
|
signing_key:
|
487
492
|
specification_version: 4
|
488
493
|
summary: Core module for CATS applications
|