cats_core 1.3.7 → 1.3.11

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: 9380d0ff2181f5043d3c4d4f6251dde2561d5b08013959b6848558b505dbba2d
4
- data.tar.gz: 1dc278bcfb116197b0c04620de35f042669a11e5690ce14fa93959a252f0e922
3
+ metadata.gz: 07bfd5b8cfedc80be5973e4c41ab660e71e1cc55dafea9dc3f0ad9669ce54382
4
+ data.tar.gz: 44265ec189d02cbb4e8553c3f2a837f78275a03a3a82d5c33e1a43f5695592e8
5
5
  SHA512:
6
- metadata.gz: 0cecc9ef0cf5fc29c4b912e5b513afd23db6f6d607a93bdcd927348b2f11928df5624ccde4ae80b12048db368f1da25f4b8781b5a22014cb1b1fc2e0e251dba5
7
- data.tar.gz: e3e5fbbe9e672a276f80a1d90e5c4b6a1958b5ccf894b1196387a7e9f50ce44a3d8285afdbcc8100c04b91702f9efa55b3b099074fd44330c6aa3ec38df53f6b
6
+ metadata.gz: c06175c94d4b3a39e011355104a963553d271a296e12f6e72af2e541d94aa2cf53a7898b953416f014012d6dddfa5738ba07d52e268193d7aab4103a692746b3
7
+ data.tar.gz: a21021e5054816d3ede7ac9ecadb7746bd2f9f62a43f977d90452350989003398fcb807aa59d15ff4a87975a7dd88debbdf7ae3ee1fc992ffbb6604aab77a025
@@ -1,11 +1,16 @@
1
1
  module Cats
2
2
  module Core
3
3
  class MonthlyPlan < ApplicationRecord
4
- belongs_to :ration
5
4
  belongs_to :plan
5
+ belongs_to :regional_request
6
+
7
+ has_many :monthly_plan_items
8
+ has_many :monthly_rations
6
9
 
7
10
  validates :reference_no, presence: true, uniqueness: true
8
11
  validates :status, presence: true, inclusion: { in: Cats::Core::Plan::STATUSES }
12
+
13
+ delegate(:reference_no, to: :regional_request, prefix: 'request')
9
14
  end
10
15
  end
11
16
  end
@@ -4,6 +4,8 @@ module Cats
4
4
  belongs_to :monthly_plan
5
5
  belongs_to :plan_item
6
6
 
7
+ has_many :monthly_plan_item_details
8
+
7
9
  validates :beneficiaries, presence: true, numericality: { greater_than: 0 }
8
10
  end
9
11
  end
@@ -0,0 +1,11 @@
1
+ module Cats
2
+ module Core
3
+ class MonthlyRation < ApplicationRecord
4
+ belongs_to :commodity_category
5
+ belongs_to :unit_of_measure
6
+ belongs_to :monthly_plan
7
+
8
+ validates :amount, :no_of_days, presence: true, numericality: { greater_than: 0 }
9
+ end
10
+ end
11
+ end
@@ -2,12 +2,14 @@ module Cats
2
2
  module Core
3
3
  class RegionalRequest < ApplicationRecord
4
4
  belongs_to :plan
5
+ belongs_to :region, class_name: 'Cats::Core::Location'
5
6
 
6
7
  validates :reference_no, presence: true, uniqueness: true
7
8
  validates :beneficiaries, :no_of_days, :month, presence: true, numericality: { greater_than: 0 }
8
- validate :validate_month, :validate_beneficiaries
9
+ validate :validate_month, :validate_beneficiaries, :validate_region
9
10
 
10
11
  delegate(:reference_no, to: :plan, prefix: true)
12
+ delegate(:name, to: :region, prefix: true)
11
13
 
12
14
  def validate_month
13
15
  return unless month
@@ -23,6 +25,12 @@ module Cats
23
25
  total = plan.plan_items.sum(:beneficiaries)
24
26
  errors.add(:beneficiaries, "cannot be higher than #{total}.") if total < beneficiaries
25
27
  end
28
+
29
+ def validate_region
30
+ return unless region
31
+
32
+ errors.add(:region, 'is not valid.') unless region.location_type == Cats::Core::Location::REGION
33
+ end
26
34
  end
27
35
  end
28
36
  end
@@ -9,6 +9,10 @@ class CreateCatsCoreRegionalRequests < ActiveRecord::Migration[6.1]
9
9
  null: false,
10
10
  index: { name: 'plan_on_rr_indx' },
11
11
  foreign_key: { to_table: :cats_core_plans }
12
+ t.references :region,
13
+ null: false,
14
+ index: { name: 'region_on_rr_indx' },
15
+ foreign_key: { to_table: :cats_core_locations }
12
16
 
13
17
  t.timestamps
14
18
  end
@@ -3,14 +3,14 @@ class CreateCatsCoreMonthlyPlans < ActiveRecord::Migration[6.1]
3
3
  create_table :cats_core_monthly_plans do |t|
4
4
  t.string :reference_no, unique: true
5
5
  t.string :status, null: false, default: 'Draft'
6
- t.references :ration,
7
- null: false,
8
- index: { name: 'ration_on_mp_indx' },
9
- foreign_key: { to_table: :cats_core_rations }
10
6
  t.references :plan,
11
7
  null: false,
12
8
  index: { name: 'plan_on_mp_indx' },
13
9
  foreign_key: { to_table: :cats_core_plans }
10
+ t.references :regional_request,
11
+ null: false,
12
+ index: { name: 'rr_on_mp_indx' },
13
+ foreign_key: { to_table: :cats_core_regional_requests }
14
14
 
15
15
  t.timestamps
16
16
  end
@@ -0,0 +1,22 @@
1
+ class CreateCatsCoreMonthlyRations < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :cats_core_monthly_rations do |t|
4
+ t.references :commodity_category,
5
+ null: false,
6
+ index: { name: 'cc_on_mr_indx' },
7
+ foreign_key: { to_table: :cats_core_commodity_categories }
8
+ t.float :amount, null: false
9
+ t.references :unit_of_measure,
10
+ null: false,
11
+ index: { name: 'uom_on_mr_indx' },
12
+ foreign_key: { to_table: :cats_core_unit_of_measures }
13
+ t.integer :no_of_days, null: false
14
+ t.references :monthly_plan,
15
+ index: { name: 'mp_on_mr_indx' },
16
+ null: false,
17
+ foreign_key: { to_table: :cats_core_monthly_plans }
18
+
19
+ t.timestamps
20
+ end
21
+ end
22
+ end
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.3.7'.freeze
3
+ VERSION = '1.3.11'.freeze
4
4
  end
5
5
  end
@@ -2,7 +2,7 @@ FactoryBot.define do
2
2
  factory :monthly_plan, class: 'Cats::Core::MonthlyPlan' do
3
3
  reference_no { FFaker::Name.name }
4
4
  status { Cats::Core::Plan::DRAFT }
5
- ration
6
5
  plan
6
+ regional_request
7
7
  end
8
8
  end
@@ -0,0 +1,9 @@
1
+ FactoryBot.define do
2
+ factory :monthly_ration, class: 'Cats::Core::MonthlyRation' do
3
+ commodity_category
4
+ amount { 100 }
5
+ unit_of_measure
6
+ no_of_days { 30 }
7
+ monthly_plan
8
+ end
9
+ end
@@ -5,6 +5,7 @@ FactoryBot.define do
5
5
  3.times { create(:plan_item, plan: pl, beneficiaries: 100) }
6
6
  pl
7
7
  end
8
+ region factory: :location
8
9
  reference_no { FFaker::Name.name }
9
10
  beneficiaries { 100 }
10
11
  month { 1 }
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.3.7
4
+ version: 1.3.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-07 00:00:00.000000000 Z
11
+ date: 2022-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers
@@ -272,6 +272,7 @@ files:
272
272
  - app/models/cats/core/monthly_plan.rb
273
273
  - app/models/cats/core/monthly_plan_item.rb
274
274
  - app/models/cats/core/monthly_plan_item_detail.rb
275
+ - app/models/cats/core/monthly_ration.rb
275
276
  - app/models/cats/core/notification.rb
276
277
  - app/models/cats/core/notification_rule.rb
277
278
  - app/models/cats/core/offer_item.rb
@@ -388,6 +389,7 @@ files:
388
389
  - db/migrate/20220107121752_create_cats_core_monthly_plans.rb
389
390
  - db/migrate/20220107125025_create_cats_core_monthly_plan_items.rb
390
391
  - db/migrate/20220107132433_create_cats_core_monthly_plan_item_details.rb
392
+ - db/migrate/20220107224630_create_cats_core_monthly_rations.rb
391
393
  - lib/cats/core.rb
392
394
  - lib/cats/core/engine.rb
393
395
  - lib/cats/core/version.rb
@@ -414,6 +416,7 @@ files:
414
416
  - spec/factories/cats/core/monthly_plan_item_details.rb
415
417
  - spec/factories/cats/core/monthly_plan_items.rb
416
418
  - spec/factories/cats/core/monthly_plans.rb
419
+ - spec/factories/cats/core/monthly_rations.rb
417
420
  - spec/factories/cats/core/notification_rules.rb
418
421
  - spec/factories/cats/core/notifications.rb
419
422
  - spec/factories/cats/core/offer_items.rb