cats_core 1.4.2 → 1.4.5

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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/cats/core/dispatch_plan_items_controller.rb +1 -1
  3. data/app/controllers/cats/core/dispatch_plans_controller.rb +1 -1
  4. data/app/controllers/cats/core/dispatch_transactions_controller.rb +1 -1
  5. data/app/controllers/cats/core/dispatches_controller.rb +1 -1
  6. data/app/controllers/cats/core/stacks_controller.rb +2 -2
  7. data/app/controllers/cats/core/unit_conversions_controller.rb +13 -0
  8. data/app/models/cats/core/commodity.rb +1 -1
  9. data/app/models/cats/core/dispatch_plan.rb +2 -4
  10. data/app/models/cats/core/dispatch_plan_item.rb +3 -1
  11. data/app/models/cats/core/location.rb +3 -1
  12. data/app/models/cats/core/transport_bid.rb +4 -0
  13. data/app/models/cats/core/transport_bid_item.rb +2 -0
  14. data/app/models/cats/core/transport_requisition.rb +28 -0
  15. data/app/models/cats/core/transport_requisition_detail.rb +12 -0
  16. data/app/models/cats/core/transport_requisition_item.rb +14 -0
  17. data/app/models/cats/core/unit_conversion.rb +25 -0
  18. data/app/notifications/cats/core/allocation_notification.rb +2 -2
  19. data/app/notifications/cats/core/dispatch_notification.rb +1 -1
  20. data/app/serializers/cats/core/commodity_serializer.rb +1 -1
  21. data/app/serializers/cats/core/dispatch_plan_item_serializer.rb +1 -1
  22. data/app/serializers/cats/core/dispatch_plan_serializer.rb +1 -2
  23. data/app/serializers/cats/core/unit_conversion_serializer.rb +7 -0
  24. data/app/services/cats/core/stack_service.rb +8 -8
  25. data/config/routes.rb +2 -1
  26. data/db/migrate/20210718043328_create_cats_core_dispatch_plans.rb +0 -5
  27. data/db/migrate/20210718043401_create_cats_core_dispatch_plan_items.rb +4 -0
  28. data/db/migrate/20211215124452_create_cats_core_transport_bid_items.rb +4 -0
  29. data/db/migrate/20220416143416_create_cats_core_unit_conversions.rb +19 -0
  30. data/db/migrate/20220417105839_create_cats_core_transport_requisitions.rb +26 -0
  31. data/db/migrate/20220417123835_create_cats_core_transport_requisition_items.rb +21 -0
  32. data/db/migrate/20220417151821_create_cats_core_transport_requisition_details.rb +17 -0
  33. data/lib/cats/core/version.rb +1 -1
  34. data/spec/factories/cats/core/dispatch_plan_items.rb +1 -0
  35. data/spec/factories/cats/core/dispatch_plans.rb +11 -3
  36. data/spec/factories/cats/core/locations.rb +13 -8
  37. data/spec/factories/cats/core/transport_bid_items.rb +1 -0
  38. data/spec/factories/cats/core/transport_requisition_details.rb +7 -0
  39. data/spec/factories/cats/core/transport_requisition_items.rb +8 -0
  40. data/spec/factories/cats/core/transport_requisitions.rb +10 -0
  41. data/spec/factories/cats/core/unit_conversions.rb +7 -0
  42. metadata +17 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16cbad0f2d1788e23d39a4b904aac57711bc3d6432b36ea4a96105ee9fccfd94
4
- data.tar.gz: d3ff309544e77e52620b48c66f19be7488c7629bcd6a2e7cf45cd084f48ce835
3
+ metadata.gz: 1f6f8e286a7968b1159a3b0a7c9cb6e99f1637179ceb1d283d6b00f8c7e04d0b
4
+ data.tar.gz: a98a62f4250435c8611f1034e27e5dc0668ab1833ed8bdf42aa0b6ecdb47b4cd
5
5
  SHA512:
6
- metadata.gz: c38aaf1efefb124e3e2e1d2122d420f5fe152363580931ac0c49065a19392b092cd280e503ce84d674c87709f251d1f780c50674808b83c47c2f7cd3bcf48a89
7
- data.tar.gz: d7c641de65a5a30397eecabd9af62c792e50e5540aeafbb1f795a720ce49a4d0747611a01af39ab086b72c6c8cd759deb1561940d1c31f09b2cda51c8c2b6a1d
6
+ metadata.gz: 5e8cfe8cacbf89d43b8a3552e2414d35081e2c4a92925f6c0a8678bc40822d34274961dd5bcb96c192e0b35ef6956cf709bea806676ff5dad7e84f73cae29888
7
+ data.tar.gz: 8d4e6d29a50e7ebc4fb2fa78dca753ca9d11ba90453c421ba77f7cf57819649e5027a40e76a298b14cdf20959f74b8fae2d57a265360a24d91ffe2e44df9134b
@@ -17,7 +17,7 @@ module Cats
17
17
 
18
18
  def model_params
19
19
  params.require(:payload).permit(:dispatch_plan_id, :source_id, :destination_id, :quantity, :commodity_status,
20
- :status)
20
+ :status, :commodity_id)
21
21
  end
22
22
  end
23
23
  end
@@ -33,7 +33,7 @@ module Cats
33
33
  private
34
34
 
35
35
  def model_params
36
- params.require(:payload).permit(:reference_no, :dispatchable_id, :dispatchable_type, :commodity_id)
36
+ params.require(:payload).permit(:reference_no, :dispatchable_id, :dispatchable_type)
37
37
  end
38
38
  end
39
39
  end
@@ -14,7 +14,7 @@ module Cats
14
14
  # user to give us a source.
15
15
  def create_allocation
16
16
  dispatch = Dispatch.find(model_params[:dispatch_id])
17
- commodity = dispatch.dispatch_plan_item.dispatch_plan.commodity
17
+ commodity = dispatch.dispatch_plan_item.commodity
18
18
  transaction = DispatchTransaction.new(model_params)
19
19
 
20
20
  # Fetch supplier stack by commodity
@@ -49,7 +49,7 @@ module Cats
49
49
  end
50
50
 
51
51
  def commodity
52
- data = @dispatch.dispatch_plan_item.dispatch_plan.commodity
52
+ data = @dispatch.dispatch_plan_item.commodity
53
53
  render json: { success: true, data: serialize(data) }
54
54
  end
55
55
 
@@ -13,9 +13,9 @@ module Cats
13
13
  render json: { success: true, data: serialize(query.result) }
14
14
  end
15
15
 
16
- def commodity_for_location
16
+ def items_for_location
17
17
  service = StackService.new
18
- commodities = service.commodity_for_location(current_user)
18
+ commodities = service.items_for_location(current_user)
19
19
  render json: { success: true, data: serialize(commodities) }
20
20
  end
21
21
 
@@ -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
@@ -38,7 +38,7 @@ module Cats
38
38
  validates :arrival_status, presence: true, inclusion: { in: ARRIVAL_STATUSES }
39
39
  validates :status, presence: true, inclusion: { in: STATUSES }
40
40
 
41
- delegate(:abbreviation, to: :unit_of_measure, prefix: true)
41
+ delegate(:abbreviation, to: :unit_of_measure, prefix: 'unit')
42
42
  delegate(:reference_no, to: :source, prefix: true)
43
43
 
44
44
  def name
@@ -8,7 +8,6 @@ module Cats
8
8
  belongs_to :dispatchable, polymorphic: true, optional: true
9
9
  belongs_to :prepared_by, class_name: 'Cats::Core::User'
10
10
  belongs_to :approved_by, class_name: 'Cats::Core::User', optional: true
11
- belongs_to :commodity
12
11
 
13
12
  has_many :dispatch_plan_items
14
13
 
@@ -16,7 +15,6 @@ module Cats
16
15
  validates :status, inclusion: { in: STATUSES }
17
16
  validate :validate_dispatchable, on: :create
18
17
 
19
- delegate(:batch_no, :name, :quantity, to: :commodity, prefix: true)
20
18
  delegate(:request_reference, to: :dispatchable, allow_nil: true)
21
19
  delegate(:request_quantity, to: :dispatchable, allow_nil: true)
22
20
 
@@ -44,12 +42,12 @@ module Cats
44
42
 
45
43
  # Raise error if the total dispatch plan quantity is not equal to the
46
44
  # dispatchable quantity
47
- if dispatchable && dispatchable.quantity != quantity
45
+ if dispatchable.instance_of?(RhnRequest) && dispatchable.quantity != quantity
48
46
  raise(StandardError, 'Requested quantity and plan quantity do not match.')
49
47
  end
50
48
 
51
49
  self.status = APPROVED
52
- dispatchable&.allocate
50
+ dispatchable&.allocate if dispatchable.instance_of?(RhnRequest)
53
51
  save!
54
52
  end
55
53
 
@@ -10,6 +10,8 @@ module Cats
10
10
  belongs_to :source, class_name: 'Cats::Core::Location'
11
11
  belongs_to :destination, class_name: 'Cats::Core::Location'
12
12
  belongs_to :dispatch_plan
13
+ belongs_to :commodity
14
+
13
15
  has_many :dispatches
14
16
  has_many :hub_authorizations
15
17
 
@@ -18,7 +20,7 @@ module Cats
18
20
  validates :status, presence: true, inclusion: { in: STATUSES }
19
21
 
20
22
  delegate(:reference_no, to: :dispatch_plan, prefix: :plan, allow_nil: true)
21
- delegate(:commodity_batch_no, :commodity_name, to: :dispatch_plan)
23
+ delegate(:batch_no, :name, to: :commodity, prefix: true)
22
24
  delegate(:name, to: :source, prefix: true)
23
25
  delegate(:name, to: :destination, prefix: true)
24
26
  delegate(:location_type, to: :source, prefix: true)
@@ -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
 
@@ -10,6 +11,7 @@ module Cats
10
11
  validates :transport_plan_item_id, uniqueness: true
11
12
 
12
13
  delegate(:reference_no, to: :transport_bid, prefix: true)
14
+ delegate(:abbreviation, to: :unit, prefix: true)
13
15
 
14
16
  def route
15
17
  transport_plan_item.route.name
@@ -0,0 +1,28 @@
1
+ module Cats
2
+ module Core
3
+ class TransportRequisition < ApplicationRecord
4
+ DRAFT = 'Draft'.freeze
5
+ APPROVED = 'Approved'.freeze
6
+ STATUSES = [DRAFT, APPROVED].freeze
7
+
8
+ belongs_to :dispatch_plan
9
+ belongs_to :requested_by, class_name: 'Cats::Core::User'
10
+ belongs_to :approved_by, class_name: 'Cats::Core::User', optional: true
11
+ belongs_to :unit, class_name: 'Cats::Core::UnitOfMeasure'
12
+
13
+ has_many :transport_requisition_items
14
+
15
+ validates :reference_no, presence: true, uniqueness: true
16
+ validates :status, presence: true, inclusion: { in: STATUSES }
17
+
18
+ delegate(:full_name, to: :requested_by, prefix: 'requestor')
19
+ delegate(:full_name, to: :approved_by, prefix: 'approver')
20
+ delegate(:abbreviation, to: :unit, prefix: true)
21
+
22
+ def quantity
23
+ quantities = transport_requisition_items.map { |item| UnitConversion.convert(item.unit, unit, item.quantity) }
24
+ quantities.sum
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,12 @@
1
+ module Cats
2
+ module Core
3
+ class TransportRequisitionDetail < ApplicationRecord
4
+ belongs_to :transport_requisition_item
5
+ belongs_to :fdp, class_name: 'Cats::Core::Location'
6
+
7
+ validates :quantity, presence: true, numericality: { greater_than: 0 }
8
+
9
+ delegate(:name, to: :fdp, prefix: true)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ module Cats
2
+ module Core
3
+ class TransportRequisitionItem < ApplicationRecord
4
+ belongs_to :transport_requisition
5
+ belongs_to :dispatch_plan_item
6
+ belongs_to :unit, class_name: 'Cats::Core::UnitOfMeasure'
7
+
8
+ validates :quantity, presence: true, numericality: { greater_than: 0 }
9
+
10
+ delegate(:reference_no, to: :transport_requisition, prefix: 'requisition')
11
+ delegate(:abbreviation, to: :unit, prefix: true)
12
+ end
13
+ end
14
+ end
@@ -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
@@ -12,14 +12,14 @@ module Cats
12
12
 
13
13
  def message
14
14
  allocation_item = params[:allocation_item]
15
- commodity = allocation_item.dispatch_plan.commodity.name
15
+ commodity = allocation_item.commodity.name
16
16
  source = allocation_item.source.name
17
17
  destination = allocation_item.destination.name
18
18
  title = "Allocation Notification - #{commodity}"
19
19
  date = Date.today
20
20
  body = <<~BODY
21
21
  Commodity with the following specification has been allocated to you:
22
- Batch No. = #{allocation_item.dispatch_plan.commodity.batch_no}
22
+ Batch No. = #{allocation_item.commodity.batch_no}
23
23
  Commodity = #{commodity}
24
24
  Quantity = #{allocation_item.quantity}
25
25
  The commodity is expected to be delivered from #{source} to #{destination}
@@ -7,7 +7,7 @@ module Cats
7
7
 
8
8
  def message
9
9
  dispatch = params[:dispatch]
10
- commodity = dispatch.dispatch_plan_item.dispatch_plan.commodity
10
+ commodity = dispatch.dispatch_plan_item.commodity
11
11
  title = "Dispatch Notification - #{commodity.name}"
12
12
  date = Date.today
13
13
  body = <<~BODY
@@ -1,7 +1,7 @@
1
1
  module Cats
2
2
  module Core
3
3
  class CommoditySerializer < ActiveModel::Serializer
4
- attributes :id, :name, :batch_no, :description, :unit_of_measure_id, :unit_of_measure_abbreviation, :source_id,
4
+ attributes :id, :name, :batch_no, :description, :unit_of_measure_id, :unit_abbreviation, :source_id,
5
5
  :source_type, :source_reference_no, :quantity, :best_use_before, :volume_per_metric_ton,
6
6
  :arrival_status, :status, :shipping_reference
7
7
  end
@@ -3,7 +3,7 @@ module Cats
3
3
  class DispatchPlanItemSerializer < ActiveModel::Serializer
4
4
  attributes :id, :dispatch_plan_id, :plan_reference_no, :source_id, :source_name, :destination_id,
5
5
  :destination_name, :quantity, :source_location_type, :destination_location_type, :commodity_status,
6
- :status
6
+ :status, :commodity_id, :commodity_name, :commodity_batch_no
7
7
  end
8
8
  end
9
9
  end
@@ -2,8 +2,7 @@ module Cats
2
2
  module Core
3
3
  class DispatchPlanSerializer < ActiveModel::Serializer
4
4
  attributes :id, :reference_no, :status, :dispatchable_id, :dispatchable_type, :request_reference,
5
- :request_quantity, :commodity_id, :commodity_name, :commodity_batch_no, :commodity_quantity,
6
- :upstream
5
+ :request_quantity, :upstream
7
6
  end
8
7
  end
9
8
  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
@@ -1,7 +1,7 @@
1
1
  module Cats
2
2
  module Core
3
3
  class StackService
4
- def commodity_for_location(user)
4
+ def items_for_location(user)
5
5
  details = user.details
6
6
 
7
7
  key_available = details.keys.any? { |key| %w[stores warehouse hub].include?(key) }
@@ -17,7 +17,7 @@ module Cats
17
17
 
18
18
  allocation_items =
19
19
  DispatchPlanItem
20
- .joins(dispatch_plan: :commodity)
20
+ .joins(:dispatch_plan)
21
21
  .where(destination: hub, dispatch_plan: { status: DispatchPlan::APPROVED })
22
22
 
23
23
  allocation_items.map do |item|
@@ -26,10 +26,10 @@ module Cats
26
26
  source: item.source.name,
27
27
  destination: item.destination.name,
28
28
  quantity: item.quantity,
29
- batch_no: item.dispatch_plan.commodity.batch_no,
30
- commodity_id: item.dispatch_plan.commodity_id,
31
- commodity_name: item.dispatch_plan.commodity.name,
32
- unit: item.dispatch_plan.commodity.unit_of_measure.abbreviation
29
+ batch_no: item.commodity.batch_no,
30
+ commodity_id: item.commodity_id,
31
+ commodity_name: item.commodity.name,
32
+ unit: item.commodity.unit_abbreviation
33
33
  }
34
34
  end
35
35
  end
@@ -39,7 +39,7 @@ module Cats
39
39
  warehouses = location.children
40
40
  stores = Store.where(warehouse: warehouses)
41
41
 
42
- commodity = receipt.dispatch.dispatch_plan_item.dispatch_plan.commodity
42
+ commodity = receipt.dispatch.dispatch_plan_item.commodity
43
43
  Stack.where(commodity: commodity, store: stores)
44
44
  end
45
45
 
@@ -48,7 +48,7 @@ module Cats
48
48
  warehouses = location.children
49
49
  stores = Store.where(warehouse: warehouses)
50
50
 
51
- commodity = dispatch.dispatch_plan_item.dispatch_plan.commodity
51
+ commodity = dispatch.dispatch_plan_item.commodity
52
52
  Stack.where(commodity: commodity, store: stores)
53
53
  end
54
54
  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]
@@ -136,7 +137,7 @@ Cats::Core::Engine.routes.draw do
136
137
 
137
138
  get '/stores/:id/stacks', controller: :stacks, action: :index, as: :stacks_store
138
139
  post '/stores/:id/stacks', controller: :stacks, action: :filter
139
- get '/stacks/commodity_for_location', controller: :stacks, action: :commodity_for_location, as: :commodity_for_location
140
+ get '/stacks/items_for_location', controller: :stacks, action: :items_for_location, as: :items_for_location
140
141
  get '/receipts/:id/stacks', controller: :stacks, action: :receipt_stacks, as: :receipt_stacks
141
142
  get '/dispatches/:id/stacks', controller: :stacks, action: :dispatch_stacks, as: :dispatch_stacks
142
143
  resources :stacks, only: %i[show index create update]
@@ -6,11 +6,6 @@ class CreateCatsCoreDispatchPlans < ActiveRecord::Migration[6.1]
6
6
  t.string :status, null: false, default: 'Draft'
7
7
  t.references :dispatchable, polymorphic: true
8
8
  t.boolean :upstream, null: false, default: false
9
- t.references :commodity,
10
- null: false,
11
- index: { name: 'commodity_on_dp_indx' },
12
- foreign_key: { to_table: :cats_core_commodities }
13
-
14
9
  t.references :prepared_by,
15
10
  null: false,
16
11
  index: { name: 'pb_on_dp_indx' },
@@ -13,6 +13,10 @@ class CreateCatsCoreDispatchPlanItems < ActiveRecord::Migration[6.1]
13
13
  null: false,
14
14
  index: { name: 'dpi_on_destination_indx'},
15
15
  foreign_key: { to_table: :cats_core_locations }
16
+ t.references :commodity,
17
+ null: false,
18
+ index: { name: 'commodity_on_dpi_indx' },
19
+ foreign_key: { to_table: :cats_core_commodities }
16
20
  t.float :quantity, null: false
17
21
  t.string :commodity_status, null: false, default: 'Good'
18
22
  t.string :status, null: false, default: 'Unauthorized'
@@ -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
@@ -0,0 +1,26 @@
1
+ class CreateCatsCoreTransportRequisitions < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :cats_core_transport_requisitions do |t|
4
+ t.references :dispatch_plan,
5
+ null: false,
6
+ index: { name: 'dp_on_tr_indx' },
7
+ foreign_key: { to_table: :cats_core_dispatch_plans }
8
+ t.string :reference_no, null: false, unique: true
9
+ t.references :requested_by,
10
+ null: false,
11
+ index: { name: 'rb_on_tr_indx' },
12
+ foreign_key: { to_table: :cats_core_users }
13
+ t.references :approved_by,
14
+ null: true,
15
+ index: { name: 'ab_on_tr_indx' },
16
+ foreign_key: { to_table: :cats_core_users }
17
+ t.string :status, null: false
18
+ t.references :unit,
19
+ null: false,
20
+ index: { name: 'unit_on_tr_indx' },
21
+ foreign_key: { to_table: :cats_core_unit_of_measures }
22
+
23
+ t.timestamps
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,21 @@
1
+ class CreateCatsCoreTransportRequisitionItems < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :cats_core_transport_requisition_items do |t|
4
+ t.references :transport_requisition,
5
+ null: false,
6
+ index: { name: 'tr_on_tri_indx' },
7
+ foreign_key: { to_table: :cats_core_transport_requisitions }
8
+ t.references :dispatch_plan_item,
9
+ null: false,
10
+ index: { name: 'dpi_on_tri_indx' },
11
+ foreign_key: { to_table: :cats_core_dispatch_plan_items }
12
+ t.float :quantity, null: false
13
+ t.references :unit,
14
+ null: false,
15
+ index: { name: 'unit_on_tri_indx' },
16
+ foreign_key: { to_table: :cats_core_unit_of_measures }
17
+
18
+ t.timestamps
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,17 @@
1
+ class CreateCatsCoreTransportRequisitionDetails < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :cats_core_transport_requisition_details do |t|
4
+ t.references :transport_requisition_item,
5
+ null: false,
6
+ index: { name: 'tri_on_trd_indx'},
7
+ foreign_key: { to_table: :cats_core_transport_requisition_items }
8
+ t.float :quantity, null: false
9
+ t.references :fdp,
10
+ null: false,
11
+ index: { name: 'fdp_on_tri_indx'},
12
+ foreign_key: { to_table: :cats_core_locations }
13
+
14
+ t.timestamps
15
+ end
16
+ end
17
+ end
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.4.2'.freeze
3
+ VERSION = '1.4.5'.freeze
4
4
  end
5
5
  end
@@ -4,6 +4,7 @@ FactoryBot.define do
4
4
  destination factory: :location
5
5
  dispatch_plan
6
6
  quantity { 100 }
7
+ commodity
7
8
  commodity_status { Cats::Core::Commodity::GOOD }
8
9
  status { Cats::Core::DispatchPlanItem::UNAUTHORIZED }
9
10
  end
@@ -4,16 +4,24 @@ FactoryBot.define do
4
4
  status { Cats::Core::DispatchPlan::DRAFT }
5
5
  dispatchable { nil }
6
6
  upstream { false }
7
- commodity
8
7
  prepared_by factory: :user
9
8
  approved_by { nil }
10
9
 
11
10
  trait :with_rhn do
12
- dispatchable { create(:rhn_request) }
11
+ dispatchable do
12
+ disp = create(:rhn_request)
13
+ disp.approve
14
+ disp
15
+ end
13
16
  end
14
17
 
15
18
  trait :with_monthly_plan do
16
- dispatchable { create(:monthly_plan) }
19
+ dispatchable do
20
+ disp = create(:monthly_plan)
21
+ 3.times { create(:monthly_plan_item, monthly_plan: disp) }
22
+ disp.approve
23
+ disp
24
+ end
17
25
  end
18
26
  end
19
27
  end
@@ -6,23 +6,28 @@ FactoryBot.define do
6
6
  ancestry { nil }
7
7
  end
8
8
 
9
- factory :hub, parent: :location, class: 'Cats::Core::Location' do
10
- location_type { Cats::Core::Location::HUB }
9
+ factory :zone, parent: :location, class: 'Cats::Core::Location' do
10
+ location_type { Cats::Core::Location::ZONE }
11
11
  parent
12
12
  end
13
13
 
14
- factory :warehouse, parent: :location, class: 'Cats::Core::Location' do
15
- location_type { Cats::Core::Location::WAREHOUSE }
14
+ factory :woreda, parent: :location, class: 'Cats::Core::Location' do
15
+ location_type { Cats::Core::Location::WOREDA }
16
16
  parent
17
17
  end
18
18
 
19
- factory :woreda, parent: :location, class: 'Cats::Core::Location' do
20
- location_type { Cats::Core::Location::WOREDA }
19
+ factory :fdp, parent: :woreda, class: 'Cats::Core::Location' do
20
+ location_type { Cats::Core::Location::FDP }
21
21
  parent
22
22
  end
23
23
 
24
- factory :zone, parent: :location, class: 'Cats::Core::Location' do
25
- location_type { Cats::Core::Location::ZONE }
24
+ factory :hub, parent: :location, class: 'Cats::Core::Location' do
25
+ location_type { Cats::Core::Location::HUB }
26
+ parent
27
+ end
28
+
29
+ factory :warehouse, parent: :location, class: 'Cats::Core::Location' do
30
+ location_type { Cats::Core::Location::WAREHOUSE }
26
31
  parent
27
32
  end
28
33
  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 :transport_requisition_detail, class: 'Cats::Core::TransportRequisitionDetail' do
3
+ transport_requisition_item
4
+ quantity { 50 }
5
+ fdp factory: :fdp
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ FactoryBot.define do
2
+ factory :transport_requisition_item, class: 'Cats::Core::TransportRequisitionItem' do
3
+ transport_requisition
4
+ dispatch_plan_item
5
+ quantity { 100 }
6
+ unit factory: :unit_of_measure
7
+ end
8
+ end
@@ -0,0 +1,10 @@
1
+ FactoryBot.define do
2
+ factory :transport_requisition, class: 'Cats::Core::TransportRequisition' do
3
+ dispatch_plan
4
+ reference_no { FFaker::Name.name }
5
+ requested_by factory: :user
6
+ approved_by factory: :user
7
+ status { Cats::Core::TransportRequisition::DRAFT }
8
+ unit factory: :unit_of_measure
9
+ end
10
+ 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.5
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
@@ -308,7 +309,11 @@ files:
308
309
  - app/models/cats/core/transport_offer.rb
309
310
  - app/models/cats/core/transport_plan.rb
310
311
  - app/models/cats/core/transport_plan_item.rb
312
+ - app/models/cats/core/transport_requisition.rb
313
+ - app/models/cats/core/transport_requisition_detail.rb
314
+ - app/models/cats/core/transport_requisition_item.rb
311
315
  - app/models/cats/core/transporter.rb
316
+ - app/models/cats/core/unit_conversion.rb
312
317
  - app/models/cats/core/unit_of_measure.rb
313
318
  - app/models/cats/core/user.rb
314
319
  - app/models/concerns/cats/core/dispatchable.rb
@@ -332,6 +337,7 @@ files:
332
337
  - app/serializers/cats/core/route_serializer.rb
333
338
  - app/serializers/cats/core/stack_serializer.rb
334
339
  - app/serializers/cats/core/transporter_serializer.rb
340
+ - app/serializers/cats/core/unit_conversion_serializer.rb
335
341
  - app/serializers/cats/core/unit_of_measure_serializer.rb
336
342
  - app/serializers/cats/core/user_serializer.rb
337
343
  - app/services/cats/core/dispatch_plan_service.rb
@@ -400,6 +406,10 @@ files:
400
406
  - db/migrate/20220107125025_create_cats_core_monthly_plan_items.rb
401
407
  - db/migrate/20220107132433_create_cats_core_monthly_plan_item_details.rb
402
408
  - db/migrate/20220209083928_create_cats_core_hub_authorizations.rb
409
+ - db/migrate/20220416143416_create_cats_core_unit_conversions.rb
410
+ - db/migrate/20220417105839_create_cats_core_transport_requisitions.rb
411
+ - db/migrate/20220417123835_create_cats_core_transport_requisition_items.rb
412
+ - db/migrate/20220417151821_create_cats_core_transport_requisition_details.rb
403
413
  - lib/cats/core.rb
404
414
  - lib/cats/core/engine.rb
405
415
  - lib/cats/core/version.rb
@@ -456,7 +466,11 @@ files:
456
466
  - spec/factories/cats/core/transport_offers.rb
457
467
  - spec/factories/cats/core/transport_plan_items.rb
458
468
  - spec/factories/cats/core/transport_plans.rb
469
+ - spec/factories/cats/core/transport_requisition_details.rb
470
+ - spec/factories/cats/core/transport_requisition_items.rb
471
+ - spec/factories/cats/core/transport_requisitions.rb
459
472
  - spec/factories/cats/core/transporters.rb
473
+ - spec/factories/cats/core/unit_conversions.rb
460
474
  - spec/factories/cats/core/unit_of_measures.rb
461
475
  - spec/factories/cats/core/users.rb
462
476
  homepage: http://cats.ndrmcapps.org
@@ -482,7 +496,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
482
496
  - !ruby/object:Gem::Version
483
497
  version: '0'
484
498
  requirements: []
485
- rubygems_version: 3.3.3
499
+ rubygems_version: 3.3.7
486
500
  signing_key:
487
501
  specification_version: 4
488
502
  summary: Core module for CATS applications