cats_core 1.2.16 → 1.2.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/cats/core/routes_controller.rb +13 -0
  3. data/app/models/cats/core/contract_item.rb +13 -0
  4. data/app/models/cats/core/route.rb +18 -0
  5. data/app/models/cats/core/transport_bid.rb +21 -0
  6. data/app/models/cats/core/transport_bid_item.rb +15 -0
  7. data/app/models/cats/core/transport_contract.rb +10 -0
  8. data/app/models/cats/core/transport_offer.rb +1 -1
  9. data/app/serializers/cats/core/route_serializer.rb +7 -0
  10. data/config/routes.rb +1 -0
  11. data/db/migrate/20210718040129_create_cats_core_routes.rb +19 -0
  12. data/db/migrate/20211215121151_create_cats_core_transport_bids.rb +13 -0
  13. data/db/migrate/20211215124452_create_cats_core_transport_bid_items.rb +21 -0
  14. data/db/migrate/{20211209160126_create_cats_core_transport_offers.rb → 20211229160126_create_cats_core_transport_offers.rb} +3 -3
  15. data/db/migrate/20211229160127_create_cats_core_transport_contracts.rb +19 -0
  16. data/db/migrate/20211229160128_create_cats_core_contract_items.rb +21 -0
  17. data/lib/cats/core/version.rb +1 -1
  18. data/spec/factories/cats/core/contract_items.rb +8 -0
  19. data/spec/factories/cats/core/routes.rb +6 -0
  20. data/spec/factories/cats/core/transport_bid_items.rb +8 -0
  21. data/spec/factories/cats/core/transport_bids.rb +8 -0
  22. data/spec/factories/cats/core/transport_contracts.rb +9 -0
  23. data/spec/factories/cats/core/transport_offers.rb +1 -1
  24. metadata +20 -7
  25. data/db/migrate/20211209155113_create_cats_core_transport_requests.rb +0 -19
  26. data/db/migrate/20211209155915_create_cats_core_transport_request_items.rb +0 -24
  27. data/spec/factories/cats/core/transport_request_items.rb +0 -8
  28. data/spec/factories/cats/core/transport_requests.rb +0 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 83ed27840275615cce0b4a2fdee9d147a61407eef87df375e9db5e0424d4e923
4
- data.tar.gz: 06a77ee55dec5a1d292afeaa225b35629867d85eac43640d5073aab84b657634
3
+ metadata.gz: d7fad29c6363b9f97a6cdf998aa0af3319adb3484d6c12ac363bd17058de3d0e
4
+ data.tar.gz: 31efe7250a22930a60ad18ee7913530ef5c387b4f743e1f606fa91ab764b620d
5
5
  SHA512:
6
- metadata.gz: f57ac8ebc0d69cb0abc5e0b19a28ae3afd4b3549a72b2fe34469bf63e15bc05067fa101bc378b97f073b5650b66d21516d9ea7998d165e8e5b133d971e08dbfe
7
- data.tar.gz: 41f293dd59320cafef958b1d1dcf6b2342e2af1d696e31fb761ff50cf749966e5a993062d23f3e859c32bbb0431cba93c333b7410977be67a33c1bb8575e829a
6
+ metadata.gz: ff6fa84f59e57e8e7ffe5bfa0e1c6028ecad74a36b98cdff4b189a08fcd367a7c565bd0b7e987a76753df9516d74ba163050ee024cf7659ff0ee98bfc40105bf
7
+ data.tar.gz: 0672a380f2afef89c0ca904e27415c4286b36b13c844bcc6d7e5ac93cc767cd7fe225824a9c9116613a4601ac6dce1cbf777ac640832565311ff4ac511f34b71
@@ -0,0 +1,13 @@
1
+ module Cats
2
+ module Core
3
+ class RoutesController < ApplicationController
4
+ include Common
5
+
6
+ private
7
+
8
+ def model_params
9
+ params.require(:payload).permit(:source_id, :destination_id)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Cats
2
+ module Core
3
+ class ContractItem < ApplicationRecord
4
+ belongs_to :transport_contract
5
+ belongs_to :route
6
+ belongs_to :unit, class_name: 'Cats::Core::UnitOfMeasure'
7
+
8
+ validates :price, presence: true, numericality: { greater_than: 0 }
9
+
10
+ delegate(:name, to: :route, prefix: true)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ module Cats
2
+ module Core
3
+ class Route < ApplicationRecord
4
+ before_validation :set_name, on: %i[create update]
5
+
6
+ belongs_to :source, class_name: 'Cats::Core::Location'
7
+ belongs_to :destination, class_name: 'Cats::Core::Location'
8
+
9
+ validates :source_id, uniqueness: { scope: :destination_id }
10
+
11
+ def set_name
12
+ return unless source && destination
13
+
14
+ self.name = "#{source.name} - #{destination.name}"
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,21 @@
1
+ module Cats
2
+ module Core
3
+ class TransportBid < ApplicationRecord
4
+ NEW = 'New'.freeze
5
+ OPEN = 'Open'.freeze
6
+ CLOSED = 'Closed'.freeze
7
+ STATUSES = [NEW, OPEN, CLOSED].freeze
8
+
9
+ validates :reference_no, presence: true, uniqueness: true
10
+ validates :start_date, :end_date, :status, presence: true
11
+ validates :status, inclusion: { in: STATUSES }
12
+ validate :validate_start_date_against_end_date
13
+
14
+ def validate_start_date_against_end_date
15
+ return unless start_date && end_date
16
+
17
+ errors.add(:start_date, 'should be before end date.') if start_date >= end_date
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ module Cats
2
+ module Core
3
+ class TransportBidItem < ApplicationRecord
4
+ belongs_to :transport_bid
5
+ belongs_to :route
6
+ belongs_to :unit, class_name: 'Cats::Core::UnitOfMeasure', optional: true
7
+
8
+ has_many :transport_offers
9
+
10
+ validates :quantity, presence: true, numericality: { greater_than: 0 }
11
+
12
+ delegate(:name, to: :route, prefix: true)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ module Cats
2
+ module Core
3
+ class TransportContract < ApplicationRecord
4
+ belongs_to :region, class_name: 'Cats::Core::Location'
5
+ belongs_to :transporter
6
+
7
+ validates :contract_date, :expires_on, presence: true
8
+ end
9
+ end
10
+ end
@@ -1,7 +1,7 @@
1
1
  module Cats
2
2
  module Core
3
3
  class TransportOffer < ApplicationRecord
4
- belongs_to :transport_request_item
4
+ belongs_to :transport_bid_item
5
5
  belongs_to :transporter
6
6
 
7
7
  validates :price, presence: true, numericality: { greater_than: 0 }
@@ -0,0 +1,7 @@
1
+ module Cats
2
+ module Core
3
+ class RouteSerializer < ActiveModel::Serializer
4
+ attributes :id, :name, :source_id, :destination_id
5
+ end
6
+ end
7
+ end
data/config/routes.rb CHANGED
@@ -66,6 +66,7 @@ Cats::Core::Engine.routes.draw do
66
66
  end
67
67
  resources :currencies, except: %i[destroy]
68
68
  resources :unit_of_measures, except: %i[destroy]
69
+ resources :routes, except: %i[destroy]
69
70
 
70
71
  post '/dispatch_plans/filter', controller: :dispatch_plans, action: :filter
71
72
  resources :dispatch_plans do
@@ -0,0 +1,19 @@
1
+ class CreateCatsCoreRoutes < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :cats_core_routes do |t|
4
+ t.string :name, null: false
5
+ t.references :source,
6
+ null: false,
7
+ index: { name: 'source_on_routes_indx' },
8
+ foreign_key: { to_table: :cats_core_locations }
9
+ t.references :destination,
10
+ null: false,
11
+ index: { name: 'destination_on_routes_indx' },
12
+ foreign_key: { to_table: :cats_core_locations }
13
+
14
+ t.timestamps
15
+
16
+ t.index [:source_id, :destination_id], unique: true
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ class CreateCatsCoreTransportBids < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :cats_core_transport_bids do |t|
4
+ t.string :reference_no, unique: true
5
+ t.string :description
6
+ t.date :start_date, null: false
7
+ t.date :end_date, null: false
8
+ t.string :status, null: false, default: 'New'
9
+
10
+ t.timestamps
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ class CreateCatsCoreTransportBidItems < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :cats_core_transport_bid_items do |t|
4
+ t.references :transport_bid,
5
+ null: false,
6
+ index: { name: 'tb_on_tbi_indx' },
7
+ foreign_key: { to_table: :cats_core_transport_bids }
8
+ t.references :route,
9
+ null: false,
10
+ index: { name: 'route_on_tbi_indx' },
11
+ foreign_key: { to_table: :cats_core_routes }
12
+ t.references :unit,
13
+ null: true,
14
+ index: { name: 'unit_on_tbi_indx' },
15
+ foreign_key: { to_table: :cats_core_unit_of_measures }
16
+ t.float :quantity, null: false
17
+
18
+ t.timestamps
19
+ end
20
+ end
21
+ end
@@ -1,10 +1,10 @@
1
1
  class CreateCatsCoreTransportOffers < ActiveRecord::Migration[6.1]
2
2
  def change
3
3
  create_table :cats_core_transport_offers do |t|
4
- t.references :transport_request_item,
4
+ t.references :transport_bid_item,
5
5
  null: false,
6
- index: { name: 'to_on_tri_indx' },
7
- foreign_key: { to_table: :cats_core_transport_request_items }
6
+ index: { name: 'to_on_tbi_indx' },
7
+ foreign_key: { to_table: :cats_core_transport_bid_items }
8
8
  t.references :transporter,
9
9
  null: false,
10
10
  index: { name: 'to_on_transporter_indx' },
@@ -0,0 +1,19 @@
1
+ class CreateCatsCoreTransportContracts < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :cats_core_transport_contracts do |t|
4
+ t.references :region,
5
+ null: false,
6
+ index: { name: 'region_on_tc_indx' },
7
+ foreign_key: { to_table: :cats_core_locations }
8
+ t.references :transporter,
9
+ null: false,
10
+ index: { name: 'transporter_on_tc_indx' },
11
+ foreign_key: { to_table: :cats_core_transporters }
12
+ t.date :contract_date, null: false
13
+ t.date :expires_on, null: false
14
+ t.string :payment_term
15
+
16
+ t.timestamps
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ class CreateCatsCoreContractItems < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :cats_core_contract_items do |t|
4
+ t.references :transport_contract,
5
+ null: false,
6
+ index: { name: 'tc_on_ci_indx' },
7
+ foreign_key: { to_table: :cats_core_transport_contracts }
8
+ t.references :route,
9
+ null: false,
10
+ index: { name: 'route_on_ci_indx' },
11
+ foreign_key: { to_table: :cats_core_routes }
12
+ t.float :price, null: false
13
+ t.references :unit,
14
+ null: false,
15
+ index: { name: 'unit_on_ci_indx' },
16
+ foreign_key: { to_table: :cats_core_unit_of_measures }
17
+
18
+ t.timestamps
19
+ end
20
+ end
21
+ end
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.2.16'.freeze
3
+ VERSION = '1.2.17'.freeze
4
4
  end
5
5
  end
@@ -0,0 +1,8 @@
1
+ FactoryBot.define do
2
+ factory :contract_item, class: 'Cats::Core::ContractItem' do
3
+ transport_contract
4
+ route
5
+ price { 150 }
6
+ unit factory: :unit_of_measure
7
+ end
8
+ end
@@ -0,0 +1,6 @@
1
+ FactoryBot.define do
2
+ factory :route, class: 'Cats::Core::Route' do
3
+ source factory: :location
4
+ destination factory: :location
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ FactoryBot.define do
2
+ factory :transport_bid_item, class: 'Cats::Core::TransportBidItem' do
3
+ transport_bid
4
+ route
5
+ unit factory: :unit_of_measure
6
+ quantity { 100 }
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ FactoryBot.define do
2
+ factory :transport_bid, class: 'Cats::Core::TransportBid' do
3
+ reference_no { FFaker::Name.name }
4
+ description { FFaker::Name.name }
5
+ start_date { Date.today - 1.week }
6
+ end_date { Date.today }
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ FactoryBot.define do
2
+ factory :transport_contract, class: 'Cats::Core::TransportContract' do
3
+ region factory: :location
4
+ transporter
5
+ contract_date { Date.today }
6
+ expires_on { Date.today + 6.month }
7
+ payment_term { FFaker::Name.name }
8
+ end
9
+ end
@@ -1,6 +1,6 @@
1
1
  FactoryBot.define do
2
2
  factory :transport_offer, class: 'Cats::Core::TransportOffer' do
3
- transport_request_item
3
+ transport_bid_item
4
4
  transporter
5
5
  price { 100 }
6
6
  winner { false }
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.16
4
+ version: 1.2.17
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-12-14 00:00:00.000000000 Z
11
+ date: 2021-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers
@@ -244,6 +244,7 @@ files:
244
244
  - app/controllers/cats/core/receipt_transactions_controller.rb
245
245
  - app/controllers/cats/core/receipts_controller.rb
246
246
  - app/controllers/cats/core/roles_controller.rb
247
+ - app/controllers/cats/core/routes_controller.rb
247
248
  - app/controllers/cats/core/spaces_controller.rb
248
249
  - app/controllers/cats/core/unit_of_measures_controller.rb
249
250
  - app/controllers/cats/core/users_controller.rb
@@ -255,6 +256,7 @@ files:
255
256
  - app/models/cats/core/application_record.rb
256
257
  - app/models/cats/core/commodity.rb
257
258
  - app/models/cats/core/commodity_category.rb
259
+ - app/models/cats/core/contract_item.rb
258
260
  - app/models/cats/core/currency.rb
259
261
  - app/models/cats/core/dispatch.rb
260
262
  - app/models/cats/core/dispatch_plan.rb
@@ -281,12 +283,16 @@ files:
281
283
  - app/models/cats/core/rhn_request.rb
282
284
  - app/models/cats/core/role.rb
283
285
  - app/models/cats/core/role_menu.rb
286
+ - app/models/cats/core/route.rb
284
287
  - app/models/cats/core/stack.rb
285
288
  - app/models/cats/core/stack_transaction.rb
286
289
  - app/models/cats/core/stacking_rule.rb
287
290
  - app/models/cats/core/store.rb
288
291
  - app/models/cats/core/supplier.rb
289
292
  - app/models/cats/core/transaction.rb
293
+ - app/models/cats/core/transport_bid.rb
294
+ - app/models/cats/core/transport_bid_item.rb
295
+ - app/models/cats/core/transport_contract.rb
290
296
  - app/models/cats/core/transport_offer.rb
291
297
  - app/models/cats/core/transport_request.rb
292
298
  - app/models/cats/core/transport_request_item.rb
@@ -308,6 +314,7 @@ files:
308
314
  - app/serializers/cats/core/receipt_transaction_serializer.rb
309
315
  - app/serializers/cats/core/role_menu_serializer.rb
310
316
  - app/serializers/cats/core/role_serializer.rb
317
+ - app/serializers/cats/core/route_serializer.rb
311
318
  - app/serializers/cats/core/unit_of_measure_serializer.rb
312
319
  - app/serializers/cats/core/user_serializer.rb
313
320
  - app/services/cats/core/dispatch_plan_service.rb
@@ -343,6 +350,7 @@ files:
343
350
  - db/migrate/20210717033223_create_cats_core_commodities.rb
344
351
  - db/migrate/20210717140855_create_cats_core_stores.rb
345
352
  - db/migrate/20210717171101_create_cats_core_stacks.rb
353
+ - db/migrate/20210718040129_create_cats_core_routes.rb
346
354
  - db/migrate/20210718042749_create_cats_core_transporters.rb
347
355
  - db/migrate/20210718042755_create_cats_core_rhn_requests.rb
348
356
  - db/migrate/20210718042823_create_cats_core_allocations.rb
@@ -359,9 +367,11 @@ files:
359
367
  - db/migrate/20211002050739_create_cats_core_notification_rules.rb
360
368
  - db/migrate/20211024063240_add_status_to_cats_core_rhn_requests.rb
361
369
  - db/migrate/20211030133752_add_status_to_cats_core_commodities.rb
362
- - db/migrate/20211209155113_create_cats_core_transport_requests.rb
363
- - db/migrate/20211209155915_create_cats_core_transport_request_items.rb
364
- - db/migrate/20211209160126_create_cats_core_transport_offers.rb
370
+ - db/migrate/20211215121151_create_cats_core_transport_bids.rb
371
+ - db/migrate/20211215124452_create_cats_core_transport_bid_items.rb
372
+ - db/migrate/20211229160126_create_cats_core_transport_offers.rb
373
+ - db/migrate/20211229160127_create_cats_core_transport_contracts.rb
374
+ - db/migrate/20211229160128_create_cats_core_contract_items.rb
365
375
  - lib/cats/core.rb
366
376
  - lib/cats/core/engine.rb
367
377
  - lib/cats/core/version.rb
@@ -372,6 +382,7 @@ files:
372
382
  - spec/factories/cats/core/application_modules.rb
373
383
  - spec/factories/cats/core/commodities.rb
374
384
  - spec/factories/cats/core/commodity_categories.rb
385
+ - spec/factories/cats/core/contract_items.rb
375
386
  - spec/factories/cats/core/currencies.rb
376
387
  - spec/factories/cats/core/dispatch_plan_items.rb
377
388
  - spec/factories/cats/core/dispatch_plans.rb
@@ -398,14 +409,16 @@ files:
398
409
  - spec/factories/cats/core/rhn_requests.rb
399
410
  - spec/factories/cats/core/role_menus.rb
400
411
  - spec/factories/cats/core/roles.rb
412
+ - spec/factories/cats/core/routes.rb
401
413
  - spec/factories/cats/core/stack_transactions.rb
402
414
  - spec/factories/cats/core/stacking_rules.rb
403
415
  - spec/factories/cats/core/stacks.rb
404
416
  - spec/factories/cats/core/stores.rb
405
417
  - spec/factories/cats/core/suppliers.rb
418
+ - spec/factories/cats/core/transport_bid_items.rb
419
+ - spec/factories/cats/core/transport_bids.rb
420
+ - spec/factories/cats/core/transport_contracts.rb
406
421
  - spec/factories/cats/core/transport_offers.rb
407
- - spec/factories/cats/core/transport_request_items.rb
408
- - spec/factories/cats/core/transport_requests.rb
409
422
  - spec/factories/cats/core/transporters.rb
410
423
  - spec/factories/cats/core/unit_of_measures.rb
411
424
  - spec/factories/cats/core/users.rb
@@ -1,19 +0,0 @@
1
- class CreateCatsCoreTransportRequests < ActiveRecord::Migration[6.1]
2
- def change
3
- create_table :cats_core_transport_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
@@ -1,24 +0,0 @@
1
- class CreateCatsCoreTransportRequestItems < ActiveRecord::Migration[6.1]
2
- def change
3
- create_table :cats_core_transport_request_items do |t|
4
- t.references :transport_request,
5
- null: false,
6
- index: { name: 'tri_on_tr_indx' },
7
- foreign_key: { to_table: :cats_core_transport_requests }
8
- t.references :source,
9
- null: false,
10
- index: { name: 'tri_on_source_indx' },
11
- foreign_key: { to_table: :cats_core_locations }
12
- t.references :destination,
13
- null: false,
14
- index: { name: 'tri_on_destination_indx'},
15
- foreign_key: { to_table: :cats_core_locations }
16
- t.references :commodity,
17
- null: false,
18
- index: { name: 'tri_on_commodity_indx' },
19
- foreign_key: { to_table: :cats_core_commodities }
20
-
21
- t.timestamps
22
- end
23
- end
24
- end
@@ -1,8 +0,0 @@
1
- FactoryBot.define do
2
- factory :transport_request_item, class: 'Cats::Core::TransportRequestItem' do
3
- transport_request
4
- source factory: :location
5
- destination factory: :location
6
- commodity
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- FactoryBot.define do
2
- factory :transport_request, class: 'Cats::Core::TransportRequest' 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