cats_core 1.2.2 → 1.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/cats/core/dispatch_plan_items_controller.rb +18 -0
  3. data/app/controllers/cats/core/dispatch_plans_controller.rb +26 -0
  4. data/app/controllers/cats/core/dispatches_controller.rb +6 -6
  5. data/app/models/cats/core/dispatch.rb +9 -9
  6. data/app/models/cats/core/dispatch_plan.rb +24 -0
  7. data/app/models/cats/core/dispatch_plan_item.rb +20 -0
  8. data/app/models/cats/core/transport_service_offer.rb +10 -0
  9. data/app/models/cats/core/transport_service_request.rb +16 -0
  10. data/app/models/cats/core/transport_service_request_item.rb +10 -0
  11. data/app/notifications/cats/core/dispatch_notification.rb +5 -5
  12. data/app/serializers/cats/core/dispatch_plan_item_serializer.rb +8 -0
  13. data/app/serializers/cats/core/dispatch_plan_serializer.rb +7 -0
  14. data/app/serializers/cats/core/dispatch_serializer.rb +4 -3
  15. data/app/services/cats/core/dispatch_plan_service.rb +7 -0
  16. data/app/services/cats/core/dispatch_service.rb +16 -14
  17. data/config/routes.rb +13 -3
  18. data/db/migrate/20210718043328_create_cats_core_dispatch_plans.rb +13 -0
  19. data/db/migrate/20210718043401_create_cats_core_dispatch_plan_items.rb +25 -0
  20. data/db/migrate/20210718045516_create_cats_core_dispatches.rb +3 -3
  21. data/db/migrate/20211209155113_create_cats_core_transport_service_requests.rb +19 -0
  22. data/db/migrate/20211209155915_create_cats_core_transport_service_request_items.rb +24 -0
  23. data/db/migrate/20211209160126_create_cats_core_transport_service_offers.rb +17 -0
  24. data/lib/cats/core/version.rb +1 -1
  25. data/spec/factories/cats/core/dispatch_plan_items.rb +9 -0
  26. data/spec/factories/cats/core/dispatch_plans.rb +8 -0
  27. data/spec/factories/cats/core/dispatches.rb +4 -5
  28. data/spec/factories/cats/core/transport_service_offers.rb +7 -0
  29. data/spec/factories/cats/core/transport_service_request_items.rb +8 -0
  30. data/spec/factories/cats/core/transport_service_requests.rb +8 -0
  31. metadata +24 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa114e4773fb08fcaa761ebcc584caa4e6314e321e04d66fecccf107af2c72b9
4
- data.tar.gz: bb57609da9d647843d17ddfa11e9b9fbbdbe116e35c624fb36a769cafa203dd9
3
+ metadata.gz: b102951859559bc96354a41e5dd05582209632d2394b86ba3916100374594706
4
+ data.tar.gz: b9f1ea8526f5bca4776f32e7c3a16f6dee1b32ce460e4975eebd693b00d941a9
5
5
  SHA512:
6
- metadata.gz: e1e019180bc325929319cf7e014db073015f9db04f322f904edc436ee17798df1dea5533b8d8f9758b617e60de2d5bc5d3c3fc8741b44b24b062330758389791
7
- data.tar.gz: e4221dc2d453f8454ecb8f4cab23757b277dbb18e4f6802abba7463908997227e18298ac6e1add7deae5e932aa3b06c67c4cffa2b9d5ea4d0d35f494c7bc55ab
6
+ metadata.gz: 196b1372ef0c79666b491dfc63deedee8c624ae774ee12ef14894f94471be09a6b595ca1e0a483eea5ad01e9a6afb20652aa884adaf7bf383c82be0b270e3537
7
+ data.tar.gz: 8e3264080cc5cdfbab53447fc1eb59e7c6354433053d60484b0e056051aeeb35e0961f6dbc91d38a66b5cd5aa76895092cc343b1c8e37ff70c96b913e0ddb7ab
@@ -0,0 +1,18 @@
1
+ module Cats
2
+ module Core
3
+ class DispatchPlanItemsController < ApplicationController
4
+ include Common
5
+
6
+ def index
7
+ items = Cats::Core::DispatchPlanItem.where(dispatch_plan_id: params[:id])
8
+ render json: { success: true, data: serialize(items) }
9
+ end
10
+
11
+ private
12
+
13
+ def model_params
14
+ params.require(:payload).permit(:dispatch_plan_id, :source_id, :destination_id, :quantity, :commodity_id)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,26 @@
1
+ module Cats
2
+ module Core
3
+ class DispatchPlansController < ApplicationController
4
+ include Common
5
+
6
+ def filter
7
+ query = Cats::Core::DispatchPlan.ransack(params[:q])
8
+ render json: { success: true, data: serialize(query.result) }
9
+ end
10
+
11
+ def approve
12
+ plan = Cats::Core::DispatchPlan.find(params[:id])
13
+ plan.approve
14
+ render json: { success: true, data: serialize(plan) }
15
+ rescue StandardError => e
16
+ render json: { success: false, error: e.message }
17
+ end
18
+
19
+ private
20
+
21
+ def model_params
22
+ params.require(:payload).permit(:reference_no, :request_id)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -7,7 +7,7 @@ module Cats
7
7
  before_action :set_dispatch, only: %i[approve start confirm commodity]
8
8
 
9
9
  def index
10
- dispatches = Cats::Core::Dispatch.where(allocation_item_id: params[:id])
10
+ dispatches = Cats::Core::Dispatch.where(dispatch_plan_item_id: params[:id])
11
11
  render json: { success: true, data: serialize(dispatches) }
12
12
  end
13
13
 
@@ -23,9 +23,9 @@ module Cats
23
23
  end
24
24
 
25
25
  def create_receipt_authorization
26
- allocation_item = Cats::Core::AllocationItem.find(params[:id])
26
+ item = Cats::Core::DispatchPlanItem.find(params[:id])
27
27
  dispatch = @service.create_receipt_authorization(
28
- params[:reference_no], allocation_item, params[:quantity], params[:remark], current_user
28
+ params[:reference_no], item, params[:quantity], params[:remark], current_user
29
29
  )
30
30
  render json: { success: true, data: serialize(dispatch) }
31
31
  end
@@ -57,7 +57,7 @@ module Cats
57
57
  end
58
58
 
59
59
  def commodity
60
- data = @dispatch.allocation_item.allocation.commodity
60
+ data = @dispatch.dispatch_plan_item.commodity
61
61
  render json: { success: true, data: serialize(data) }
62
62
  end
63
63
 
@@ -72,8 +72,8 @@ module Cats
72
72
  end
73
73
 
74
74
  def model_params
75
- params.require(:payload).permit(:reference_no, :allocation_item_id, :transporter_id, :plate_no, :driver_name,
76
- :driver_phone, :quantity, :remark)
75
+ params.require(:payload).permit(:reference_no, :dispatch_plan_item_id, :transporter_id, :plate_no,
76
+ :driver_name, :driver_phone, :quantity, :remark)
77
77
  end
78
78
  end
79
79
  end
@@ -12,7 +12,7 @@ module Cats
12
12
 
13
13
  belongs_to :prepared_by, class_name: 'Cats::Core::User'
14
14
  belongs_to :transporter
15
- belongs_to :allocation_item
15
+ belongs_to :dispatch_plan_item
16
16
  has_many :receipts
17
17
 
18
18
  validates :reference_no, :plate_no, :driver_name, :driver_phone, :quantity, :commodity_status, presence: true
@@ -20,27 +20,27 @@ module Cats
20
20
  validates :reference_no, uniqueness: true
21
21
  validates :quantity, numericality: { greater_than: 0 }
22
22
  validates :commodity_status, inclusion: { in: Cats::Core::Commodity::COMMODITY_STATUSES }
23
- validate :validate_quantity, :validate_allocation_status
23
+ validate :validate_quantity, :validate_dispatch_plan_status
24
24
 
25
25
  delegate(:name, to: :transporter, prefix: true)
26
26
  delegate(:email, to: :prepared_by, prefix: true)
27
27
 
28
28
  def validate_quantity
29
- return unless quantity && allocation_item
29
+ return unless quantity && dispatch_plan_item
30
30
 
31
31
  return unless quantity_changed?
32
32
 
33
- dispatched = Dispatch.where(allocation_item: allocation_item).sum(:quantity)
34
- remaining = allocation_item.quantity - dispatched
33
+ dispatched = dispatch_plan_item.dispatches.sum(:quantity)
34
+ remaining = dispatch_plan_item.quantity - dispatched
35
35
  remaining += quantity_was if quantity_was
36
36
  errors.add(:quantity, "exceeds allocated quantity. Maximum allowed is #{remaining}") if quantity > remaining
37
37
  end
38
38
 
39
- def validate_allocation_status
40
- return unless allocation_item
39
+ def validate_dispatch_plan_status
40
+ return unless dispatch_plan_item
41
41
 
42
- status = allocation_item.allocation.allocation_status
43
- errors.add(:allocation_item, 'should be approved first.') unless status == Allocation::APPROVED
42
+ status = dispatch_plan_item.dispatch_plan.status
43
+ errors.add(:dispatch_plan, 'should be approved first.') unless status == DispatchPlan::APPROVED
44
44
  end
45
45
 
46
46
  def approve
@@ -0,0 +1,24 @@
1
+ module Cats
2
+ module Core
3
+ class DispatchPlan < ApplicationRecord
4
+ DRAFT = 'Draft'.freeze
5
+ APPROVED = 'Approved'.freeze
6
+ STATUSES = [DRAFT, APPROVED].freeze
7
+
8
+ belongs_to :request, polymorphic: true, optional: true
9
+ has_many :dispatch_plan_items
10
+
11
+ validates :reference_no, presence: true, uniqueness: true
12
+ validates :status, inclusion: { in: STATUSES }
13
+
14
+ def approve
15
+ raise(StandardError, 'Dispatch plan already approved.') if status == APPROVED
16
+
17
+ raise(StandardError, 'Dispatch plan is empty.') if dispatch_plan_items.count.zero?
18
+
19
+ self.status = APPROVED
20
+ save!
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,20 @@
1
+ module Cats
2
+ module Core
3
+ class DispatchPlanItem < ApplicationRecord
4
+ belongs_to :commodity
5
+ belongs_to :source, class_name: 'Cats::Core::Location'
6
+ belongs_to :destination, class_name: 'Cats::Core::Location'
7
+ belongs_to :dispatch_plan
8
+ has_many :dispatches
9
+
10
+ validates :quantity, presence: true, numericality: { greater_than: 0 }
11
+
12
+ delegate(:reference_no, to: :dispatch_plan, prefix: :plan, allow_nil: true)
13
+ delegate(:batch_no, to: :commodity, prefix: true)
14
+ delegate(:name, to: :source, prefix: true)
15
+ delegate(:name, to: :destination, prefix: true)
16
+ delegate(:location_type, to: :source, prefix: true)
17
+ delegate(:location_type, to: :destination, prefix: true)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,10 @@
1
+ module Cats
2
+ module Core
3
+ class TransportServiceOffer < ApplicationRecord
4
+ belongs_to :transport_service_request_item
5
+ belongs_to :transporter
6
+
7
+ validates :price, presence: true, numericality: { greater_than: 0 }
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,16 @@
1
+ module Cats
2
+ module Core
3
+ class TransportServiceRequest < ApplicationRecord
4
+ DRAFT = 'Draft'.freeze
5
+ APPROVED = 'Approved'.freeze
6
+ STATUSES = [DRAFT, APPROVED].freeze
7
+
8
+ belongs_to :requested_by, class_name: 'Cats::Core::User'
9
+ belongs_to :approved_by, class_name: 'Cats::Core::User', optional: true
10
+
11
+ validates :reference_no, :request_date, :status, presence: true
12
+ validates :reference_no, uniqueness: true
13
+ validates :status, inclusion: { in: STATUSES }
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,10 @@
1
+ module Cats
2
+ module Core
3
+ class TransportServiceRequestItem < ApplicationRecord
4
+ belongs_to :transport_service_request
5
+ belongs_to :source, class_name: 'Cats::Core::Location'
6
+ belongs_to :destination, class_name: 'Cats::Core::Location'
7
+ belongs_to :commodity
8
+ end
9
+ end
10
+ end
@@ -7,15 +7,15 @@ module Cats
7
7
 
8
8
  def message
9
9
  dispatch = params[:dispatch]
10
- commodity = dispatch.allocation_item.allocation.commodity.name
11
- title = "Dispatch Notification - #{commodity}"
10
+ commodity = dispatch.dispatch_plan_item.commodity
11
+ title = "Dispatch Notification - #{commodity.name}"
12
12
  date = Date.today
13
13
  body = <<~BODY
14
14
  Commodity with the following details has been dispatched to you:
15
15
  Dispatch Ref. = #{dispatch.reference_no}
16
- Batch No. = #{dispatch.allocation_item.allocation.commodity.batch_no}
17
- Commodity = #{commodity}
18
- Allocated Quantity = #{dispatch.allocation_item.quantity}
16
+ Batch No. = #{commodity.batch_no}
17
+ Commodity = #{commodity.name}
18
+ Allocated Quantity = #{dispatch.dispatch_plan_item.quantity}
19
19
  Quantity = #{dispatch.quantity}
20
20
  Truck Plate No. = #{dispatch.plate_no}
21
21
  Driver Name = #{dispatch.driver_name}
@@ -0,0 +1,8 @@
1
+ module Cats
2
+ module Core
3
+ class DispatchPlanItemSerializer < ActiveModel::Serializer
4
+ attributes :id, :dispatch_plan_id, :plan_reference_no, :source_id, :source_name, :destination_id,
5
+ :destination_name, :quantity, :source_location_type, :destination_location_type
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ module Cats
2
+ module Core
3
+ class DispatchPlanSerializer < ActiveModel::Serializer
4
+ attributes :id, :reference_no, :status, :request_id, :upstream
5
+ end
6
+ end
7
+ end
@@ -1,11 +1,12 @@
1
1
  module Cats
2
2
  module Core
3
3
  class DispatchSerializer < ActiveModel::Serializer
4
- attributes :id, :reference_no, :allocation_item_id, :transporter_id, :transporter_name, :plate_no, :driver_name,
5
- :driver_phone, :quantity, :remark, :prepared_by_id, :prepared_by_email, :dispatch_status, :destination
4
+ attributes :id, :reference_no, :dispatch_plan_item_id, :transporter_id, :transporter_name, :plate_no,
5
+ :driver_name, :driver_phone, :quantity, :remark, :prepared_by_id, :prepared_by_email,
6
+ :dispatch_status, :destination
6
7
 
7
8
  def destination
8
- object.allocation_item.destination.name
9
+ object.dispatch_plan_item.destination.name
9
10
  end
10
11
  end
11
12
  end
@@ -0,0 +1,7 @@
1
+ class DispatchPlanService
2
+ def approve(plan)
3
+ plan.approve
4
+ send_notification(plan)
5
+ plan
6
+ end
7
+ end
@@ -1,14 +1,16 @@
1
1
  module Cats
2
2
  module Core
3
3
  class DispatchService
4
- def create_receipt_authorization(reference_no, allocation_item, quantity, remark, user)
4
+ def create_receipt_authorization(reference_no, plan_item, quantity, remark, user)
5
+ raise(StandardError, 'Dispatch plan is not an upstream plan.') unless plan_item.dispatch_plan.upstream?
6
+
5
7
  transporter = Cats::Core::Transporter.find_by(code: 'SUP-TRANS')
6
8
  raise(StandardError, 'Supplier transporter does not exist.') unless transporter
7
9
 
8
10
  store = Cats::Core::Store.find_by(code: 'SUP-STORE')
9
11
  raise(StandardError, 'Supplier store does not exist.') unless store
10
12
 
11
- commodity = allocation_item.allocation.commodity
13
+ commodity = plan_item.commodity
12
14
  stack = store.stacks.find_by(commodity: commodity)
13
15
 
14
16
  raise(StandardError, 'Commodity not found in supplier store.') unless stack
@@ -17,7 +19,7 @@ module Cats
17
19
  ApplicationRecord.transaction do
18
20
  dispatch = Cats::Core::Dispatch.create!(
19
21
  reference_no: reference_no,
20
- allocation_item: allocation_item,
22
+ dispatch_plan_item: plan_item,
21
23
  transporter: transporter,
22
24
  plate_no: 'Supplier plate no',
23
25
  driver_name: 'Supplier driver',
@@ -51,36 +53,36 @@ module Cats
51
53
  warehouse = Cats::Core::Store.find(details['stores'][0]).warehouse
52
54
  hub = warehouse.parent
53
55
 
54
- dispatches = Cats::Core::Dispatch.joins(:allocation_item)
56
+ dispatches = Cats::Core::Dispatch.joins(:dispatch_plan_item)
55
57
  .where(
56
- allocation_item: { destination: hub },
58
+ dispatch_plan_item: { destination: hub },
57
59
  dispatch_status: status
58
60
  ).or(
59
- Cats::Core::Dispatch.joins(:allocation_item)
61
+ Cats::Core::Dispatch.joins(:dispatch_plan_item)
60
62
  .where(
61
- allocation_item: { destination: warehouse },
63
+ dispatch_plan_item: { destination: warehouse },
62
64
  dispatch_status: status
63
65
  )
64
66
  )
65
67
  elsif details['warehouse']
66
68
  warehouse = Cats::Core::Location.find(details['warehouse'])
67
69
  hub = warehouse.parent
68
- dispatches = Cats::Core::Dispatch.joins(:allocation_item)
70
+ dispatches = Cats::Core::Dispatch.joins(:dispatch_plan_item)
69
71
  .where(
70
- allocation_item: { destination: hub },
72
+ dispatch_plan_item: { destination: hub },
71
73
  dispatch_status: status
72
74
  ).or(
73
- Cats::Core::Dispatch.joins(:allocation_item)
75
+ Cats::Core::Dispatch.joins(:dispatch_plan_item)
74
76
  .where(
75
- allocation_item: { destination: warehouse },
77
+ dispatch_plan_item: { destination: warehouse },
76
78
  dispatch_status: status
77
79
  )
78
80
  )
79
81
  elsif details['hub']
80
82
  hub = Cats::Core::Location.find(details['hub'])
81
- dispatches = Cats::Core::Dispatch.joins(:allocation_item)
83
+ dispatches = Cats::Core::Dispatch.joins(:dispatch_plan_item)
82
84
  .where(
83
- allocation_item: { destination: hub },
85
+ dispatch_plan_item: { destination: hub },
84
86
  dispatch_status: status
85
87
  )
86
88
  end
@@ -98,7 +100,7 @@ module Cats
98
100
  raise(StandardError, 'Notification rule not found for dispatch notification.') unless notification_rule
99
101
 
100
102
  users = Cats::Core::User.joins(:roles).where(cats_core_roles: { name: notification_rule.roles })
101
- location_id = dispatch.allocation_item.destination_id
103
+ location_id = dispatch.dispatch_plan_item.destination_id
102
104
  recipients = users.map do |user|
103
105
  details = user.details
104
106
  if (details.key?('warehouse') && details['warehouse'] == location_id) ||
data/config/routes.rb CHANGED
@@ -66,11 +66,21 @@ Cats::Core::Engine.routes.draw do
66
66
  resources :currencies, except: %i[destroy]
67
67
  resources :unit_of_measures, except: %i[destroy]
68
68
 
69
- get '/allocation_items/:id/dispatches', controller: :dispatches, action: :index, as: :dispatches_allocation_item
70
- post '/allocation_items/:id/receipt_authorizaton',
69
+ post '/dispatch_plans/filter', controller: :dispatch_plans, action: :filter
70
+ resources :dispatch_plans do
71
+ member do
72
+ get 'items', controller: :dispatch_plan_items, action: :index
73
+ post 'approve'
74
+ end
75
+ end
76
+
77
+ resources :dispatch_plan_items, except: %i[index destroy]
78
+
79
+ get '/dispatch_plan_items/:id/dispatches', controller: :dispatches, action: :index, as: :dispatches_plan_item
80
+ post '/dispatch_plan_items/:id/receipt_authorizaton',
71
81
  controller: :dispatches,
72
82
  action: :create_receipt_authorization,
73
- as: :receipt_authorization_allocation_item
83
+ as: :receipt_authorization_plan_item
74
84
 
75
85
  get '/dispatches/search', controller: :dispatches, action: :search, as: :search_dispatches
76
86
  resources :dispatches, except: %i[index destroy] do
@@ -0,0 +1,13 @@
1
+ class CreateCatsCoreDispatchPlans < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :cats_core_dispatch_plans do |t|
4
+ t.string :reference_no, unique: true
5
+ t.string :description
6
+ t.string :status, null: false, default: 'Draft'
7
+ t.references :request, polymorphic: true
8
+ t.boolean :upstream, null: false, default: false
9
+
10
+ t.timestamps
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,25 @@
1
+ class CreateCatsCoreDispatchPlanItems < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :cats_core_dispatch_plan_items do |t|
4
+ t.references :dispatch_plan,
5
+ null: false,
6
+ index: { name: 'dpi_on_dp_indx' },
7
+ foreign_key: { to_table: :cats_core_dispatch_plans }
8
+ t.references :commodity,
9
+ null: false,
10
+ index: { name: 'dpi_on_commodity_indx' },
11
+ foreign_key: { to_table: :cats_core_commodities }
12
+ t.references :source,
13
+ null: false,
14
+ index: { name: 'dpi_on_source_indx' },
15
+ foreign_key: { to_table: :cats_core_locations }
16
+ t.references :destination,
17
+ null: false,
18
+ index: { name: 'dpi_on_destination_indx'},
19
+ foreign_key: { to_table: :cats_core_locations }
20
+ t.float :quantity, null: false
21
+
22
+ t.timestamps
23
+ end
24
+ end
25
+ end
@@ -2,10 +2,10 @@ class CreateCatsCoreDispatches < ActiveRecord::Migration[6.1]
2
2
  def change
3
3
  create_table :cats_core_dispatches do |t|
4
4
  t.string :reference_no, unique: true
5
- t.references :allocation_item,
5
+ t.references :dispatch_plan_item,
6
6
  null: false,
7
- index: { name: 'ai_on_dispatches_indx' },
8
- foreign_key: { to_table: :cats_core_allocation_items }
7
+ index: { name: 'dpi_on_dispatches_indx' },
8
+ foreign_key: { to_table: :cats_core_dispatch_plan_items }
9
9
  t.references :transporter,
10
10
  null: false,
11
11
  index: { name: 'transporter_on_dispatches_indx' },
@@ -0,0 +1,19 @@
1
+ class CreateCatsCoreTransportServiceRequests < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :cats_core_transport_service_requests do |t|
4
+ t.string :reference_no, unique: true
5
+ t.date :request_date, null: false
6
+ t.string :status, null: false, default: 'Draft'
7
+ t.references :requested_by,
8
+ null: false,
9
+ index: { name: 'tsr_on_rb_indx' },
10
+ foreign_key: { to_table: :cats_core_users }
11
+ t.references :approved_by,
12
+ null: true,
13
+ index: { name: 'tsr_on_ab_indx' },
14
+ foreign_key: { to_table: :cats_core_users }
15
+
16
+ t.timestamps
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,24 @@
1
+ class CreateCatsCoreTransportServiceRequestItems < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :cats_core_transport_service_request_items do |t|
4
+ t.references :transport_service_request,
5
+ null: false,
6
+ index: { name: 'tsri_on_tsr_indx' },
7
+ foreign_key: { to_table: :cats_core_transport_service_requests }
8
+ t.references :source,
9
+ null: false,
10
+ index: { name: 'tsri_on_source_indx' },
11
+ foreign_key: { to_table: :cats_core_locations }
12
+ t.references :destination,
13
+ null: false,
14
+ index: { name: 'tsri_on_destination_indx'},
15
+ foreign_key: { to_table: :cats_core_locations }
16
+ t.references :commodity,
17
+ null: false,
18
+ index: { name: 'tsri_on_commodity_indx' },
19
+ foreign_key: { to_table: :cats_core_commodities }
20
+
21
+ t.timestamps
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,17 @@
1
+ class CreateCatsCoreTransportServiceOffers < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :cats_core_transport_service_offers do |t|
4
+ t.references :transport_service_request_item,
5
+ null: false,
6
+ index: { name: 'tso_on_tsri_indx' },
7
+ foreign_key: { to_table: :cats_core_transport_service_request_items }
8
+ t.references :transporter,
9
+ null: false,
10
+ index: { name: 'tso_on_transporter_indx' },
11
+ foreign_key: { to_table: :cats_core_transporters }
12
+ t.float :price, null: false
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.2.2'.freeze
3
+ VERSION = '1.2.6'.freeze
4
4
  end
5
5
  end
@@ -0,0 +1,9 @@
1
+ FactoryBot.define do
2
+ factory :dispatch_plan_item, class: 'Cats::Core::DispatchPlanItem' do
3
+ commodity
4
+ source factory: :location
5
+ destination factory: :location
6
+ dispatch_plan
7
+ quantity { 100 }
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ FactoryBot.define do
2
+ factory :dispatch_plan, class: 'Cats::Core::DispatchPlan' do
3
+ reference_no { FFaker::Name.name }
4
+ status { Cats::Core::DispatchPlan::DRAFT }
5
+ request { nil }
6
+ upstream { false }
7
+ end
8
+ end
@@ -1,11 +1,10 @@
1
1
  FactoryBot.define do
2
2
  factory :dispatch, class: 'Cats::Core::Dispatch' do
3
3
  reference_no { FFaker::Name.name }
4
- allocation_item do
5
- allocation = create(:allocation, quantity: 100)
6
- allocation_item = create(:allocation_item, allocation: allocation, quantity: 100)
7
- allocation.approve
8
- allocation_item
4
+ dispatch_plan_item do
5
+ plan_item = create(:dispatch_plan_item, quantity: 100)
6
+ plan_item.dispatch_plan.approve
7
+ plan_item
9
8
  end
10
9
  transporter
11
10
  plate_no { FFaker::Name.name }
@@ -0,0 +1,7 @@
1
+ FactoryBot.define do
2
+ factory :transport_service_offer, class: 'Cats::Core::TransportServiceOffer' do
3
+ transport_service_request_item
4
+ transporter
5
+ price { 100 }
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ FactoryBot.define do
2
+ factory :transport_service_request_item, class: 'Cats::Core::TransportServiceRequestItem' do
3
+ transport_service_request
4
+ source factory: :location
5
+ destination factory: :location
6
+ commodity
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ FactoryBot.define do
2
+ factory :transport_service_request, class: 'Cats::Core::TransportServiceRequest' do
3
+ reference_no { FFaker::Name.name }
4
+ request_date { Date.today }
5
+ requested_by factory: :user
6
+ approved_by factory: :user
7
+ end
8
+ 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.2.2
4
+ version: 1.2.6
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-11-12 00:00:00.000000000 Z
11
+ date: 2021-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 2.2.3
61
+ version: 2.3.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 2.2.3
68
+ version: 2.3.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: noticed
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -234,6 +234,8 @@ files:
234
234
  - app/controllers/cats/core/application_controller.rb
235
235
  - app/controllers/cats/core/commodity_categories_controller.rb
236
236
  - app/controllers/cats/core/currencies_controller.rb
237
+ - app/controllers/cats/core/dispatch_plan_items_controller.rb
238
+ - app/controllers/cats/core/dispatch_plans_controller.rb
237
239
  - app/controllers/cats/core/dispatch_transactions_controller.rb
238
240
  - app/controllers/cats/core/dispatches_controller.rb
239
241
  - app/controllers/cats/core/locations_controller.rb
@@ -255,6 +257,8 @@ files:
255
257
  - app/models/cats/core/commodity_category.rb
256
258
  - app/models/cats/core/currency.rb
257
259
  - app/models/cats/core/dispatch.rb
260
+ - app/models/cats/core/dispatch_plan.rb
261
+ - app/models/cats/core/dispatch_plan_item.rb
258
262
  - app/models/cats/core/dispatch_transaction.rb
259
263
  - app/models/cats/core/donation.rb
260
264
  - app/models/cats/core/donor.rb
@@ -283,6 +287,9 @@ files:
283
287
  - app/models/cats/core/store.rb
284
288
  - app/models/cats/core/supplier.rb
285
289
  - app/models/cats/core/transaction.rb
290
+ - app/models/cats/core/transport_service_offer.rb
291
+ - app/models/cats/core/transport_service_request.rb
292
+ - app/models/cats/core/transport_service_request_item.rb
286
293
  - app/models/cats/core/transporter.rb
287
294
  - app/models/cats/core/unit_of_measure.rb
288
295
  - app/models/cats/core/user.rb
@@ -292,6 +299,8 @@ files:
292
299
  - app/serializers/cats/core/commodity_category_serializer.rb
293
300
  - app/serializers/cats/core/commodity_serializer.rb
294
301
  - app/serializers/cats/core/currency_serializer.rb
302
+ - app/serializers/cats/core/dispatch_plan_item_serializer.rb
303
+ - app/serializers/cats/core/dispatch_plan_serializer.rb
295
304
  - app/serializers/cats/core/dispatch_serializer.rb
296
305
  - app/serializers/cats/core/dispatch_transaction_serializer.rb
297
306
  - app/serializers/cats/core/location_serializer.rb
@@ -301,6 +310,7 @@ files:
301
310
  - app/serializers/cats/core/role_serializer.rb
302
311
  - app/serializers/cats/core/unit_of_measure_serializer.rb
303
312
  - app/serializers/cats/core/user_serializer.rb
313
+ - app/services/cats/core/dispatch_plan_service.rb
304
314
  - app/services/cats/core/dispatch_service.rb
305
315
  - app/services/cats/core/menu_service.rb
306
316
  - app/services/cats/core/notification_service.rb
@@ -337,6 +347,8 @@ files:
337
347
  - db/migrate/20210718042755_create_cats_core_rhn_requests.rb
338
348
  - db/migrate/20210718042823_create_cats_core_allocations.rb
339
349
  - db/migrate/20210718043204_create_cats_core_allocation_items.rb
350
+ - db/migrate/20210718043328_create_cats_core_dispatch_plans.rb
351
+ - db/migrate/20210718043401_create_cats_core_dispatch_plan_items.rb
340
352
  - db/migrate/20210718045516_create_cats_core_dispatches.rb
341
353
  - db/migrate/20210718202957_create_cats_core_dispatch_transactions.rb
342
354
  - db/migrate/20210719133710_create_cats_core_stacking_rules.rb
@@ -347,6 +359,9 @@ files:
347
359
  - db/migrate/20211002050739_create_cats_core_notification_rules.rb
348
360
  - db/migrate/20211024063240_add_status_to_cats_core_rhn_requests.rb
349
361
  - db/migrate/20211030133752_add_status_to_cats_core_commodities.rb
362
+ - db/migrate/20211209155113_create_cats_core_transport_service_requests.rb
363
+ - db/migrate/20211209155915_create_cats_core_transport_service_request_items.rb
364
+ - db/migrate/20211209160126_create_cats_core_transport_service_offers.rb
350
365
  - lib/cats/core.rb
351
366
  - lib/cats/core/engine.rb
352
367
  - lib/cats/core/version.rb
@@ -358,6 +373,8 @@ files:
358
373
  - spec/factories/cats/core/commodities.rb
359
374
  - spec/factories/cats/core/commodity_categories.rb
360
375
  - spec/factories/cats/core/currencies.rb
376
+ - spec/factories/cats/core/dispatch_plan_items.rb
377
+ - spec/factories/cats/core/dispatch_plans.rb
361
378
  - spec/factories/cats/core/dispatch_transactions.rb
362
379
  - spec/factories/cats/core/dispatches.rb
363
380
  - spec/factories/cats/core/donations.rb
@@ -386,6 +403,9 @@ files:
386
403
  - spec/factories/cats/core/stacks.rb
387
404
  - spec/factories/cats/core/stores.rb
388
405
  - spec/factories/cats/core/suppliers.rb
406
+ - spec/factories/cats/core/transport_service_offers.rb
407
+ - spec/factories/cats/core/transport_service_request_items.rb
408
+ - spec/factories/cats/core/transport_service_requests.rb
389
409
  - spec/factories/cats/core/transporters.rb
390
410
  - spec/factories/cats/core/unit_of_measures.rb
391
411
  - spec/factories/cats/core/users.rb