cats_core 1.5.6 → 1.5.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3cb500b5c99210b40ab7cd416cd861caf4cd61528515e5317ba1abc9690ab2a9
4
- data.tar.gz: 4279dca09b00c065f1c4568c12baa404970ce8fa093d0eba4939e232eb849692
3
+ metadata.gz: a7b180bedd093fa12aaf7cdbf46b9a9b4d5467f9a4679f3b977ed9bd57dddac9
4
+ data.tar.gz: e142956dce9922b02289fb0852109da69480b5c2ae459ff4fc892ef6a41fccc9
5
5
  SHA512:
6
- metadata.gz: e90c5c515b3fdd39a415dd6b174b0dddfac4775b067822aeec0dca3193125857fbc918cc46b04428a70badd5817353b2fd1eded643c387f66f1bbbbabc6014d3
7
- data.tar.gz: 86ffddf979ddeead9980606491667acf4837606ef50d631230054c7e4c79180f7a2c6557f4aa747c0aa6ca918325a1045c7ae9a83bc86d8caa467e34284101d9
6
+ metadata.gz: 37605aa2ffdc3a3f4d9741124a4b65bb3f5a8c8d73c925b0881529eca3545a86709d8a0e7600fbabcb005bd7418dfcc9cd06bff3fc895cb6d3c634f984c448e0
7
+ data.tar.gz: 0b8c7f19cd38d66128f16f6b87bbb1e2e383798213cd465482cdcd6bafeb37177bfaa2c62a5335f60eb852a01692501416c804f2ec074370173936dd9ba0821e
@@ -3,6 +3,7 @@ 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 }
@@ -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.7'.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.7
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