cats_core 1.5.6 → 1.5.8

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: 3cb500b5c99210b40ab7cd416cd861caf4cd61528515e5317ba1abc9690ab2a9
4
- data.tar.gz: 4279dca09b00c065f1c4568c12baa404970ce8fa093d0eba4939e232eb849692
3
+ metadata.gz: 02b7883db68e256449e949034e2b56a5c40387292ab61c7346a429f1d94a04f7
4
+ data.tar.gz: 7d0230d0c98ca9c7b57ccd23bc410c7c5b0126eca37c3daca4707dd95e154a08
5
5
  SHA512:
6
- metadata.gz: e90c5c515b3fdd39a415dd6b174b0dddfac4775b067822aeec0dca3193125857fbc918cc46b04428a70badd5817353b2fd1eded643c387f66f1bbbbabc6014d3
7
- data.tar.gz: 86ffddf979ddeead9980606491667acf4837606ef50d631230054c7e4c79180f7a2c6557f4aa747c0aa6ca918325a1045c7ae9a83bc86d8caa467e34284101d9
6
+ metadata.gz: 1e865e4a70b174511dd8de23aeab18e54cea7847583a206d6da5609e9487137de117b0ef3461e77f89706e88094c3f1a99249a88686ac191e61e93efb7c62a4b
7
+ data.tar.gz: 9785438a4a1ce510068ebb3a693d89eb0d66297132b8b700968f3c32eec45317ed2cde89f771dfb4d63cacc03aad35eb21818d6774d236a3022c61569635e1af
@@ -3,9 +3,12 @@ module Cats
3
3
  class RoundPlanItemDetail < ApplicationRecord
4
4
  belongs_to :beneficiary_round_plan_item
5
5
  belongs_to :round_ration
6
+ belongs_to :unit, class_name: 'Cats::Core::UnitOfMeasure'
6
7
 
7
8
  validates :quantity, presence: true, numericality: { greater_than: 0 }
8
9
  validates :beneficiary_round_plan_item_id, uniqueness: { scope: :round_ration_id }
10
+
11
+ delegate(:abbreviation, to: :unit, prefix: true)
9
12
  end
10
13
  end
11
14
  end
@@ -19,12 +19,17 @@ module Cats
19
19
  round_rations.each do |ration|
20
20
  quantity = (no_of_days / ration.no_of_days * ration.quantity) * plan_item.beneficiaries *
21
21
  round_plan.rounds.count
22
- quantity = UnitConversion.convert(ration.unit, mt, quantity) if ration.unit.abbreviation.downcase != 'pcs'
22
+ unit = ration.unit
23
+ if ration.unit.abbreviation.downcase != 'pc'
24
+ quantity = UnitConversion.convert(unit, mt, quantity)
25
+ unit = mt
26
+ end
23
27
 
24
28
  details << {
25
29
  beneficiary_round_plan_item_id: plan_item.id,
26
30
  round_ration_id: ration.id,
27
- quantity: quantity
31
+ quantity: quantity,
32
+ unit_id: unit.id
28
33
  }
29
34
  end
30
35
  end
@@ -10,6 +10,10 @@ class CreateCatsCoreRoundPlanItemDetails < ActiveRecord::Migration[6.1]
10
10
  index: { name: 'rr_on_rpid_indx' },
11
11
  foreign_key: { to_table: :cats_core_round_rations }
12
12
  t.float :quantity, null: false
13
+ t.references :unit,
14
+ null: false,
15
+ index: { name: 'unit_on_rpid_indx' },
16
+ foreign_key: { to_table: :cats_core_unit_of_measures }
13
17
 
14
18
  t.timestamps
15
19
  end
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.5.6'.freeze
3
+ VERSION = '1.5.8'.freeze
4
4
  end
5
5
  end
@@ -1,7 +1,11 @@
1
1
  FactoryBot.define do
2
2
  factory :round_plan_item_detail, class: 'Cats::Core::RoundPlanItemDetail' do
3
+ transient do
4
+ mt { create(:unit_of_measure, abbreviation: 'mt', name: 'Metric Tonne') }
5
+ end
3
6
  beneficiary_round_plan_item
4
7
  round_ration
5
8
  quantity { 150 }
9
+ unit { round_ration.unit.abbreviation == 'pc' ? round_ration.unit : mt }
6
10
  end
7
11
  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.5.6
4
+ version: 1.5.8
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-10-01 00:00:00.000000000 Z
11
+ date: 2022-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers