cats_core 1.0.22 → 1.0.26

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: 7847bbf4c0a83ac387d2b9e7bc1f8f4b4ffe184d12f9611ee60c6f14d1fe3078
4
- data.tar.gz: 319c387eeddbd6342b1b4fe14ea921e7c3e686243feded978cad60d96c9756ad
3
+ metadata.gz: 3f7140f7b94aaf47e0b5cfcb9ad89515a6884a6f59c685d7bf3b10978d2239e8
4
+ data.tar.gz: d10e11f6f3506f4513921bb85814d1303bea873558c8603241b87df4474aa777
5
5
  SHA512:
6
- metadata.gz: 5ec1c786270a96caa0097f2cd8c95d4a14e88b255d2def862f246770c36fd6956fc6b9e401ea931c4a306c0444c1ca9487fd64439769810249730c407b1e2ecb
7
- data.tar.gz: eafd2a9293936dab8f7130c9428598fdc88fffb4b7a294e3f381fb08f985d9b379e5d268aa340ab5cfce4952da6c6b10b8b4b829cce8309268f48fb26de3b7ba
6
+ metadata.gz: 6a63abe18b61954481d0e758aa4a714bc201d2270febe2b86c157806c8ba9a7dafc44399177079fe5bf5bfed3dc916634cfae1a711ab3030ee8c2a95cc9c514a
7
+ data.tar.gz: 0ec75ce43af82a2dd05e1b3d7836893e273741c7cbb2bc074e49582cf0231b9105d8e4d9b0f0d44a08760dd40cb9bdd83e8b1bbcb4dbbce47ae3711417de64d1
@@ -1,17 +1,37 @@
1
1
  module Cats
2
2
  module Core
3
3
  class Commodity < ApplicationRecord
4
+ after_initialize :set_approved
5
+
4
6
  # Commodity statuses
5
7
  GOOD = 'Good'.freeze
6
8
  DAMAGED = 'Damaged'.freeze
7
9
  COMMODITY_STATUSES = [GOOD, DAMAGED].freeze
8
10
 
11
+ # Arrival Statuses
12
+ AT_SOURCE = 'At Source'.freeze
13
+ IN_TRANSIT = 'In Transit'.freeze
14
+ ARRIVED = 'Arrived'.freeze
15
+ ARRIVAL_STATUSES = [AT_SOURCE, IN_TRANSIT, ARRIVED].freeze
16
+
9
17
  belongs_to :unit_of_measure
10
18
  belongs_to :source, polymorphic: true
19
+ belongs_to :commodity_category
11
20
 
12
21
  validates :best_use_before, presence: true
22
+ validates :batch_no, presence: true, uniqueness: true
13
23
  validates :quantity, presence: true, numericality: { greater_than: 0 }
14
24
  validates :volume_per_metric_ton, numericality: { greater_than: 0, allow_nil: true }
25
+ validates :arrival_status, presence: true, inclusion: { in: ARRIVAL_STATUSES }
26
+
27
+ delegate(:abbreviation, to: :unit_of_measure, prefix: true)
28
+ delegate(:name, to: :commodity_category, prefix: true)
29
+
30
+ def set_approved
31
+ return unless new_record?
32
+
33
+ self.approved = false
34
+ end
15
35
  end
16
36
  end
17
37
  end
@@ -13,6 +13,9 @@ module Cats
13
13
  validates :reference_no, uniqueness: true
14
14
  validates :donation_type, inclusion: { in: DONATION_TYPES }
15
15
  validates :currency, :amount, presence: true, if: -> { donation_type == CASH }
16
+
17
+ delegate(:name, to: :donor, prefix: true)
18
+ delegate(:reference_no, to: :hrp, prefix: true)
16
19
  end
17
20
  end
18
21
  end
@@ -6,6 +6,8 @@ module Cats
6
6
 
7
7
  validates :reference_no, presence: true, uniqueness: true
8
8
  validates :gift_date, presence: true
9
+
10
+ delegate(:name, to: :commodity_category, prefix: true)
9
11
  end
10
12
  end
11
13
  end
@@ -6,6 +6,8 @@ module Cats
6
6
 
7
7
  validates :reference_no, :order_date, :supplier, presence: true
8
8
  validates :reference_no, uniqueness: true
9
+
10
+ delegate(:name, to: :commodity_category, prefix: true)
9
11
  end
10
12
  end
11
13
  end
@@ -1,15 +1,22 @@
1
1
  class CreateCatsCoreCommodities < ActiveRecord::Migration[6.1]
2
2
  def change
3
3
  create_table :cats_core_commodities do |t|
4
+ t.string :batch_no, unique: true
4
5
  t.references :unit_of_measure,
5
6
  null: false,
6
7
  index: { name: 'uom_on_commodities_indx' },
7
8
  foreign_key: { to_table: :cats_core_unit_of_measures }
9
+ t.references :commodity_category,
10
+ null: false,
11
+ index: { name: 'cc_on_commodities_indx' },
12
+ foreign_key: { to_table: :cats_core_commodity_categories }
8
13
  t.references :source, polymorphic: true
9
14
  t.float :quantity, null: false
10
15
  t.string :description
11
16
  t.date :best_use_before, null: false
12
17
  t.float :volume_per_metric_ton
18
+ t.string :arrival_status, null: false, default: 'At Source'
19
+ t.boolean :approved, null: false, default: false
13
20
 
14
21
  t.timestamps
15
22
  end
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.0.22'.freeze
3
+ VERSION = '1.0.26'.freeze
4
4
  end
5
5
  end
@@ -1,10 +1,14 @@
1
1
  FactoryBot.define do
2
2
  factory :commodity, class: 'Cats::Core::Commodity' do
3
+ batch_no { FFaker::Name.name }
3
4
  description { FFaker::Name.name }
4
5
  unit_of_measure
6
+ commodity_category
5
7
  source factory: :gift_certificate
6
8
  quantity { 100 }
7
9
  best_use_before { Date.today + 2.month }
8
10
  volume_per_metric_ton { 10 }
11
+ arrival_status { Cats::Core::Commodity::AT_SOURCE }
12
+ approved { false }
9
13
  end
10
14
  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.0.22
4
+ version: 1.0.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.