cats_core 1.2.21 → 1.2.25

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: 7acc9223402378e3d0708d5868c80f1bbff5bf9f22db440a9ef298834ca886df
4
- data.tar.gz: aae5042083532d9ec3d31b5c13cee75d060539b53ddb97da52f1b65f6529422b
3
+ metadata.gz: 4f77886d3ecd05214933544684c4bd9f37165fb8c34ed8a641866e792a993385
4
+ data.tar.gz: 3b01c59cc8e1baad2f912313166c3f974212542d8eb3623a8ae0a5a25bcfebc4
5
5
  SHA512:
6
- metadata.gz: 8a7c5f08aaac792fe9f745f552fceb45968d2cef9b627916af18205466897051331f52620b720b000b9b07ae4e301f9ee473669caa22c8f64ee63a1ce39e7e19
7
- data.tar.gz: f7b9292e6e8173f0aec82e71ced97b11dad6f16882763d4fb6b91c788d2b1db60df38ef5f35961930800cebf6308cc42576127d76cb2e2560eb853b4bc0ed6f8
6
+ metadata.gz: cdb748fff925eca80e12bbe4f1f272535cf70bf40bab98f4b5f08bb1d499ddd542352356d9ea87ec08e657f9cabc74510aa38899b15c01484b40598c0f506a24
7
+ data.tar.gz: 3d3375b52e6edffe8cd3d92f5b9476d28b077f4ee611356b7219fd5f5a69cff2d5b0f7f70af22ab5843c33323095bf9b33e59d832151f688a612b0ad68427a9c
@@ -0,0 +1,23 @@
1
+ module Cats
2
+ module Core
3
+ class CommoditySubstitution < ApplicationRecord
4
+ belongs_to :program
5
+ belongs_to :commodity, class_name: 'Cats::Core::CommodityCategory'
6
+ belongs_to :replaced_by, class_name: 'Cats::Core::CommodityCategory'
7
+
8
+ validates :ratio, presence: true
9
+ validates :program_id, uniqueness: { scope: %i[commodity_id replaced_by_id] }
10
+ validate :validate_ratio
11
+
12
+ def validate_ratio
13
+ return unless ratio
14
+
15
+ left, right = ratio.split(':')
16
+ left_correct = Integer(left).is_a?(Integer) rescue false
17
+ right_correct = Integer(right).is_a?(Integer) rescue false
18
+
19
+ errors.add(:ratio, 'is not in correct format.') unless left_correct && right_correct
20
+ end
21
+ end
22
+ end
23
+ end
@@ -4,9 +4,12 @@ module Cats
4
4
  NEW = 'New'.freeze
5
5
  OPEN = 'Open'.freeze
6
6
  CLOSED = 'Closed'.freeze
7
- STATUSES = [NEW, OPEN, CLOSED].freeze
7
+ RANKED = 'Ranked'.freeze
8
+ WINNERS_DECLARED = 'Winner Declared'.freeze
9
+ STATUSES = [NEW, OPEN, CLOSED, RANKED, WINNERS_DECLARED].freeze
8
10
 
9
11
  has_many :transport_bid_items
12
+ has_many :transport_offers, through: :transport_bid_items
10
13
 
11
14
  validates :reference_no, presence: true, uniqueness: true
12
15
  validates :start_date, :end_date, :status, presence: true
@@ -3,6 +3,7 @@ module Cats
3
3
  class TransportContract < ApplicationRecord
4
4
  belongs_to :region, class_name: 'Cats::Core::Location'
5
5
  belongs_to :transporter
6
+ belongs_to :transport_bid
6
7
 
7
8
  validates :contract_date, :expires_on, presence: true
8
9
  end
@@ -9,6 +9,10 @@ class CreateCatsCoreTransportContracts < ActiveRecord::Migration[6.1]
9
9
  null: false,
10
10
  index: { name: 'transporter_on_tc_indx' },
11
11
  foreign_key: { to_table: :cats_core_transporters }
12
+ t.references :transport_bid,
13
+ null: false,
14
+ index: { name: 'tb_on_tc_indx' },
15
+ foreign_key: { to_table: :cats_core_transport_bids }
12
16
  t.date :contract_date, null: false
13
17
  t.date :expires_on, null: false
14
18
  t.string :payment_term
@@ -0,0 +1,23 @@
1
+ class CreateCatsCoreCommoditySubstitutions < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :cats_core_commodity_substitutions do |t|
4
+ t.references :program,
5
+ null: false,
6
+ index: { name: 'program_on_cs_indx' },
7
+ foreign_key: { to_table: :cats_core_programs }
8
+ t.references :commodity,
9
+ null: false,
10
+ index: { name: 'commodity_on_cs_indx' },
11
+ foreign_key: { to_table: :cats_core_commodity_categories }
12
+ t.references :replaced_by,
13
+ null: false,
14
+ index: { name: 'rb_on_cs_indx' },
15
+ foreign_key: { to_table: :cats_core_commodity_categories }
16
+ t.string :ratio, null: false
17
+
18
+ t.timestamps
19
+
20
+ t.index [:program_id, :commodity_id, :replaced_by_id], unique: true, name: 'pcr_on_cs_indx'
21
+ end
22
+ end
23
+ end
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.2.21'.freeze
3
+ VERSION = '1.2.25'.freeze
4
4
  end
5
5
  end
@@ -0,0 +1,8 @@
1
+ FactoryBot.define do
2
+ factory :commodity_substitution, class: 'Cats::Core::CommoditySubstitution' do
3
+ program
4
+ commodity factory: :commodity_category
5
+ replaced_by factory: :commodity_category
6
+ ratio { '1:2' }
7
+ end
8
+ end
@@ -2,6 +2,7 @@ FactoryBot.define do
2
2
  factory :transport_contract, class: 'Cats::Core::TransportContract' do
3
3
  region factory: :location
4
4
  transporter
5
+ transport_bid
5
6
  contract_date { Date.today }
6
7
  expires_on { Date.today + 6.month }
7
8
  payment_term { FFaker::Name.name }
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.21
4
+ version: 1.2.25
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-18 00:00:00.000000000 Z
11
+ date: 2021-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers
@@ -256,6 +256,7 @@ files:
256
256
  - app/models/cats/core/application_record.rb
257
257
  - app/models/cats/core/commodity.rb
258
258
  - app/models/cats/core/commodity_category.rb
259
+ - app/models/cats/core/commodity_substitution.rb
259
260
  - app/models/cats/core/contract_item.rb
260
261
  - app/models/cats/core/currency.rb
261
262
  - app/models/cats/core/dispatch.rb
@@ -294,8 +295,6 @@ files:
294
295
  - app/models/cats/core/transport_bid_item.rb
295
296
  - app/models/cats/core/transport_contract.rb
296
297
  - app/models/cats/core/transport_offer.rb
297
- - app/models/cats/core/transport_request.rb
298
- - app/models/cats/core/transport_request_item.rb
299
298
  - app/models/cats/core/transporter.rb
300
299
  - app/models/cats/core/unit_of_measure.rb
301
300
  - app/models/cats/core/user.rb
@@ -372,6 +371,7 @@ files:
372
371
  - db/migrate/20211229160126_create_cats_core_transport_offers.rb
373
372
  - db/migrate/20211229160127_create_cats_core_transport_contracts.rb
374
373
  - db/migrate/20211229160128_create_cats_core_contract_items.rb
374
+ - db/migrate/20211229160129_create_cats_core_commodity_substitutions.rb
375
375
  - lib/cats/core.rb
376
376
  - lib/cats/core/engine.rb
377
377
  - lib/cats/core/version.rb
@@ -382,6 +382,7 @@ files:
382
382
  - spec/factories/cats/core/application_modules.rb
383
383
  - spec/factories/cats/core/commodities.rb
384
384
  - spec/factories/cats/core/commodity_categories.rb
385
+ - spec/factories/cats/core/commodity_substitutions.rb
385
386
  - spec/factories/cats/core/contract_items.rb
386
387
  - spec/factories/cats/core/currencies.rb
387
388
  - spec/factories/cats/core/dispatch_plan_items.rb
@@ -1,46 +0,0 @@
1
- module Cats
2
- module Core
3
- class TransportRequest < ApplicationRecord
4
- DRAFT = 'Draft'.freeze
5
- APPROVED = 'Approved'.freeze
6
- OPEN = 'Open'.freeze
7
- CLOSED = 'Closed'.freeze
8
- STATUSES = [DRAFT, APPROVED, OPEN, CLOSED].freeze
9
-
10
- belongs_to :requested_by, class_name: 'Cats::Core::User'
11
- belongs_to :approved_by, class_name: 'Cats::Core::User', optional: true
12
- has_many :transport_request_items
13
-
14
- validates :reference_no, :request_date, :status, presence: true
15
- validates :reference_no, uniqueness: true
16
- validates :status, inclusion: { in: STATUSES }
17
-
18
- delegate(:full_name, to: :requested_by, prefix: true, allow_nil: true)
19
- delegate(:full_name, to: :approved_by, prefix: true, allow_nil: true)
20
-
21
- def approve(approver)
22
- raise(StandardError, 'Request is not open for approval.') unless status == DRAFT
23
-
24
- raise(StandardError, 'Request is empty.') if transport_request_items.count.zero?
25
-
26
- self.approved_by = approver
27
- self.status = APPROVED
28
- save!
29
- end
30
-
31
- def open
32
- raise(StandardError, 'Request is not approved for opening.') unless status == APPROVED
33
-
34
- self.status = OPEN
35
- save!
36
- end
37
-
38
- def close
39
- raise(StandardError, 'Request is not open.') unless status == OPEN
40
-
41
- self.status = CLOSED
42
- save!
43
- end
44
- end
45
- end
46
- end
@@ -1,16 +0,0 @@
1
- module Cats
2
- module Core
3
- class TransportRequestItem < ApplicationRecord
4
- belongs_to :transport_request
5
- belongs_to :source, class_name: 'Cats::Core::Location'
6
- belongs_to :destination, class_name: 'Cats::Core::Location'
7
- belongs_to :commodity
8
-
9
- has_many :transport_offers
10
-
11
- delegate(:name, to: :source, prefix: true)
12
- delegate(:name, to: :destination, prefix: true)
13
- delegate(:name, to: :commodity, prefix: true)
14
- end
15
- end
16
- end