cats_core 1.4.17 → 1.4.20

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: 41699f66a4650b220cf3d02f028da8baade6d675d25f06823342d8fb11287309
4
- data.tar.gz: a1e7903ad574573c09a87df11fc67ca133546abee2a44efd3e2d12cd0d44982f
3
+ metadata.gz: d78b456ef9b9082680246207509f81b33ba4c9584136bafc00ac1dd9085e77cb
4
+ data.tar.gz: f1138cb24c4f94d7c42dd84b15916762c1f27c321531b1057f2b9e96a2da5c75
5
5
  SHA512:
6
- metadata.gz: a32b2685361ee616976123043970cf782d6180ac5b5d1d885ed3bf78dc4a36774ae004fc5640dd0fa50223f522c5c009a7be3ffb988c3edd05f7e454119e950b
7
- data.tar.gz: 4cf9dcd0928eeaec7bceb628cb21486263b07f426cb9846ae587c8112eec488e938a1735ebac5d7338a5a65cea507d15223a9a7eb2499575348106b893dc3acc
6
+ metadata.gz: 74b5f1fc12c9851dd07224c07b6a00912d44012f2347f87b3264cad20882f5950b9d27d9820c3c0b1526e26f32dfb83ee16263d77b4bcf2efdcd8f5ca30aaef9
7
+ data.tar.gz: 349b6c6a81040bf195ea723e9920f97711be1dce7c4257a5c7f03459d4b0cebd3d59ae650265ed952791c85330891df00d51c621c81c4948c85819f30ce07903
@@ -8,11 +8,34 @@ module Cats
8
8
  render json: { success: true, data: serialize(query.result) }
9
9
  end
10
10
 
11
+ def bulk_create
12
+ p = bulk_create_params
13
+ source = Location.find(p[:source_id])
14
+ destinations = Location.where(id: p[:destination_ids]).pluck(:id, :name)
15
+ data = p[:destination_ids].each_with_object([]) do |id, res|
16
+ destination_name = destinations.find { |d| d[0] == id }[1]
17
+ res << {
18
+ region_id: p[:region_id],
19
+ source_id: p[:source_id],
20
+ destination_id: id,
21
+ name: "#{source.name} - #{destination_name}"
22
+ }
23
+ end
24
+
25
+ result = Route.insert_all!(data, record_timestamps: true)
26
+ routes = Route.where(id: result.rows.flatten)
27
+ render json: { success: true, data: serialize(routes) }
28
+ end
29
+
11
30
  private
12
31
 
13
32
  def model_params
14
33
  params.require(:payload).permit(:region_id, :source_id, :destination_id)
15
34
  end
35
+
36
+ def bulk_create_params
37
+ params.require(:payload).permit(:region_id, :source_id, destination_ids: [])
38
+ end
16
39
  end
17
40
  end
18
41
  end
@@ -7,6 +7,8 @@ module Cats
7
7
 
8
8
  validates :beneficiaries, presence: true, numericality: { greater_than: 0 }
9
9
  validates :plan_item_id, uniqueness: { scope: :beneficiary_category_id }
10
+
11
+ delegate(:name, to: :beneficiary_category, prefix: true)
10
12
  end
11
13
  end
12
14
  end
@@ -59,7 +59,7 @@ module Cats
59
59
  # Commit transactions
60
60
  dispatch_transactions.each(&:commit)
61
61
  self.quantity = total_quantity
62
- self.dispatch_status = Dispatch::APPROVED
62
+ self.dispatch_status = APPROVED
63
63
  save!
64
64
  end
65
65
  end
@@ -67,7 +67,7 @@ module Cats
67
67
  def start
68
68
  raise(StandardError, 'Dispatch has to be approved first.') unless dispatch_status == Dispatch::APPROVED
69
69
 
70
- self.dispatch_status = Dispatch::STARTED
70
+ self.dispatch_status = STARTED
71
71
  save!
72
72
  end
73
73
 
@@ -83,12 +83,32 @@ module Cats
83
83
  end
84
84
 
85
85
  Dispatch.transaction do
86
- self.dispatch_status = Dispatch::RECEIVED
86
+ self.dispatch_status = RECEIVED
87
87
  receipts.each { |r| r.status = Receipt::CONFIRMED }
88
88
  save!
89
89
  receipts.each(&:save!)
90
90
  end
91
91
  end
92
+
93
+ def self.search_commodity(batch_no)
94
+ commodity = Commodity.find_by(batch_no: batch_no)
95
+ dispatches = Dispatch.includes(:dispatch_transactions)
96
+ .joins(:transporter)
97
+ .where(
98
+ dispatch_status: [APPROVED, STARTED, ARRIVED, UNLOADED]
99
+ )
100
+ dispatches.map do |dispatch|
101
+ {
102
+ batch_no: batch_no,
103
+ commodity_name: commodity.name,
104
+ quantity: dispatch.total_quantity,
105
+ unit: commodity.unit_abbreviation,
106
+ location: dispatch.transporter.name,
107
+ location_detail: "Plate No.: #{dispatch.plate_no}, Driver: #{dispatch.driver_name}",
108
+ stack: ''
109
+ }
110
+ end
111
+ end
92
112
  end
93
113
  end
94
114
  end
@@ -146,6 +146,25 @@ module Cats
146
146
 
147
147
  store.save
148
148
  end
149
+
150
+ def self.search_commodity(batch_no)
151
+ commodity = Commodity.find_by(batch_no: batch_no)
152
+ stacks = Stack.joins(:commodity, store: :warehouse).where(
153
+ commodity: { batch_no: batch_no },
154
+ stack_status: Stack::ALLOCATED
155
+ )
156
+ stacks.map do |stack|
157
+ {
158
+ batch_no: batch_no,
159
+ commodity_name: commodity.name,
160
+ quantity: stack.quantity,
161
+ unit: commodity.unit_abbreviation,
162
+ location: stack.store.warehouse.name,
163
+ location_detail: stack.store.name,
164
+ stack: stack.code
165
+ }
166
+ end
167
+ end
149
168
  end
150
169
  end
151
170
  end
@@ -13,7 +13,7 @@ module Cats
13
13
 
14
14
  validates :status, presence: true, inclusion: { in: STATUSES }
15
15
  validates :order_date, presence: true
16
- validate :validate_against_requisition
16
+ validate :validate_against_requisition, :validate_status
17
17
 
18
18
  delegate(:full_name, to: :prepared_by, prefix: true)
19
19
  delegate(:full_name, to: :approved_by, prefix: true, allow_nil: true)
@@ -26,6 +26,30 @@ module Cats
26
26
 
27
27
  errors.add(:transport_requisition, 'is not approved.')
28
28
  end
29
+
30
+ def validate_status
31
+ return unless status
32
+
33
+ return if status == DRAFT
34
+
35
+ return if transport_order_items.count.positive?
36
+
37
+ errors.add(:status, 'cannot be set to "APPROVED" because the order has no items.') if status == APPROVED
38
+ end
39
+
40
+ def approve(user)
41
+ raise(StandardError, 'Transport order is already approved.') if status == APPROVED
42
+
43
+ begin
44
+ self.status = APPROVED
45
+ self.approved_by = user
46
+ save!
47
+ self
48
+ rescue ActiveRecord::RecordInvalid => e
49
+ error = e.record.errors.full_messages_for(:status)[0]
50
+ raise(StandardError, error)
51
+ end
52
+ end
29
53
  end
30
54
  end
31
55
  end
@@ -26,11 +26,12 @@ module Cats
26
26
  quantities.sum
27
27
  end
28
28
 
29
- def approve
29
+ def approve(user)
30
30
  raise(StandardError, 'Transport requisition is already approved.') if status == APPROVED
31
31
 
32
32
  begin
33
33
  self.status = APPROVED
34
+ self.approved_by = user
34
35
  save!
35
36
  self
36
37
  rescue ActiveRecord::RecordInvalid => e
@@ -9,6 +9,7 @@ module Cats
9
9
 
10
10
  delegate(:reference_no, to: :transport_requisition, prefix: 'requisition')
11
11
  delegate(:abbreviation, to: :unit, prefix: true)
12
+ delegate(:source_name, to: :dispatch_plan_item, prefix: false)
12
13
 
13
14
  def commodity_name
14
15
  dispatch_plan_item.commodity.source.commodity_category.name
@@ -17,6 +18,10 @@ module Cats
17
18
  def woreda
18
19
  dispatch_plan_item.destination.name
19
20
  end
21
+
22
+ def region
23
+ dispatch_plan_item.destination.root.name
24
+ end
20
25
  end
21
26
  end
22
27
  end
data/config/routes.rb CHANGED
@@ -80,6 +80,7 @@ Cats::Core::Engine.routes.draw do
80
80
  resources :transporters, except: %i[destroy]
81
81
 
82
82
  post '/routes/filter', controller: :routes, action: :filter
83
+ post '/routes/bulk_create', controller: :routes, action: :bulk_create
83
84
  resources :routes, except: %i[destroy]
84
85
 
85
86
  post '/dispatch_plans/filter', controller: :dispatch_plans, action: :filter
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.4.17'.freeze
3
+ VERSION = '1.4.20'.freeze
4
4
  end
5
5
  end
@@ -3,5 +3,6 @@ FactoryBot.define do
3
3
  region factory: :location
4
4
  source factory: :woreda
5
5
  destination factory: :woreda
6
+ name { "#{source.name} - #{destination.name}" }
6
7
  end
7
8
  end
@@ -9,8 +9,9 @@ FactoryBot.define do
9
9
 
10
10
  trait :approved do
11
11
  after(:create) do |requisition|
12
+ user = create(:user)
12
13
  create(:transport_requisition_item, transport_requisition: requisition)
13
- requisition.approve
14
+ requisition.approve(user)
14
15
  end
15
16
  end
16
17
  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.17
4
+ version: 1.4.20
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-05-16 00:00:00.000000000 Z
11
+ date: 2022-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers