cats_core 1.2.21 → 1.2.22

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: c5139b115f1503157e1d5f53a0a013b72d1296a0cd1fe808c1fd117a4a813830
4
+ data.tar.gz: eaf56d0ba167f6360144a4d7e6152eba2e0375b7c272ea271cfc9805178e781b
5
5
  SHA512:
6
- metadata.gz: 8a7c5f08aaac792fe9f745f552fceb45968d2cef9b627916af18205466897051331f52620b720b000b9b07ae4e301f9ee473669caa22c8f64ee63a1ce39e7e19
7
- data.tar.gz: f7b9292e6e8173f0aec82e71ced97b11dad6f16882763d4fb6b91c788d2b1db60df38ef5f35961930800cebf6308cc42576127d76cb2e2560eb853b4bc0ed6f8
6
+ metadata.gz: bad07930acac569a78aee9152527d95c390f48eb3a69070894c888a3ff8de74f07f0904730aa59446b17a9b1979a0cdbd8e898b23eeb231b1693f449f664be7b
7
+ data.tar.gz: ab180af55c2610e87a0f1f7f7f1031a8730f9cccbae2ea1c0f5bc58cc6cf219dfac657e3078624e2624f38230b950dd49d708d44691f8ed47db55652262852d3
@@ -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
@@ -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.22'.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
metadata CHANGED
@@ -1,7 +1,7 @@
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.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.
@@ -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
@@ -372,6 +373,7 @@ files:
372
373
  - db/migrate/20211229160126_create_cats_core_transport_offers.rb
373
374
  - db/migrate/20211229160127_create_cats_core_transport_contracts.rb
374
375
  - db/migrate/20211229160128_create_cats_core_contract_items.rb
376
+ - db/migrate/20211229160129_create_cats_core_commodity_substitutions.rb
375
377
  - lib/cats/core.rb
376
378
  - lib/cats/core/engine.rb
377
379
  - lib/cats/core/version.rb
@@ -382,6 +384,7 @@ files:
382
384
  - spec/factories/cats/core/application_modules.rb
383
385
  - spec/factories/cats/core/commodities.rb
384
386
  - spec/factories/cats/core/commodity_categories.rb
387
+ - spec/factories/cats/core/commodity_substitutions.rb
385
388
  - spec/factories/cats/core/contract_items.rb
386
389
  - spec/factories/cats/core/currencies.rb
387
390
  - spec/factories/cats/core/dispatch_plan_items.rb