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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16cbad0f2d1788e23d39a4b904aac57711bc3d6432b36ea4a96105ee9fccfd94
4
- data.tar.gz: d3ff309544e77e52620b48c66f19be7488c7629bcd6a2e7cf45cd084f48ce835
3
+ metadata.gz: e2624794cc9a3787caefb212037b9f33f8964e9d5512fcc40a7dbb31fa129009
4
+ data.tar.gz: 0f2d9b94ca4dc8794fe89928449b6c26cac67a78e2ffffadfa5be8d49baef52c
5
5
  SHA512:
6
- metadata.gz: c38aaf1efefb124e3e2e1d2122d420f5fe152363580931ac0c49065a19392b092cd280e503ce84d674c87709f251d1f780c50674808b83c47c2f7cd3bcf48a89
7
- data.tar.gz: d7c641de65a5a30397eecabd9af62c792e50e5540aeafbb1f795a720ce49a4d0747611a01af39ab086b72c6c8cd759deb1561940d1c31f09b2cda51c8c2b6a1d
6
+ metadata.gz: c0f3fc9431f4b011ca5015f9bf288627b51b547d79323e48d1f0221baae4781766b63ab521c23652feda8cd2fefb7f17a2242166ace64875cf4418138dc37c54
7
+ data.tar.gz: c9b0ec89851d48c0fcc9338dd749364d4a1a66e0a4291085c59f70b73605f5b47b4831cbfd03d01683f0b1ed829309247069f0878b6bc199cf2791936e416978
@@ -0,0 +1,13 @@
1
+ module Cats
2
+ module Core
3
+ class UnitConversionsController < ApplicationController
4
+ include Common
5
+
6
+ private
7
+
8
+ def model_params
9
+ params.require(:payload).permit(:from_id, :to_id, :factor)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -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
  }
@@ -46,6 +46,10 @@ module Cats
46
46
  save!
47
47
  self
48
48
  end
49
+
50
+ def quantity
51
+ transport_bid_items.sum(:quantity)
52
+ end
49
53
  end
50
54
  end
51
55
  end
@@ -3,6 +3,7 @@ module Cats
3
3
  class TransportBidItem < ApplicationRecord
4
4
  belongs_to :transport_bid
5
5
  belongs_to :transport_plan_item
6
+ belongs_to :unit, class_name: 'Cats::Core::UnitOfMeasure'
6
7
 
7
8
  has_many :offer_items
8
9
 
@@ -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
@@ -0,0 +1,7 @@
1
+ module Cats
2
+ module Core
3
+ class UnitConversionSerializer < ActiveModel::Serializer
4
+ attributes :id, :from_id, :from_abbreviation, :to_id, :to_abbreviation, :factor
5
+ end
6
+ end
7
+ 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
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.4.2'.freeze
3
+ VERSION = '1.4.3'.freeze
4
4
  end
5
5
  end
@@ -9,11 +9,20 @@ FactoryBot.define do
9
9
  approved_by { nil }
10
10
 
11
11
  trait :with_rhn do
12
- dispatchable { create(:rhn_request) }
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 { create(:monthly_plan) }
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
@@ -3,5 +3,6 @@ FactoryBot.define do
3
3
  transport_bid
4
4
  transport_plan_item
5
5
  quantity { 100 }
6
+ unit factory: :unit_of_measure
6
7
  end
7
8
  end
@@ -0,0 +1,7 @@
1
+ FactoryBot.define do
2
+ factory :unit_conversion, class: 'Cats::Core::UnitConversion' do
3
+ from factory: :unit_of_measure
4
+ to factory: :unit_of_measure
5
+ factor { 1 }
6
+ end
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.4.2
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-10 00:00:00.000000000 Z
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.3
490
+ rubygems_version: 3.3.7
486
491
  signing_key:
487
492
  specification_version: 4
488
493
  summary: Core module for CATS applications