cats_core 1.2.31 → 1.2.35

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: 6c2bd0f123f3f3c2ea21cd6987d61a19839bd8b60519ee8853ae00b163a2ff9c
4
- data.tar.gz: e6825f6847ea16a205fbee1bcfe5d74bf546cbad91dd5ae2c0b42e38d33eb806
3
+ metadata.gz: 7642c89b1980407bb2366d413f35325fa547cf339131269638d41069112504ce
4
+ data.tar.gz: a749c65316d24bf37deac90a7b35fa01cf7a463a793a5140f982ad380320d62a
5
5
  SHA512:
6
- metadata.gz: d62649ef9300dbcac14b73ea849e1cda359b4e78a2d62ece62bb4df13d623c0e6f0ed435dabd48e35cae417baaaa5476975d8bdc5b6d9d7be05b4a972e4c9b7a
7
- data.tar.gz: 535bc18ed18dd49dfeba9e8f58b966ee46690a7218293380658e9aa5ded0812ac20f47d9c474deaacc7f174ad3aae76d8da7e61f023f1bd376b4946ac5dc611a
6
+ metadata.gz: 957c5ce09ad50fe4e0bcef7ded61b11f6de78a3b0ec4c4055c047186c73f27951050d3c708c37bebca4984ea20b2f360e63e106936c9e2611aff4036cb8dd53e
7
+ data.tar.gz: f5a9ed6b97b4bf5e59e11c7a876c9962fef4eb1194e8e242c578ad77675e969071945f2fc423e7765e00f5daddb492f0262f8a79dd3376324863f408ec0b9817
@@ -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
@@ -5,7 +5,7 @@ module Cats
5
5
  belongs_to :ration
6
6
  belongs_to :unit_of_measure
7
7
 
8
- validates :amount, presence: true, numericality: { greater_than: 0 }
8
+ validates :amount, :no_of_days, presence: true, numericality: { greater_than: 0 }
9
9
 
10
10
  delegate(:name, to: :commodity_category, prefix: true)
11
11
  delegate(:abbreviation, to: :unit_of_measure, prefix: true)
@@ -8,13 +8,23 @@ 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, through: :transport_bid_items
17
+ has_many :transport_offers
18
+ has_many :offer_items, through: :transport_offers
19
+ belongs_to :region, class_name: 'Cats::Core::Location', optional: true
13
20
 
14
21
  validates :reference_no, presence: true, uniqueness: true
15
- validates :start_date, :end_date, :status, presence: true
22
+ validates :start_date, :end_date, :status, :bid_type, :bid_bond_amount, presence: true
23
+ validates :bid_bond_amount, numericality: { greater_than_or_equal_to: 0 }
16
24
  validates :status, inclusion: { in: STATUSES }
25
+ validates :bid_type, inclusion: { in: BID_TYPES }
17
26
  validate :validate_start_date_against_end_date
27
+ validate :validate_region
18
28
 
19
29
  def validate_start_date_against_end_date
20
30
  return unless start_date && end_date
@@ -22,6 +32,16 @@ module Cats
22
32
  errors.add(:start_date, 'should be before end date.') if start_date >= end_date
23
33
  end
24
34
 
35
+ def validate_region
36
+ return unless bid_type
37
+
38
+ errors.add(:region, 'should be null.') if bid_type == NON_REGIONAL && region
39
+
40
+ errors.add(:region, 'should not be null.') if bid_type == REGIONAL && !region
41
+
42
+ errors.add(:region, 'is not valid.') if region && region.location_type != Location::REGION
43
+ end
44
+
25
45
  def open
26
46
  raise(StandardError, 'Bid is already open.') if status == OPEN
27
47
 
@@ -5,7 +5,7 @@ module Cats
5
5
  belongs_to :route
6
6
  belongs_to :unit, class_name: 'Cats::Core::UnitOfMeasure', optional: true
7
7
 
8
- has_many :transport_offers
8
+ has_many :offer_items
9
9
 
10
10
  validates :quantity, presence: true, numericality: { greater_than: 0 }
11
11
 
@@ -1,7 +1,6 @@
1
1
  module Cats
2
2
  module Core
3
3
  class TransportContract < ApplicationRecord
4
- belongs_to :region, class_name: 'Cats::Core::Location'
5
4
  belongs_to :transporter
6
5
  belongs_to :transport_bid
7
6
  has_many :contract_items
@@ -9,7 +8,6 @@ module Cats
9
8
  validates :contract_no, presence: true, uniqueness: true
10
9
  validates :contract_date, :expires_on, presence: true
11
10
 
12
- delegate(:name, to: :region, prefix: true)
13
11
  delegate(:name, to: :transporter, prefix: true)
14
12
  delegate(:reference_no, to: :transport_bid, prefix: :bid)
15
13
  end
@@ -1,28 +1,15 @@
1
1
  module Cats
2
2
  module Core
3
3
  class TransportOffer < ApplicationRecord
4
- belongs_to :transport_bid_item
4
+ belongs_to :transport_bid
5
5
  belongs_to :transporter
6
+ has_many :offer_items
6
7
 
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
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
@@ -14,6 +14,7 @@ class CreateCatsCoreRationItems < ActiveRecord::Migration[6.1]
14
14
  index: { name: 'uom_on_ration_indx' },
15
15
  foreign_key: { to_table: :cats_core_unit_of_measures }
16
16
  t.float :amount, null: false
17
+ t.integer :no_of_days, null: false
17
18
 
18
19
  t.timestamps
19
20
  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 :transport_bid_item,
4
+ t.references :transport_bid,
5
5
  null: false,
6
- index: { name: 'to_on_tbi_indx' },
7
- foreign_key: { to_table: :cats_core_transport_bid_items }
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.float :price, null: false
13
- t.boolean :winner, null: false, default: false
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
@@ -2,10 +2,6 @@ class CreateCatsCoreTransportContracts < ActiveRecord::Migration[6.1]
2
2
  def change
3
3
  create_table :cats_core_transport_contracts do |t|
4
4
  t.string :contract_no, unique: true
5
- t.references :region,
6
- null: false,
7
- index: { name: 'region_on_tc_indx' },
8
- foreign_key: { to_table: :cats_core_locations }
9
5
  t.references :transporter,
10
6
  null: false,
11
7
  index: { name: 'transporter_on_tc_indx' },
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.2.31'.freeze
3
+ VERSION = '1.2.35'.freeze
4
4
  end
5
5
  end
@@ -0,0 +1,9 @@
1
+ FactoryBot.define do
2
+ factory :offer_item, class: 'Cats::Core::OfferItem' do
3
+ transport_offer
4
+ transport_bid_item
5
+ price { 150 }
6
+ rank { 2 }
7
+ winner { false }
8
+ end
9
+ end
@@ -4,5 +4,6 @@ FactoryBot.define do
4
4
  ration
5
5
  amount { 150 }
6
6
  unit_of_measure
7
+ no_of_days { 1 }
7
8
  end
8
9
  end
@@ -4,5 +4,8 @@ FactoryBot.define do
4
4
  description { FFaker::Name.name }
5
5
  start_date { Date.today - 1.week }
6
6
  end_date { Date.today }
7
+ bid_type { Cats::Core::TransportBid::REGIONAL }
8
+ region factory: :location
9
+ bid_bond_amount { 100 }
7
10
  end
8
11
  end
@@ -1,7 +1,6 @@
1
1
  FactoryBot.define do
2
2
  factory :transport_contract, class: 'Cats::Core::TransportContract' do
3
3
  contract_no { FFaker::Name.name }
4
- region factory: :location
5
4
  transporter
6
5
  transport_bid
7
6
  contract_date { Date.today }
@@ -1,9 +1,8 @@
1
1
  FactoryBot.define do
2
2
  factory :transport_offer, class: 'Cats::Core::TransportOffer' do
3
- transport_bid_item
3
+ transport_bid
4
4
  transporter
5
- price { 100 }
6
- winner { false }
7
- rank { nil }
5
+ bid_bond_amount { 100 }
6
+ offer_date { Date.today }
8
7
  end
9
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.31
4
+ version: 1.2.35
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-23 00:00:00.000000000 Z
11
+ date: 2022-01-02 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/20211229160126_create_cats_core_transport_offers.rb
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