cats_core 1.4.9 → 1.4.10

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: a1eacca23e0a10e3a707dcc45f51e2c44013fccb7a35182f3d7476c95d0bcad8
4
- data.tar.gz: bcbcaf4bda959f028521528e8e7c979bca422037c9e4abb913449f831cadc73b
3
+ metadata.gz: 5c497f5ed7c7fd9a82dd7a8f2450db08ab9e6ea307cfebf448819c15affe9baa
4
+ data.tar.gz: 0c7514559659448cf6b1b83381b3eda706b37497b7fc2d4e2556430c50cfe21a
5
5
  SHA512:
6
- metadata.gz: b34d8901501515edaa28a7aea773ccea4156f079124be80200ab77673f22357e3f1e7891e667244ec8ffcc11a6310a5a575a36ab549468dc292fc7ad5bc868b5
7
- data.tar.gz: bc9c7ea903b2cfaf05db1819391c0c5b2d2999498b3ee488263c240bc2971a67fe85b24911afd1432ef7aef81bc6b6f473cfc0ba34516839a93cc69b06571ad1
6
+ metadata.gz: cda6953720eb9492fd45083008ab61c38dc28ed1d7f1995f882335725d9f2beeb07b4e1bf1b012eddb6639bce628c6c3e98c939fe6ce59d18ad450d91bd17ffc
7
+ data.tar.gz: 8785eba470967b8c6b765363c9c88d27270e482a1196decc995182030a6448160590eabe0bb696fabcdceed73e59f17cfffd2c6edb88d9870b4c45fe496652e7
@@ -0,0 +1,24 @@
1
+ module Cats
2
+ module Core
3
+ class TransportOrder < ApplicationRecord
4
+ DRAFT = 'Draft'.freeze
5
+ APPROVED = 'Approved'.freeze
6
+ STATUSES = [DRAFT, APPROVED].freeze
7
+
8
+ belongs_to :transport_requisition
9
+ belongs_to :prepared_by, class_name: 'Cats::Core::User'
10
+ belongs_to :approved_by, class_name: 'Cats::Core::User'
11
+
12
+ validates :status, presence: true, inclusion: { in: STATUSES }
13
+ validate :validate_against_requisition
14
+
15
+ def validate_against_requisition
16
+ return unless transport_requisition
17
+
18
+ return if transport_requisition.approved?
19
+
20
+ errors.add(:transport_requisition, 'is not approved.')
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ module Cats
2
+ module Core
3
+ class TransportOrderItem < ApplicationRecord
4
+ belongs_to :transport_order
5
+ belongs_to :transporter
6
+ belongs_to :transport_requisition_item
7
+ belongs_to :transport_contract, optional: true
8
+
9
+ validates :order_date, :valid_for, presence: true
10
+ validates :valid_for, numericality: { greater_than: 0 }
11
+ validates :transport_requisition_item_id, uniqueness: true
12
+ validate :validate_requisition
13
+
14
+ def validate_requisition
15
+ return unless transport_requisition_item
16
+
17
+ return unless transport_order
18
+
19
+ return if transport_order.transport_requisition_id == transport_requisition_item.transport_requisition_id
20
+
21
+ errors.add(:transport_requisition_item, 'does not belong to the requisition of the order.')
22
+ end
23
+ end
24
+ end
25
+ end
@@ -14,6 +14,7 @@ module Cats
14
14
 
15
15
  validates :reference_no, presence: true, uniqueness: true
16
16
  validates :status, presence: true, inclusion: { in: STATUSES }
17
+ validate :validate_status
17
18
 
18
19
  delegate(:full_name, to: :requested_by, prefix: 'requestor')
19
20
  delegate(:full_name, to: :approved_by, prefix: 'approver', allow_nil: true)
@@ -28,13 +29,28 @@ module Cats
28
29
  def approve
29
30
  raise(StandardError, 'Transport requisition is already approved.') if status == APPROVED
30
31
 
31
- if transport_requisition_items.count.zero?
32
- raise(StandardError, 'Transport requisition has no requisition items.')
32
+ begin
33
+ self.status = APPROVED
34
+ save!
35
+ self
36
+ rescue ActiveRecord::RecordInvalid => e
37
+ error = e.record.errors.full_messages_for(:status)[0]
38
+ raise(StandardError, error)
33
39
  end
40
+ end
41
+
42
+ def approved?
43
+ status == APPROVED
44
+ end
45
+
46
+ def validate_status
47
+ return unless status
48
+
49
+ return if status == DRAFT
50
+
51
+ return if transport_requisition_items.count.positive?
34
52
 
35
- self.status = APPROVED
36
- save!
37
- self
53
+ errors.add(:status, 'cannot be set to "APPROVED" because the requisition has no items.') if status == APPROVED
38
54
  end
39
55
  end
40
56
  end
@@ -0,0 +1,21 @@
1
+ class CreateCatsCoreTransportOrders < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :cats_core_transport_orders do |t|
4
+ t.references :transport_requisition,
5
+ null: false,
6
+ index: { name: 'tr_on_to_indx' },
7
+ foreign_key: { to_table: :cats_core_transport_requisitions }
8
+ t.references :prepared_by,
9
+ null: false,
10
+ index: { name: 'pb_on_to_indx' },
11
+ foreign_key: { to_table: :cats_core_users }
12
+ t.references :approved_by,
13
+ null: false,
14
+ index: { name: 'ab_on_to_indx' },
15
+ foreign_key: { to_table: :cats_core_users }
16
+ t.string :status, null: false, default: 'Draft'
17
+
18
+ t.timestamps
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,33 @@
1
+ class CreateCatsCoreTransportOrderItems < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :cats_core_transport_order_items do |t|
4
+ t.references :transport_order,
5
+ null: false,
6
+ index: { name: 'to_on_toi_indx' },
7
+ foreign_key: { to_table: :cats_core_transport_orders }
8
+ t.references :transporter,
9
+ null: false,
10
+ index: { name: 'transporter_on_toi_indx' },
11
+ foreign_key: { to_table: :cats_core_transporters }
12
+ t.references :transport_contract,
13
+ null: true,
14
+ index: { name: 'tc_on_toi_indx' },
15
+ foreign_key: { to_table: :cats_core_transport_contracts }
16
+ t.references :transport_requisition_item,
17
+ null: false,
18
+ index: { name: 'tri_on_toi_indx' },
19
+ foreign_key: { to_table: :cats_core_transport_requisition_items }
20
+ t.date :order_date, null: false, default: Date.today
21
+ t.integer :valid_for, null: false, default: 10
22
+
23
+ t.timestamps
24
+ end
25
+
26
+ add_index(
27
+ :cats_core_transport_order_items,
28
+ :transport_requisition_item_id,
29
+ unique: true,
30
+ name: 'tri_on_toi_uniq_indx'
31
+ )
32
+ end
33
+ end
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.4.9'.freeze
3
+ VERSION = '1.4.10'.freeze
4
4
  end
5
5
  end
@@ -0,0 +1,10 @@
1
+ FactoryBot.define do
2
+ factory :transport_order_item, class: 'Cats::Core::TransportOrderItem' do
3
+ transport_order
4
+ transporter
5
+ transport_contract
6
+ transport_requisition_item { transport_order.transport_requisition.transport_requisition_items.first }
7
+ order_date { Date.today }
8
+ valid_for { 10 }
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ FactoryBot.define do
2
+ factory :transport_order, class: 'Cats::Core::TransportOrder' do
3
+ transport_requisition do
4
+ requisition = create(:transport_requisition)
5
+ create(:transport_requisition_item, transport_requisition: requisition)
6
+ requisition.approve
7
+ requisition
8
+ end
9
+ prepared_by factory: :user
10
+ approved_by factory: :user
11
+ status { Cats::Core::TransportOrder::DRAFT }
12
+ end
13
+ end
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.4.9
4
+ version: 1.4.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-21 00:00:00.000000000 Z
11
+ date: 2022-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers
@@ -307,6 +307,8 @@ files:
307
307
  - app/models/cats/core/transport_bid_item.rb
308
308
  - app/models/cats/core/transport_contract.rb
309
309
  - app/models/cats/core/transport_offer.rb
310
+ - app/models/cats/core/transport_order.rb
311
+ - app/models/cats/core/transport_order_item.rb
310
312
  - app/models/cats/core/transport_plan.rb
311
313
  - app/models/cats/core/transport_plan_item.rb
312
314
  - app/models/cats/core/transport_requisition.rb
@@ -410,6 +412,8 @@ files:
410
412
  - db/migrate/20220417105839_create_cats_core_transport_requisitions.rb
411
413
  - db/migrate/20220417123835_create_cats_core_transport_requisition_items.rb
412
414
  - db/migrate/20220417151821_create_cats_core_transport_requisition_details.rb
415
+ - db/migrate/20220506082329_create_cats_core_transport_orders.rb
416
+ - db/migrate/20220506083042_create_cats_core_transport_order_items.rb
413
417
  - lib/cats/core.rb
414
418
  - lib/cats/core/engine.rb
415
419
  - lib/cats/core/version.rb
@@ -464,6 +468,8 @@ files:
464
468
  - spec/factories/cats/core/transport_bids.rb
465
469
  - spec/factories/cats/core/transport_contracts.rb
466
470
  - spec/factories/cats/core/transport_offers.rb
471
+ - spec/factories/cats/core/transport_order_items.rb
472
+ - spec/factories/cats/core/transport_orders.rb
467
473
  - spec/factories/cats/core/transport_plan_items.rb
468
474
  - spec/factories/cats/core/transport_plans.rb
469
475
  - spec/factories/cats/core/transport_requisition_details.rb