cats_core 1.2.19 → 1.2.23

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: 6bab9a0fa1d97225acf7f2895a4d84ef699cc947851b11d0d304c47ad4b80ed6
4
- data.tar.gz: d8ec1bf30f447226ce4e3d8b445a72728a7c249b94e7919c69313599cc2e0c6e
3
+ metadata.gz: 6fe0f87a2452fb8bcafe40ece45a769789b6b576cab27cdf0867507acc79338e
4
+ data.tar.gz: 967feac1199b16fe037295cb805c3cb9cf7234b37e03641af952bf1ffc7e624d
5
5
  SHA512:
6
- metadata.gz: 96caa2ec1346006591ea5fd019992aec79a3e7d269e8495ad14f1818fbe40716b53b4aa5a0b2481024abd04fe2ae9d132abb4122c7791ec312264b18139fc239
7
- data.tar.gz: 7fc447ddcb864efea72a7de8cd904a70520df3ef058b2c4a26bc6fb6b8ff63a706ab7514607d647a0fa573ae81965141589a95a7487fe998f84e2c6df49edacb
6
+ metadata.gz: 01ce4d95e2c647519e65a19b109a81229bae931aa0af07cf719f9a2f2322f4d8edc4c098e221a51af9577b64a394da4bd05dc8243e7a28837d8ea5482b2c2b56
7
+ data.tar.gz: e78386c0c8df0e6b8045de92d5235516e09937d044b7e0efee9505fc6b629b1589ee962e759ea17460e19f3caef58a4ad1554959bad138740aec29d870b3c932
@@ -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
@@ -6,7 +6,7 @@ module Cats
6
6
  DONATION_TYPES = [CASH, KIND].freeze
7
7
 
8
8
  belongs_to :donor
9
- belongs_to :hrp
9
+ belongs_to :plan
10
10
  belongs_to :currency, optional: true
11
11
  belongs_to :commodity_category, optional: true
12
12
  belongs_to :unit_of_measure, optional: true
@@ -19,7 +19,7 @@ module Cats
19
19
  validates :unit_of_measure, presence: true, if: -> { donation_type == KIND }
20
20
 
21
21
  delegate(:name, to: :donor, prefix: true)
22
- delegate(:reference_no, to: :hrp, prefix: true)
22
+ delegate(:reference_no, to: :plan, prefix: true)
23
23
  delegate(:name, to: :commodity_category, prefix: true, allow_nil: true)
24
24
  delegate(:code, to: :currency, prefix: true, allow_nil: true)
25
25
  delegate(:abbreviation, to: :unit_of_measure, prefix: true, allow_nil: true)
@@ -1,6 +1,6 @@
1
1
  module Cats
2
2
  module Core
3
- class Hrp < ApplicationRecord
3
+ class Plan < ApplicationRecord
4
4
  DRAFT = 'Draft'.freeze
5
5
  APPROVED = 'Approved'.freeze
6
6
  NEEDS_APPROVED = 'Needs Approved'.freeze
@@ -13,7 +13,7 @@ module Cats
13
13
 
14
14
  belongs_to :program
15
15
  belongs_to :ration, optional: true
16
- has_many :hrp_items
16
+ has_many :plan_items
17
17
 
18
18
  validates :reference_no, :year, :status, presence: true
19
19
  validates :season, presence: true, inclusion: { in: SEASONS }
@@ -1,14 +1,14 @@
1
1
  module Cats
2
2
  module Core
3
- class HrpItem < ApplicationRecord
4
- belongs_to :hrp
3
+ class PlanItem < ApplicationRecord
4
+ belongs_to :plan
5
5
  belongs_to :woreda, -> { where(location_type: Cats::Core::Location::WOREDA) }, class_name: 'Cats::Core::Location'
6
6
  belongs_to :operator
7
7
 
8
- has_many :hrp_item_details
8
+ has_many :plan_item_details
9
9
 
10
10
  validates :beneficiaries, presence: true, numericality: { greater_than: 0 }
11
- validates :hrp_id, uniqueness: { scope: :woreda_id }
11
+ validates :plan_id, uniqueness: { scope: :woreda_id }
12
12
 
13
13
  delegate(:name, to: :woreda, prefix: true)
14
14
  delegate(:name, to: :operator, prefix: true)
@@ -1,11 +1,11 @@
1
1
  module Cats
2
2
  module Core
3
- class HrpItemDetail < ApplicationRecord
4
- belongs_to :hrp_item
3
+ class PlanItemDetail < ApplicationRecord
4
+ belongs_to :plan_item
5
5
  belongs_to :ration_item
6
6
 
7
7
  validates :amount, presence: true, numericality: { greater_than: 0 }
8
- validates :hrp_item_id, uniqueness: { scope: :ration_item_id }
8
+ validates :plan_item_id, uniqueness: { scope: :ration_item_id }
9
9
  end
10
10
  end
11
11
  end
@@ -4,7 +4,9 @@ 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
10
12
 
@@ -1,6 +1,6 @@
1
- class CreateCatsCoreHrps < ActiveRecord::Migration[6.1]
1
+ class CreateCatsCorePlans < ActiveRecord::Migration[6.1]
2
2
  def change
3
- create_table :cats_core_hrps do |t|
3
+ create_table :cats_core_plans do |t|
4
4
  t.string :reference_no, unique: true
5
5
  t.integer :year, null: false
6
6
  t.string :season, null: false
@@ -8,11 +8,11 @@ class CreateCatsCoreHrps < ActiveRecord::Migration[6.1]
8
8
 
9
9
  t.references :program,
10
10
  null: false,
11
- index: { name: 'program_on_hrp_indx' },
11
+ index: { name: 'program_on_plan_indx' },
12
12
  foreign_key: { to_table: :cats_core_programs }
13
13
  t.references :ration,
14
14
  null: true,
15
- index: { name: 'ration_on_hrp_indx' },
15
+ index: { name: 'ration_on_plan_indx' },
16
16
  foreign_key: { to_table: :cats_core_rations }
17
17
 
18
18
  t.timestamps
@@ -0,0 +1,23 @@
1
+ class CreateCatsCorePlanItems < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :cats_core_plan_items do |t|
4
+ t.references :plan,
5
+ null: false,
6
+ index: { name: 'plan_on_plan_items_indx' },
7
+ foreign_key: { to_table: :cats_core_plans }
8
+ t.references :woreda,
9
+ null: false,
10
+ index: { name: 'woreda_on_plan_items_idnx' },
11
+ foreign_key: { to_table: :cats_core_locations }
12
+ t.integer :beneficiaries, null: false
13
+ t.references :operator,
14
+ null: false,
15
+ index: { name: 'operator_on_plan_items_indx' },
16
+ foreign_key: { to_table: :cats_core_operators }
17
+
18
+ t.timestamps
19
+ end
20
+
21
+ add_index :cats_core_plan_items, [:plan_id, :woreda_id], unique: true
22
+ end
23
+ end
@@ -0,0 +1,18 @@
1
+ class CreateCatsCorePlanItemDetails < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :cats_core_plan_item_details do |t|
4
+ t.references :plan_item,
5
+ null: false,
6
+ index: { name: 'pi_on_pid_indx' },
7
+ foreign_key: { to_table: :cats_core_plan_items }
8
+ t.references :ration_item,
9
+ null: false,
10
+ index: { name: 'ri_on_pid_indx' },
11
+ foreign_key: { to_table: :cats_core_ration_items }
12
+ t.float :amount, null: false
13
+
14
+ t.timestamps
15
+ end
16
+ add_index(:cats_core_plan_item_details, [:plan_item_id, :ration_item_id], unique: true, name: 'pii_rii_on_pid_indx')
17
+ end
18
+ end
@@ -8,10 +8,10 @@ class CreateCatsCoreDonations < ActiveRecord::Migration[6.1]
8
8
  null: false,
9
9
  index: { name: 'donor_on_donation_indx' },
10
10
  foreign_key: { to_table: :cats_core_donors }
11
- t.references :hrp,
11
+ t.references :plan,
12
12
  null: false,
13
- index: { name: 'hrp_on_donation_indx' },
14
- foreign_key: { to_table: :cats_core_hrps }
13
+ index: { name: 'plan_on_donation_indx' },
14
+ foreign_key: { to_table: :cats_core_plans }
15
15
  t.float :amount, null: false
16
16
  t.references :currency,
17
17
  null: true,
@@ -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.19'.freeze
3
+ VERSION = '1.2.23'.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
@@ -4,7 +4,7 @@ FactoryBot.define do
4
4
  donation_type { Cats::Core::Donation::KIND }
5
5
  donated_on { Date.today }
6
6
  donor
7
- hrp
7
+ plan
8
8
  amount { 100 }
9
9
  currency { nil }
10
10
  commodity_category
@@ -0,0 +1,7 @@
1
+ FactoryBot.define do
2
+ factory :plan_item_detail, class: 'Cats::Core::PlanItemDetail' do
3
+ plan_item
4
+ ration_item
5
+ amount { 150 }
6
+ end
7
+ end
@@ -1,6 +1,6 @@
1
1
  FactoryBot.define do
2
- factory :hrp_item, class: 'Cats::Core::HrpItem' do
3
- hrp
2
+ factory :plan_item, class: 'Cats::Core::PlanItem' do
3
+ plan
4
4
  woreda
5
5
  beneficiaries { 100 }
6
6
  operator
@@ -0,0 +1,10 @@
1
+ FactoryBot.define do
2
+ factory :plan, class: 'Cats::Core::Plan' do
3
+ reference_no { FFaker::Name.name }
4
+ year { 1 }
5
+ season { Cats::Core::Plan::BELG }
6
+ status { Cats::Core::Plan::DRAFT }
7
+ program
8
+ ration
9
+ end
10
+ 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.19
4
+ version: 1.2.23
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
@@ -265,15 +266,15 @@ files:
265
266
  - app/models/cats/core/donation.rb
266
267
  - app/models/cats/core/donor.rb
267
268
  - app/models/cats/core/gift_certificate.rb
268
- - app/models/cats/core/hrp.rb
269
- - app/models/cats/core/hrp_item.rb
270
- - app/models/cats/core/hrp_item_detail.rb
271
269
  - app/models/cats/core/location.rb
272
270
  - app/models/cats/core/menu.rb
273
271
  - app/models/cats/core/menu_item.rb
274
272
  - app/models/cats/core/notification.rb
275
273
  - app/models/cats/core/notification_rule.rb
276
274
  - app/models/cats/core/operator.rb
275
+ - app/models/cats/core/plan.rb
276
+ - app/models/cats/core/plan_item.rb
277
+ - app/models/cats/core/plan_item_detail.rb
277
278
  - app/models/cats/core/program.rb
278
279
  - app/models/cats/core/purchase_order.rb
279
280
  - app/models/cats/core/ration.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
@@ -341,9 +340,9 @@ files:
341
340
  - db/migrate/20210717031108_create_cats_core_donors.rb
342
341
  - db/migrate/20210717031216_create_cats_core_rations.rb
343
342
  - db/migrate/20210717031343_create_cats_core_ration_items.rb
344
- - db/migrate/20210717031810_create_cats_core_hrps.rb
345
- - db/migrate/20210717032024_create_cats_core_hrp_items.rb
346
- - db/migrate/20210717032240_create_cats_core_hrp_item_details.rb
343
+ - db/migrate/20210717031810_create_cats_core_plans.rb
344
+ - db/migrate/20210717032024_create_cats_core_plan_items.rb
345
+ - db/migrate/20210717032240_create_cats_core_plan_item_details.rb
347
346
  - db/migrate/20210717032330_create_cats_core_donations.rb
348
347
  - db/migrate/20210717032602_create_cats_core_gift_certificates.rb
349
348
  - db/migrate/20210717032855_create_cats_core_purchase_orders.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
@@ -391,15 +392,15 @@ files:
391
392
  - spec/factories/cats/core/donations.rb
392
393
  - spec/factories/cats/core/donors.rb
393
394
  - spec/factories/cats/core/gift_certificates.rb
394
- - spec/factories/cats/core/hrp_item_details.rb
395
- - spec/factories/cats/core/hrp_items.rb
396
- - spec/factories/cats/core/hrps.rb
397
395
  - spec/factories/cats/core/locations.rb
398
396
  - spec/factories/cats/core/menu_items.rb
399
397
  - spec/factories/cats/core/menus.rb
400
398
  - spec/factories/cats/core/notification_rules.rb
401
399
  - spec/factories/cats/core/notifications.rb
402
400
  - spec/factories/cats/core/operators.rb
401
+ - spec/factories/cats/core/plan_item_details.rb
402
+ - spec/factories/cats/core/plan_items.rb
403
+ - spec/factories/cats/core/plans.rb
403
404
  - spec/factories/cats/core/programs.rb
404
405
  - spec/factories/cats/core/purchase_orders.rb
405
406
  - spec/factories/cats/core/ration_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
@@ -1,23 +0,0 @@
1
- class CreateCatsCoreHrpItems < ActiveRecord::Migration[6.1]
2
- def change
3
- create_table :cats_core_hrp_items do |t|
4
- t.references :hrp,
5
- null: false,
6
- index: { name: 'hrp_on_hrp_items_indx' },
7
- foreign_key: { to_table: :cats_core_hrps }
8
- t.references :woreda,
9
- null: false,
10
- index: { name: 'woreda_on_hrp_items_idnx' },
11
- foreign_key: { to_table: :cats_core_locations }
12
- t.integer :beneficiaries, null: false
13
- t.references :operator,
14
- null: false,
15
- index: { name: 'operator_on_hrp_items_indx' },
16
- foreign_key: { to_table: :cats_core_operators }
17
-
18
- t.timestamps
19
- end
20
-
21
- add_index :cats_core_hrp_items, [:hrp_id, :woreda_id], unique: true
22
- end
23
- end
@@ -1,18 +0,0 @@
1
- class CreateCatsCoreHrpItemDetails < ActiveRecord::Migration[6.1]
2
- def change
3
- create_table :cats_core_hrp_item_details do |t|
4
- t.references :hrp_item,
5
- null: false,
6
- index: { name: 'hi_on_hid_indx' },
7
- foreign_key: { to_table: :cats_core_hrp_items }
8
- t.references :ration_item,
9
- null: false,
10
- index: { name: 'ri_on_hid_indx' },
11
- foreign_key: { to_table: :cats_core_ration_items }
12
- t.float :amount, null: false
13
-
14
- t.timestamps
15
- end
16
- add_index(:cats_core_hrp_item_details, [:hrp_item_id, :ration_item_id], unique: true, name: 'hii_rii_on_hid_indx')
17
- end
18
- end
@@ -1,7 +0,0 @@
1
- FactoryBot.define do
2
- factory :hrp_item_detail, class: 'Cats::Core::HrpItemDetail' do
3
- hrp_item
4
- ration_item
5
- amount { 150 }
6
- end
7
- end
@@ -1,10 +0,0 @@
1
- FactoryBot.define do
2
- factory :hrp, class: 'Cats::Core::Hrp' do
3
- reference_no { FFaker::Name.name }
4
- year { 1 }
5
- season { Cats::Core::Hrp::BELG }
6
- status { Cats::Core::Hrp::DRAFT }
7
- program
8
- ration
9
- end
10
- end