cats_core 1.0.43 → 1.0.47

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: bda6e203d5cc23b15dfdb7cf523a175b4a620b5bfb4e630e89c088bf220162f3
4
- data.tar.gz: 2522727f3c712519f63681267b53405ce2b89a7dcdc599d1bc86810ce16b2bf5
3
+ metadata.gz: efb65bb9da37fbd6070d5844cdcd48c9c7c7e6a5b264c41e2103593e309838bd
4
+ data.tar.gz: 512001fdb9ddb2fa71fac19683b105632926a4cf75857b44a1a267c8710d02d9
5
5
  SHA512:
6
- metadata.gz: eede7fe1153179c4f3349c0124cccfe6c97e49941ff0ab9a4465239bb5afd05ea40c6e6d156b2693c288d6a9de7ebbe049b05e98474f5d91c630808820fe74d7
7
- data.tar.gz: 5c673873887a2cd373fc6c7fc586bd46477b9f377dfcab4b9328fc91cfb0ee515ac8c58ec3afd5139a7f99422019d68dbea709f24e6da8dfa312f2aecf23a33f
6
+ metadata.gz: 9f5188e5b7fbd88a26db6ee14473b199994b07fe42e475fea3b49fcb3dd63efe8beb07ad285733c9a9fcd14d1ef63740454905b4bd505c1217a02d7c3bb851b2
7
+ data.tar.gz: '082ab5a2755af2ce386e8c8636d1ae022fa6c486cd83d7da7410d74b26653d03f1d21f8ff5c79b936546f92bfc65c013fe781f5613e3ac8ae0c2ba895fbb7da0'
@@ -1,14 +1,19 @@
1
1
  module Cats
2
2
  module Core
3
3
  class Allocation < ApplicationRecord
4
+ DRAFT = 'Draft'.freeze
5
+ APPROVED = 'Approved'.freeze
6
+ ALLOCATION_STATUSES = [DRAFT, APPROVED].freeze
7
+
4
8
  belongs_to :rhn_request, optional: true
5
9
  belongs_to :commodity
6
10
  belongs_to :source, class_name: 'Cats::Core::Location'
7
11
 
8
- validates :commodity_status, presence: true
12
+ validates :commodity_status, :allocation_status, presence: true
9
13
  validates :reference_no, presence: true, uniqueness: true
10
14
  validates :quantity, presence: true, numericality: { greater_than: 0 }
11
15
  validates :commodity_status, inclusion: { in: Cats::Core::Commodity::COMMODITY_STATUSES }
16
+ validates :allocation_status, inclusion: { in: ALLOCATION_STATUSES }
12
17
 
13
18
  delegate(:reference_no, to: :rhn_request, prefix: :rhn, allow_nil: true)
14
19
  delegate(:batch_no, to: :commodity, prefix: true)
@@ -1,14 +1,38 @@
1
1
  module Cats
2
2
  module Core
3
3
  class Dispatch < ApplicationRecord
4
+ DRAFT = 'Draft'.freeze
5
+ APPROVED = 'Approved'.freeze
6
+ STARTED = 'Started'.freeze
7
+ ARRIVED = 'Arrived'.freeze
8
+ UNLOADED = 'Unloaded'.freeze
9
+ RECEIVED = 'Received'.freeze
10
+
11
+ DISPATCH_STATUSES = [DRAFT, APPROVED, STARTED, ARRIVED, UNLOADED, RECEIVED].freeze
12
+
4
13
  belongs_to :prepared_by, class_name: 'Cats::Core::User'
5
14
  belongs_to :transporter
6
15
  belongs_to :allocation_item
7
16
 
8
17
  validates :reference_no, :plate_no, :driver_name, :driver_phone, :quantity, :commodity_status, presence: true
18
+ validates :dispatch_status, presence: true, inclusion: { in: DISPATCH_STATUSES }
9
19
  validates :reference_no, uniqueness: true
10
20
  validates :quantity, numericality: { greater_than: 0 }
11
21
  validates :commodity_status, inclusion: { in: Cats::Core::Commodity::COMMODITY_STATUSES }
22
+ validate :validate_quantity
23
+
24
+ delegate(:name, to: :transporter, prefix: true)
25
+ delegate(:email, to: :prepared_by, prefix: true)
26
+
27
+ def validate_quantity
28
+ return unless quantity && allocation_item
29
+
30
+ return unless quantity_changed?
31
+
32
+ dispatched = Dispatch.where(allocation_item: allocation_item).sum(:quantity)
33
+ remaining = allocation_item.quantity - dispatched
34
+ errors.add(:quantity, "exceeds allocated quantity. Maximum allowed is #{remaining}") if quantity > remaining
35
+ end
12
36
  end
13
37
  end
14
38
  end
@@ -15,10 +15,14 @@ module Cats
15
15
  validates :reference_no, uniqueness: true
16
16
  validates :donation_type, inclusion: { in: DONATION_TYPES }
17
17
  validates :currency, presence: true, if: -> { donation_type == CASH }
18
- validates :commodity_category, :unit_of_measure, presence: true, if: -> { donation_type == KIND }
18
+ validates :commodity_category, presence: true, if: -> { donation_type == KIND }
19
+ validates :unit_of_measure, presence: true, if: -> { donation_type == KIND }
19
20
 
20
21
  delegate(:name, to: :donor, prefix: true)
21
22
  delegate(:reference_no, to: :hrp, prefix: true)
23
+ delegate(:name, to: :commodity_category, prefix: true, allow_nil: true)
24
+ delegate(:code, to: :currency, prefix: true, allow_nil: true)
25
+ delegate(:abbreviation, to: :unit_of_measure, prefix: true, allow_nil: true)
22
26
  end
23
27
  end
24
28
  end
@@ -2,12 +2,9 @@ module Cats
2
2
  module Core
3
3
  class GiftCertificate < ApplicationRecord
4
4
  belongs_to :donation
5
- belongs_to :commodity_category
6
5
 
7
6
  validates :reference_no, presence: true, uniqueness: true
8
7
  validates :gift_date, presence: true
9
-
10
- delegate(:name, to: :commodity_category, prefix: true)
11
8
  end
12
9
  end
13
10
  end
@@ -5,7 +5,8 @@ module Cats
5
5
  belongs_to :store_keeper, class_name: 'Cats::Core::User'
6
6
  has_many :stacks
7
7
 
8
- validates :name, :length, :width, :height, presence: true
8
+ validates :code, :name, :length, :width, :height, presence: true
9
+ validates :code, uniqueness: true
9
10
  validates :length, :width, :height, numericality: { greater_than: 0 }
10
11
  validates :gangway_length, :gangway_width, :gangway_corner_dist, presence: true, if: :has_gangway?
11
12
  validates :gangway_length,
@@ -8,10 +8,6 @@ class CreateCatsCoreGiftCertificates < ActiveRecord::Migration[6.1]
8
8
  null: false,
9
9
  index: { name: 'gc_on_donation_indx' },
10
10
  foreign_key: { to_table: :cats_core_donations }
11
- t.references :commodity_category,
12
- null: false,
13
- index: { name: 'gc_on_cc_indx' },
14
- foreign_key: { to_table: :cats_core_commodity_categories }
15
11
 
16
12
  t.string :vessel
17
13
  t.string :port
@@ -1,6 +1,7 @@
1
1
  class CreateCatsCoreStores < ActiveRecord::Migration[6.1]
2
2
  def change
3
3
  create_table :cats_core_stores do |t|
4
+ t.string :code, unique: true
4
5
  t.string :name, null: false
5
6
  t.float :length, null: false
6
7
  t.float :width, null: false
@@ -16,6 +16,7 @@ class CreateCatsCoreAllocations < ActiveRecord::Migration[6.1]
16
16
  foreign_key: { to_table: :cats_core_locations }
17
17
  t.float :quantity, null: false
18
18
  t.string :commodity_status, null: false, default: 'Good'
19
+ t.string :allocation_status, null: false, default: 'Draft'
19
20
  t.string :remark
20
21
 
21
22
  t.timestamps
@@ -20,6 +20,7 @@ class CreateCatsCoreDispatches < ActiveRecord::Migration[6.1]
20
20
  null: false,
21
21
  index: { name: 'pb_on_dispatches_indx' },
22
22
  foreign_key: { to_table: :cats_core_users }
23
+ t.string :dispatch_status, null: false
23
24
 
24
25
  t.timestamps
25
26
  end
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.0.43'.freeze
3
+ VERSION = '1.0.47'.freeze
4
4
  end
5
5
  end
@@ -6,6 +6,7 @@ FactoryBot.define do
6
6
  source factory: :location
7
7
  quantity { 50 }
8
8
  commodity_status { Cats::Core::Commodity::GOOD }
9
+ allocation_status { Cats::Core::Allocation::DRAFT }
9
10
  remark { FFaker::Name.name }
10
11
  end
11
12
  end
@@ -9,5 +9,6 @@ FactoryBot.define do
9
9
  quantity { 50 }
10
10
  remark { FFaker::Name.name }
11
11
  prepared_by factory: :user
12
+ dispatch_status { Cats::Core::Dispatch::DRAFT }
12
13
  end
13
14
  end
@@ -3,7 +3,6 @@ FactoryBot.define do
3
3
  reference_no { FFaker::Name.name }
4
4
  gift_date { Date.today - 1.month }
5
5
  donation
6
- commodity_category
7
6
  vessel { FFaker::Name.name }
8
7
  port { FFaker::Name.name }
9
8
  customs_declaration_no { FFaker::Name.name }
@@ -1,5 +1,6 @@
1
1
  FactoryBot.define do
2
2
  factory :store, class: 'Cats::Core::Store' do
3
+ code { FFaker::Name.name }
3
4
  name { FFaker::Name.name }
4
5
  length { 50 }
5
6
  width { 40 }
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.0.43
4
+ version: 1.0.47
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-20 00:00:00.000000000 Z
11
+ date: 2021-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers