cats_core 1.0.45 → 1.0.49

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: 296c1ea2692ccbfda9597044d6dd6f92a26dae42d008448d492a38b746906bc5
4
- data.tar.gz: 37594e0dff5425a1f6e037cf427793b1ca6af54b6fe1b2a04e00b139a96b5417
3
+ metadata.gz: 88f88c106a10c160703ee6898947a371aef510da88eea9aa514ff93e20c4e806
4
+ data.tar.gz: 2baa107b490e7372ed823c6d8fec83e91a19de41f77a48cd187e99eb2dc934bf
5
5
  SHA512:
6
- metadata.gz: af90696c4bfd02c65eb3b5d37a0be9a446d4a627e75c10ab2925d42038ff7113dfd2f56b8fd47403ffabeb106066e0644202f64cca49611956819eaf898989d3
7
- data.tar.gz: '007480b8cb6ded9688d94736634593e3004e6a1dc874a9e34d05674b9580c937046922d6dffd9a1d812501d09c2a188f4929ad9f23371ac82d43664a14653c55'
6
+ metadata.gz: f12a36ca3a10c537f09e6fd12b07e66d70b0bc69692badb2f9a0de6642d1b91f308ba53754456ecf35da935c7a380af3e7237bdda35690177ae0823acab8ef60
7
+ data.tar.gz: fdb2ed8c53e2d0c2e554017dce091be7056004b28a9dc3b0cbc6c4e343855957afcb64de644ccefc7649372c5c29584f98f9fc78ba9f0b0e6bb24bb96c434458
@@ -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)
@@ -4,8 +4,11 @@ module Cats
4
4
  DRAFT = 'Draft'.freeze
5
5
  APPROVED = 'Approved'.freeze
6
6
  STARTED = 'Started'.freeze
7
+ ARRIVED = 'Arrived'.freeze
8
+ UNLOADED = 'Unloaded'.freeze
9
+ RECEIVED = 'Received'.freeze
7
10
 
8
- DISPATCH_STATUSES = [DRAFT, APPROVED, STARTED].freeze
11
+ DISPATCH_STATUSES = [DRAFT, APPROVED, STARTED, ARRIVED, UNLOADED, RECEIVED].freeze
9
12
 
10
13
  belongs_to :prepared_by, class_name: 'Cats::Core::User'
11
14
  belongs_to :transporter
@@ -16,6 +19,20 @@ module Cats
16
19
  validates :reference_no, uniqueness: true
17
20
  validates :quantity, numericality: { greater_than: 0 }
18
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
19
36
  end
20
37
  end
21
38
  end
@@ -3,6 +3,9 @@ module Cats
3
3
  class DispatchTransaction < Transaction
4
4
  belongs_to :source, class_name: 'Cats::Core::Stack'
5
5
  belongs_to :destination, class_name: 'Cats::Core::Dispatch'
6
+
7
+ delegate(:code, to: :source, prefix: true)
8
+ delegate(:reference_no, to: :destination, prefix: true)
6
9
  end
7
10
  end
8
11
  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,
@@ -2,6 +2,7 @@ module Cats
2
2
  module Core
3
3
  class Transaction < ApplicationRecord
4
4
  self.abstract_class = true
5
+ after_initialize :set_status
5
6
 
6
7
  # Transaction statuses
7
8
  DRAFT = 'Draft'.freeze
@@ -25,8 +26,16 @@ module Cats
25
26
  destination.quantity += quantity
26
27
  source.save
27
28
  destination.save
29
+ self.status = COMMITTED
30
+ save
28
31
  end
29
32
  end
33
+
34
+ def set_status
35
+ return unless new_record?
36
+
37
+ self.status = DRAFT
38
+ end
30
39
  end
31
40
  end
32
41
  end
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.0.45'.freeze
3
+ VERSION = '1.0.49'.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
@@ -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.45
4
+ version: 1.0.49
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-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers