cats_core 1.0.23 → 1.0.27
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 970aba78ce14d116f4047df8371d5ca03949f5a668bd2c613cdfb494e652e9e4
|
4
|
+
data.tar.gz: ca25ae5f908ba942045b39f91679a8e365cd171541d008e088e46ff3d8a166e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c353f8a17d427a846408ad27ea90c6d3114179ff4634e7b2e8410f058861bf70114be3d75c2992da2be24bf16649d5b4f3717a52b9e901db3945d51f5d08ddbc
|
7
|
+
data.tar.gz: 79f09a8add5e295b1fe5414137c4986e70f74e01613bb75291f5f802380fbbc5b3ed4b588fa4e79bb75863f885462e195b24a5ca25bd12d705e39e821bca5710
|
@@ -1,17 +1,38 @@
|
|
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
|
+
delegate(:reference_no, to: :source, prefix: true)
|
30
|
+
|
31
|
+
def set_approved
|
32
|
+
return unless new_record?
|
33
|
+
|
34
|
+
self.approved = false
|
35
|
+
end
|
15
36
|
end
|
16
37
|
end
|
17
38
|
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
|
data/lib/cats/core/version.rb
CHANGED
@@ -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
|