cats_core 1.2.28 → 1.2.32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/cats/core/routes_controller.rb +1 -1
- data/app/models/cats/core/contract_item.rb +2 -0
- data/app/models/cats/core/offer_item.rb +26 -0
- data/app/models/cats/core/route.rb +20 -0
- data/app/models/cats/core/transport_bid.rb +21 -2
- data/app/models/cats/core/transport_bid_item.rb +1 -1
- data/app/models/cats/core/transport_contract.rb +1 -0
- data/app/models/cats/core/transport_offer.rb +5 -18
- data/db/migrate/20210718040129_create_cats_core_routes.rb +5 -1
- data/db/migrate/20211215121151_create_cats_core_transport_bids.rb +6 -0
- data/db/migrate/{20211229160126_create_cats_core_transport_offers.rb → 20211229160125_create_cats_core_transport_offers.rb} +5 -6
- data/db/migrate/20211229160126_create_cats_core_offer_items.rb +19 -0
- data/lib/cats/core/version.rb +1 -1
- data/spec/factories/cats/core/offer_items.rb +9 -0
- data/spec/factories/cats/core/routes.rb +3 -2
- data/spec/factories/cats/core/transport_bids.rb +3 -0
- data/spec/factories/cats/core/transport_offers.rb +3 -4
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28dccafb9f531a0e9c13331b7a3c0cb807ddfeb42504bb1b484e58837c852219
|
4
|
+
data.tar.gz: 92f65296583c53ef16ac6e07fc849b6541fa5d69ba0f8d5f1b2920b16bdd2924
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa1f417bf917a6d670ac4e787343b520650f46d05d43ec77cd0b747484b3114abee8f03136b9aa71f247b188dfc4a062c6710c8dda44f29b4ba47f20dc271ed5
|
7
|
+
data.tar.gz: 8583a0ba4f7354469161c43e95fe150a3156b4ec3c1c08b0f0ed1f44924e7b7a620a763dd02c134b6a0c8c0ce34b6f2075e21d0209e43e3f5b392365b341f834
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Cats
|
2
|
+
module Core
|
3
|
+
class OfferItem < ApplicationRecord
|
4
|
+
belongs_to :transport_offer
|
5
|
+
belongs_to :transport_bid_item
|
6
|
+
|
7
|
+
validates :price, presence: true, numericality: { greater_than: 0 }
|
8
|
+
validates :rank, numericality: { greater_than: 0 }, allow_nil: true
|
9
|
+
validate :validate_rank_is_set_for_winner
|
10
|
+
|
11
|
+
def mark_as_winner(rank)
|
12
|
+
raise(StandardError, 'Offer item already marked as winner.') if winner
|
13
|
+
|
14
|
+
self.rank = rank
|
15
|
+
self.winner = true
|
16
|
+
save!
|
17
|
+
end
|
18
|
+
|
19
|
+
def validate_rank_is_set_for_winner
|
20
|
+
return if rank
|
21
|
+
|
22
|
+
errors.add(:winner, 'cannot be set for a non-ranked offer item.') if winner
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -3,16 +3,36 @@ module Cats
|
|
3
3
|
class Route < ApplicationRecord
|
4
4
|
before_validation :set_name, on: %i[create update]
|
5
5
|
|
6
|
+
belongs_to :region, class_name: 'Cats::Core::Location'
|
6
7
|
belongs_to :source, class_name: 'Cats::Core::Location'
|
7
8
|
belongs_to :destination, class_name: 'Cats::Core::Location'
|
8
9
|
|
9
10
|
validates :source_id, uniqueness: { scope: :destination_id }
|
11
|
+
validate :validate_region, :validate_source, :validate_destination
|
10
12
|
|
11
13
|
def set_name
|
12
14
|
return unless source && destination
|
13
15
|
|
14
16
|
self.name = "#{source.name} - #{destination.name}"
|
15
17
|
end
|
18
|
+
|
19
|
+
def validate_region
|
20
|
+
return unless region
|
21
|
+
|
22
|
+
errors.add(:region, 'should be a valid region.') unless region.location_type == Location::REGION
|
23
|
+
end
|
24
|
+
|
25
|
+
def validate_source
|
26
|
+
return unless source
|
27
|
+
|
28
|
+
errors.add(:source, 'cannot be a region.') if source.location_type == Location::REGION
|
29
|
+
end
|
30
|
+
|
31
|
+
def validate_destination
|
32
|
+
return unless destination
|
33
|
+
|
34
|
+
errors.add(:destination, 'cannot be a region.') if destination.location_type == Location::REGION
|
35
|
+
end
|
16
36
|
end
|
17
37
|
end
|
18
38
|
end
|
@@ -8,13 +8,22 @@ module Cats
|
|
8
8
|
WINNERS_DECLARED = 'Winner Declared'.freeze
|
9
9
|
STATUSES = [NEW, OPEN, CLOSED, RANKED, WINNERS_DECLARED].freeze
|
10
10
|
|
11
|
+
# Bid types
|
12
|
+
REGIONAL = 'Regional'.freeze
|
13
|
+
NON_REGIONAL = 'Non Regional'.freeze
|
14
|
+
BID_TYPES = [REGIONAL, NON_REGIONAL].freeze
|
15
|
+
|
11
16
|
has_many :transport_bid_items
|
12
|
-
has_many :transport_offers
|
17
|
+
has_many :transport_offers
|
18
|
+
belongs_to :region, class_name: 'Cats::Core::Location', optional: true
|
13
19
|
|
14
20
|
validates :reference_no, presence: true, uniqueness: true
|
15
|
-
validates :start_date, :end_date, :status, presence: true
|
21
|
+
validates :start_date, :end_date, :status, :bid_type, :bid_bond_amount, presence: true
|
22
|
+
validates :bid_bond_amount, numericality: { greater_than_or_equal_to: 0 }
|
16
23
|
validates :status, inclusion: { in: STATUSES }
|
24
|
+
validates :bid_type, inclusion: { in: BID_TYPES }
|
17
25
|
validate :validate_start_date_against_end_date
|
26
|
+
validate :validate_region
|
18
27
|
|
19
28
|
def validate_start_date_against_end_date
|
20
29
|
return unless start_date && end_date
|
@@ -22,6 +31,16 @@ module Cats
|
|
22
31
|
errors.add(:start_date, 'should be before end date.') if start_date >= end_date
|
23
32
|
end
|
24
33
|
|
34
|
+
def validate_region
|
35
|
+
return unless bid_type
|
36
|
+
|
37
|
+
errors.add(:region, 'should be null.') if bid_type == NON_REGIONAL && region
|
38
|
+
|
39
|
+
errors.add(:region, 'should not be null.') if bid_type == REGIONAL && !region
|
40
|
+
|
41
|
+
errors.add(:region, 'is not valid.') if region && region.location_type != Location::REGION
|
42
|
+
end
|
43
|
+
|
25
44
|
def open
|
26
45
|
raise(StandardError, 'Bid is already open.') if status == OPEN
|
27
46
|
|
@@ -1,28 +1,15 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class TransportOffer < ApplicationRecord
|
4
|
-
belongs_to :
|
4
|
+
belongs_to :transport_bid
|
5
5
|
belongs_to :transporter
|
6
|
+
has_many :offer_items
|
6
7
|
|
7
|
-
validates :
|
8
|
-
validates :
|
9
|
-
validate :validate_rank_is_set_for_winner
|
8
|
+
validates :offer_date, :bid_bond_amount, presence: true
|
9
|
+
validates :bid_bond_amount, numericality: { greater_than_or_equal_to: 0 }
|
10
10
|
|
11
11
|
delegate(:name, to: :transporter, prefix: true)
|
12
|
-
|
13
|
-
def mark_as_winner(rank)
|
14
|
-
raise(StandardError, 'Offer already marked as winner.') if winner
|
15
|
-
|
16
|
-
self.rank = rank
|
17
|
-
self.winner = true
|
18
|
-
save!
|
19
|
-
end
|
20
|
-
|
21
|
-
def validate_rank_is_set_for_winner
|
22
|
-
return if rank
|
23
|
-
|
24
|
-
errors.add(:winner, 'cannot be set for a non-ranked offer.') if winner
|
25
|
-
end
|
12
|
+
delegate(:reference_no, to: :transport_bid, prefix: 'bid')
|
26
13
|
end
|
27
14
|
end
|
28
15
|
end
|
@@ -2,6 +2,10 @@ class CreateCatsCoreRoutes < ActiveRecord::Migration[6.1]
|
|
2
2
|
def change
|
3
3
|
create_table :cats_core_routes do |t|
|
4
4
|
t.string :name, null: false
|
5
|
+
t.references :region,
|
6
|
+
null: false,
|
7
|
+
index: { name: 'region_on_routes_indx' },
|
8
|
+
foreign_key: { to_table: :cats_core_locations }
|
5
9
|
t.references :source,
|
6
10
|
null: false,
|
7
11
|
index: { name: 'source_on_routes_indx' },
|
@@ -13,7 +17,7 @@ class CreateCatsCoreRoutes < ActiveRecord::Migration[6.1]
|
|
13
17
|
|
14
18
|
t.timestamps
|
15
19
|
|
16
|
-
t.index [
|
20
|
+
t.index %i[source_id destination_id], unique: true
|
17
21
|
end
|
18
22
|
end
|
19
23
|
end
|
@@ -6,6 +6,12 @@ class CreateCatsCoreTransportBids < ActiveRecord::Migration[6.1]
|
|
6
6
|
t.date :start_date, null: false
|
7
7
|
t.date :end_date, null: false
|
8
8
|
t.string :status, null: false, default: 'New'
|
9
|
+
t.string :bid_type, null: false, default: 'Regional'
|
10
|
+
t.references :region,
|
11
|
+
null: true,
|
12
|
+
index: { name: 'region_on_tb_indx' },
|
13
|
+
foreign_key: { to_table: :cats_core_locations }
|
14
|
+
t.float :bid_bond_amount, null: false, default: 0
|
9
15
|
|
10
16
|
t.timestamps
|
11
17
|
end
|
@@ -1,17 +1,16 @@
|
|
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 :
|
4
|
+
t.references :transport_bid,
|
5
5
|
null: false,
|
6
|
-
index: { name: '
|
7
|
-
foreign_key: { to_table: :
|
6
|
+
index: { name: 'to_on_tb_indx' },
|
7
|
+
foreign_key: { to_table: :cats_core_transport_bids }
|
8
8
|
t.references :transporter,
|
9
9
|
null: false,
|
10
10
|
index: { name: 'to_on_transporter_indx' },
|
11
11
|
foreign_key: { to_table: :cats_core_transporters }
|
12
|
-
t.
|
13
|
-
t.
|
14
|
-
t.integer :rank
|
12
|
+
t.date :offer_date, null: false
|
13
|
+
t.float :bid_bond_amount, null: false, default: 0
|
15
14
|
|
16
15
|
t.timestamps
|
17
16
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class CreateCatsCoreOfferItems < ActiveRecord::Migration[6.1]
|
2
|
+
def change
|
3
|
+
create_table :cats_core_offer_items do |t|
|
4
|
+
t.references :transport_offer,
|
5
|
+
null: false,
|
6
|
+
index: { name: 'to_on_oi_indx' },
|
7
|
+
foreign_key: { to_table: :cats_core_transport_offers }
|
8
|
+
t.references :transport_bid_item,
|
9
|
+
null: false,
|
10
|
+
index: { name: 'tbi_on_to_indx' },
|
11
|
+
foreign_key: { to_table: :cats_core_transport_bid_items }
|
12
|
+
t.float :price, null: false
|
13
|
+
t.boolean :winner, null: false, default: false
|
14
|
+
t.integer :rank
|
15
|
+
|
16
|
+
t.timestamps
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/cats/core/version.rb
CHANGED
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.
|
4
|
+
version: 1.2.32
|
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-
|
11
|
+
date: 2021-12-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_model_serializers
|
@@ -271,6 +271,7 @@ files:
|
|
271
271
|
- app/models/cats/core/menu_item.rb
|
272
272
|
- app/models/cats/core/notification.rb
|
273
273
|
- app/models/cats/core/notification_rule.rb
|
274
|
+
- app/models/cats/core/offer_item.rb
|
274
275
|
- app/models/cats/core/operator.rb
|
275
276
|
- app/models/cats/core/plan.rb
|
276
277
|
- app/models/cats/core/plan_item.rb
|
@@ -368,7 +369,8 @@ files:
|
|
368
369
|
- db/migrate/20211030133752_add_status_to_cats_core_commodities.rb
|
369
370
|
- db/migrate/20211215121151_create_cats_core_transport_bids.rb
|
370
371
|
- db/migrate/20211215124452_create_cats_core_transport_bid_items.rb
|
371
|
-
- db/migrate/
|
372
|
+
- db/migrate/20211229160125_create_cats_core_transport_offers.rb
|
373
|
+
- db/migrate/20211229160126_create_cats_core_offer_items.rb
|
372
374
|
- db/migrate/20211229160127_create_cats_core_transport_contracts.rb
|
373
375
|
- db/migrate/20211229160128_create_cats_core_contract_items.rb
|
374
376
|
- db/migrate/20211229160129_create_cats_core_commodity_substitutions.rb
|
@@ -397,6 +399,7 @@ files:
|
|
397
399
|
- spec/factories/cats/core/menus.rb
|
398
400
|
- spec/factories/cats/core/notification_rules.rb
|
399
401
|
- spec/factories/cats/core/notifications.rb
|
402
|
+
- spec/factories/cats/core/offer_items.rb
|
400
403
|
- spec/factories/cats/core/operators.rb
|
401
404
|
- spec/factories/cats/core/plan_item_details.rb
|
402
405
|
- spec/factories/cats/core/plan_items.rb
|