cats_core 1.2.12 → 1.2.16

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: c6d9c981d6dfe00647462832e97d47af7fc677b5e092a5f675366ae1e49ac8dc
4
- data.tar.gz: b24adf0ed11330190cfd57050c94ead1f871e183339351d2caebcc2b09597536
3
+ metadata.gz: 83ed27840275615cce0b4a2fdee9d147a61407eef87df375e9db5e0424d4e923
4
+ data.tar.gz: 06a77ee55dec5a1d292afeaa225b35629867d85eac43640d5073aab84b657634
5
5
  SHA512:
6
- metadata.gz: 56857803a15398dadccd2396e3a2d1b4124b392258ecc180f678d70ddca5a3dafa7b222774b34a9b2d93e8d23aa928622de3d78772017020c7c67f7996ede95c
7
- data.tar.gz: f7b0c9cdbacfec2c9836a80560b2c93a69281e4be503e850ee433ca64917d1703c4bf83d2d59c668495f93fa4371350e9573569ce87ea5207b45a54a18d8b8ac
6
+ metadata.gz: f57ac8ebc0d69cb0abc5e0b19a28ae3afd4b3549a72b2fe34469bf63e15bc05067fa101bc378b97f073b5650b66d21516d9ea7998d165e8e5b133d971e08dbfe
7
+ data.tar.gz: 41f293dd59320cafef958b1d1dcf6b2342e2af1d696e31fb761ff50cf749966e5a993062d23f3e859c32bbb0431cba93c333b7410977be67a33c1bb8575e829a
@@ -3,11 +3,26 @@ module Cats
3
3
  class DispatchPlansController < ApplicationController
4
4
  include Common
5
5
 
6
+ def plans_for_user
7
+ plans = Cats::Core::DispatchPlan.where(prepared_by: current_user)
8
+ render json: { success: true, data: serialize(plans) }
9
+ end
10
+
6
11
  def filter
7
12
  query = Cats::Core::DispatchPlan.ransack(params[:q])
8
13
  render json: { success: true, data: serialize(query.result) }
9
14
  end
10
15
 
16
+ def create
17
+ obj = Cats::Core::DispatchPlan.new(model_params)
18
+ obj.prepared_by = current_user
19
+ if obj.save
20
+ render json: { success: true, data: serialize(obj) }, status: :created
21
+ else
22
+ render json: { success: false, error: obj.errors.full_messages[0] }, status: :unprocessable_entity
23
+ end
24
+ end
25
+
11
26
  def approve
12
27
  plan = Cats::Core::DispatchPlan.find(params[:id])
13
28
  plan.approve
@@ -6,6 +6,9 @@ module Cats
6
6
  STATUSES = [DRAFT, APPROVED].freeze
7
7
 
8
8
  belongs_to :request, polymorphic: true, optional: true
9
+ belongs_to :prepared_by, class_name: 'Cats::Core::User'
10
+ belongs_to :approved_by, class_name: 'Cats::Core::User', optional: true
11
+
9
12
  has_many :dispatch_plan_items
10
13
 
11
14
  validates :reference_no, presence: true, uniqueness: true
@@ -5,8 +5,24 @@ module Cats
5
5
  belongs_to :transporter
6
6
 
7
7
  validates :price, presence: true, numericality: { greater_than: 0 }
8
+ validates :rank, numericality: { greater_than: 0 }, allow_nil: true
9
+ validate :validate_rank_is_set_for_winner
8
10
 
9
11
  delegate(:name, to: :transporter, prefix: true)
12
+
13
+ def mark_as_winner(rank)
14
+ raise(StandardError, 'Offer already marked as winner.') if winner
15
+
16
+ self.rank = rank
17
+ self.winner = true
18
+ save!
19
+ end
20
+
21
+ def validate_rank_is_set_for_winner
22
+ return if rank
23
+
24
+ errors.add(:winner, 'cannot be set for a non-ranked offer.') if winner
25
+ end
10
26
  end
11
27
  end
12
28
  end
@@ -21,6 +21,8 @@ module Cats
21
21
  def approve(approver)
22
22
  raise(StandardError, 'Request is not open for approval.') unless status == DRAFT
23
23
 
24
+ raise(StandardError, 'Request is empty.') if transport_request_items.count.zero?
25
+
24
26
  self.approved_by = approver
25
27
  self.status = APPROVED
26
28
  save!
@@ -6,6 +6,8 @@ module Cats
6
6
  belongs_to :destination, class_name: 'Cats::Core::Location'
7
7
  belongs_to :commodity
8
8
 
9
+ has_many :transport_offers
10
+
9
11
  delegate(:name, to: :source, prefix: true)
10
12
  delegate(:name, to: :destination, prefix: true)
11
13
  delegate(:name, to: :commodity, prefix: true)
data/config/routes.rb CHANGED
@@ -33,6 +33,7 @@ Cats::Core::Engine.routes.draw do
33
33
  get 'stores', controller: :users, action: :stores
34
34
  get 'warehouse', controller: :users, action: :warehouse
35
35
  get 'hub', controller: :users, action: :hub
36
+ get 'plans', controller: :dispatch_plans, action: :plans_for_user
36
37
  post 'assign_role'
37
38
  post 'revoke_role'
38
39
  end
@@ -7,6 +7,15 @@ class CreateCatsCoreDispatchPlans < ActiveRecord::Migration[6.1]
7
7
  t.references :request, polymorphic: true
8
8
  t.boolean :upstream, null: false, default: false
9
9
 
10
+ t.references :prepared_by,
11
+ null: false,
12
+ index: { name: 'pb_on_dp_indx' },
13
+ foreign_key: { to_table: :cats_core_users }
14
+ t.references :approved_by,
15
+ null: true,
16
+ index: { name: 'ab_on_dp_indx' },
17
+ foreign_key: { to_table: :cats_core_users }
18
+
10
19
  t.timestamps
11
20
  end
12
21
  end
@@ -10,6 +10,8 @@ class CreateCatsCoreTransportOffers < ActiveRecord::Migration[6.1]
10
10
  index: { name: 'to_on_transporter_indx' },
11
11
  foreign_key: { to_table: :cats_core_transporters }
12
12
  t.float :price, null: false
13
+ t.boolean :winner, null: false, default: false
14
+ t.integer :rank
13
15
 
14
16
  t.timestamps
15
17
  end
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.2.12'.freeze
3
+ VERSION = '1.2.16'.freeze
4
4
  end
5
5
  end
@@ -4,5 +4,7 @@ FactoryBot.define do
4
4
  status { Cats::Core::DispatchPlan::DRAFT }
5
5
  request { nil }
6
6
  upstream { false }
7
+ prepared_by factory: :user
8
+ approved_by { nil }
7
9
  end
8
10
  end
@@ -3,5 +3,7 @@ FactoryBot.define do
3
3
  transport_request_item
4
4
  transporter
5
5
  price { 100 }
6
+ winner { false }
7
+ rank { nil }
6
8
  end
7
9
  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.2.12
4
+ version: 1.2.16
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-12-12 00:00:00.000000000 Z
11
+ date: 2021-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers