cats_core 1.1.14 → 1.1.15

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: 849c78b04184a39a42337994d2cf68e4be874dff4e0420e34a890ce0584658cd
4
- data.tar.gz: 85b1a1ff55a91d353329eaebb38e5ff19bb2590bfa8ab2942dd5feb31a7b11c6
3
+ metadata.gz: 9c73eb407823b6e404e576cd94dd8ac14228db71edce2fab923be1fc4a76752a
4
+ data.tar.gz: 43743939e2a9b6f3aaa3f27c5898e52619d7c00ec36896cd2d4c587a90ead623
5
5
  SHA512:
6
- metadata.gz: 18cb896b37d1c7449e8955e7209bcf663e02b0e43d42fe0c7137f9f8a0e4be5ed1f664d8bc2b2f4e777e15b6f8b6c8efb57114cdb283cdffbc8f51dff6c75d7a
7
- data.tar.gz: e477156c701bee3b6dfb5c337fb344bcb1e86d16978e0208e8a9616a7721af364ff63862045f85db2ac825dd8fc876b0198ec87f857a4844064cdf7336a8a315
6
+ metadata.gz: 224e70bc25588e883cdc642db7e85dfb18c2389a9f147ada262a3891feedaf595f827fe28fb8c092449ef2ec7f3c70c8dff4a7f20891fb4d5756ec61e363a2f8
7
+ data.tar.gz: 9eaf7c258dcf29107a7ec15c6db97c088dfa5569a3ceabcccd4c179f82c6edecc7e231139c403abe52577cea6153795ea0723eaab91d821c9b4726ccfe1c3399
@@ -16,7 +16,6 @@ module Cats
16
16
 
17
17
  belongs_to :unit_of_measure
18
18
  belongs_to :source, polymorphic: true
19
- belongs_to :commodity_category
20
19
 
21
20
  validates :best_use_before, presence: true
22
21
  validates :batch_no, presence: true, uniqueness: true
@@ -25,7 +24,6 @@ module Cats
25
24
  validates :arrival_status, presence: true, inclusion: { in: ARRIVAL_STATUSES }
26
25
 
27
26
  delegate(:abbreviation, to: :unit_of_measure, prefix: true)
28
- delegate(:name, to: :commodity_category, prefix: true)
29
27
  delegate(:reference_no, to: :source, prefix: true)
30
28
 
31
29
  def set_approved
@@ -33,6 +31,10 @@ module Cats
33
31
 
34
32
  self.approved = false
35
33
  end
34
+
35
+ def name
36
+ source.commodity_category.name
37
+ end
36
38
  end
37
39
  end
38
40
  end
@@ -2,10 +2,14 @@ module Cats
2
2
  module Core
3
3
  class GiftCertificate < ApplicationRecord
4
4
  belongs_to :donation
5
+ belongs_to :commodity_category
6
+ belongs_to :unit_of_measure
5
7
 
6
8
  validates :reference_no, presence: true, uniqueness: true
7
- validates :gift_date, presence: true
9
+ validates :gift_date, :quantity, presence: true
10
+ validates :quantity, numericality: { greater_than: 0 }
8
11
 
12
+ before_save :set_commodity_category
9
13
  after_create :update_donation
10
14
 
11
15
  def update_donation
@@ -15,6 +19,14 @@ module Cats
15
19
  donation.active = true
16
20
  donation.save!
17
21
  end
22
+
23
+ def set_commodity_category
24
+ return unless donation
25
+
26
+ return if commodity_category == donation.commodity_category
27
+
28
+ self.commodity_category = donation.commodity_category
29
+ end
18
30
  end
19
31
  end
20
32
  end
@@ -1,9 +1,9 @@
1
1
  module Cats
2
2
  module Core
3
3
  class CommoditySerializer < ActiveModel::Serializer
4
- attributes :id, :batch_no, :description, :unit_of_measure_id, :unit_of_measure_abbreviation, :source_id,
4
+ attributes :id, :name, :batch_no, :description, :unit_of_measure_id, :unit_of_measure_abbreviation, :source_id,
5
5
  :source_type, :source_reference_no, :quantity, :best_use_before, :volume_per_metric_ton,
6
- :commodity_category_id, :commodity_category_name, :arrival_status, :approved
6
+ :arrival_status, :approved
7
7
  end
8
8
  end
9
9
  end
@@ -15,7 +15,15 @@ class CreateCatsCoreGiftCertificates < ActiveRecord::Migration[6.1]
15
15
  t.integer :purchase_year
16
16
  t.date :expiry_date
17
17
  t.string :bill_of_lading_no
18
- t.float :amount, null: false
18
+ t.float :quantity, null: false
19
+ t.references :commodity_category,
20
+ null: false,
21
+ index: { name: 'gc_on_cc_indx' },
22
+ foreign_key: { to_table: :cats_core_commodity_categories }
23
+ t.references :unit_of_measure,
24
+ null: false,
25
+ index: { name: 'uom_on_gc_indx' },
26
+ foreign_key: { to_table: :cats_core_unit_of_measures }
19
27
  t.float :estimated_price
20
28
  t.float :estimated_tax
21
29
 
@@ -6,10 +6,6 @@ class CreateCatsCoreCommodities < ActiveRecord::Migration[6.1]
6
6
  null: false,
7
7
  index: { name: 'uom_on_commodities_indx' },
8
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 }
13
9
  t.references :source, polymorphic: true
14
10
  t.float :quantity, null: false
15
11
  t.string :description
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.1.14'.freeze
3
+ VERSION = '1.1.15'.freeze
4
4
  end
5
5
  end
@@ -3,7 +3,6 @@ FactoryBot.define do
3
3
  batch_no { FFaker::Name.name }
4
4
  description { FFaker::Name.name }
5
5
  unit_of_measure
6
- commodity_category
7
6
  source factory: :gift_certificate
8
7
  quantity { 100 }
9
8
  best_use_before { Date.today + 2.month }
@@ -3,13 +3,15 @@ FactoryBot.define do
3
3
  reference_no { FFaker::Name.name }
4
4
  gift_date { Date.today - 1.month }
5
5
  donation
6
+ commodity_category { donation.commodity_category }
7
+ unit_of_measure
6
8
  vessel { FFaker::Name.name }
7
9
  port { FFaker::Name.name }
8
10
  customs_declaration_no { FFaker::Name.name }
9
11
  purchase_year { 1 }
10
12
  expiry_date { Date.today + 6.month }
11
13
  bill_of_lading_no { FFaker::Name.name }
12
- amount { 1.5 }
14
+ quantity { 1.5 }
13
15
  estimated_price { 1.5 }
14
16
  estimated_tax { 1.5 }
15
17
  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.1.14
4
+ version: 1.1.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.