cats_core 1.4.3 → 1.4.4

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: e2624794cc9a3787caefb212037b9f33f8964e9d5512fcc40a7dbb31fa129009
4
- data.tar.gz: 0f2d9b94ca4dc8794fe89928449b6c26cac67a78e2ffffadfa5be8d49baef52c
3
+ metadata.gz: 05ec37047a728927e68df2e0a0ae34dd16cca869cfe658314ea5fb0738ae894b
4
+ data.tar.gz: 272f1c6cb33e96a8407cab42c3b9bd8b01540156feee9bf4d6012b5b97600b52
5
5
  SHA512:
6
- metadata.gz: c0f3fc9431f4b011ca5015f9bf288627b51b547d79323e48d1f0221baae4781766b63ab521c23652feda8cd2fefb7f17a2242166ace64875cf4418138dc37c54
7
- data.tar.gz: c9b0ec89851d48c0fcc9338dd749364d4a1a66e0a4291085c59f70b73605f5b47b4831cbfd03d01683f0b1ed829309247069f0878b6bc199cf2791936e416978
6
+ metadata.gz: 19a5247f29b37ca8dc8a0176719b22b924069166168ddcf684a84ca0bcbd45ae170a164516ffada4cb2066b428ece538f89c8daa45bfb2db15bd432fb9676dab
7
+ data.tar.gz: b41ed1c8028112b527cd21b01821187260ba85ab2647fe7f477422a69f40a72420aed74d6741d3525f5812d110354b85bc12cf23b54163ce921286be1d185e10
@@ -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
 
@@ -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
 
@@ -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)
@@ -11,6 +11,7 @@ module Cats
11
11
  validates :transport_plan_item_id, uniqueness: true
12
12
 
13
13
  delegate(:reference_no, to: :transport_bid, prefix: true)
14
+ delegate(:abbreviation, to: :unit, prefix: true)
14
15
 
15
16
  def route
16
17
  transport_plan_item.route.name
@@ -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
@@ -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
@@ -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
@@ -137,7 +137,7 @@ Cats::Core::Engine.routes.draw do
137
137
 
138
138
  get '/stores/:id/stacks', controller: :stacks, action: :index, as: :stacks_store
139
139
  post '/stores/:id/stacks', controller: :stacks, action: :filter
140
- 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
141
141
  get '/receipts/:id/stacks', controller: :stacks, action: :receipt_stacks, as: :receipt_stacks
142
142
  get '/dispatches/:id/stacks', controller: :stacks, action: :dispatch_stacks, as: :dispatch_stacks
143
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'
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.4.3'.freeze
3
+ VERSION = '1.4.4'.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,7 +4,6 @@ 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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cats_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.3
4
+ version: 1.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.