cats_core 1.4.18 → 1.4.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3e9cb9c40a02753dac38f29bc222ca8f49af59d44f952126919be10544c4fe30
4
- data.tar.gz: 6c96f5a25060732795cd874c04d8f41f711597015e0d49586bbbcf91b171a72f
3
+ metadata.gz: 88b37ea0943ecb3db77fd873889665d4a58f990cb712a75ca258897cc448bc6c
4
+ data.tar.gz: c4f897f6a36c0a5ce076d5ed144d342b82ef57ac8f3e226df6de84efa4f71daa
5
5
  SHA512:
6
- metadata.gz: 28a2461af42fd0325081029bd524488716f838e4574ae2bec6589f328b2731189b0b108d9909e426734b502608c7a02de1cc3c1ab7514c12dd97c1a9b2a08a25
7
- data.tar.gz: 7a9f3d7e2f05170d74387a034e2ef0c9205c9e1f1bc0d95dcb470fb29099e64a002d250d126f5cd098b1d01af8d7f5cd41d38f239e62bb66c1156107e6b1a2b0
6
+ metadata.gz: 3c706230ac9911c572bdb611f18a65f7e61afaf01f94c4a901298391c7f54b7637be9b9b54b02a63e817e621916931fffe7eca14481ecca649fc21af0f1f553a
7
+ data.tar.gz: c90b1ec96db1ccc7f20fae099366a4f1f5660905234a287ee7a6ccf7de16602e21c8dc653df35d1cfc5b1b722e8d2deace2374685a2c42b08263d3b113790c48
@@ -15,6 +15,7 @@ module Cats
15
15
  belongs_to :dispatch_plan_item
16
16
  has_many :receipts
17
17
  has_many :dispatch_transactions
18
+ has_many :receipt_transactions, through: :receipts
18
19
  has_many :lost_commodities
19
20
 
20
21
  validates :reference_no, :plate_no, :driver_name, :driver_phone, :quantity, :commodity_status, presence: true
@@ -59,7 +60,7 @@ module Cats
59
60
  # Commit transactions
60
61
  dispatch_transactions.each(&:commit)
61
62
  self.quantity = total_quantity
62
- self.dispatch_status = Dispatch::APPROVED
63
+ self.dispatch_status = APPROVED
63
64
  save!
64
65
  end
65
66
  end
@@ -67,7 +68,7 @@ module Cats
67
68
  def start
68
69
  raise(StandardError, 'Dispatch has to be approved first.') unless dispatch_status == Dispatch::APPROVED
69
70
 
70
- self.dispatch_status = Dispatch::STARTED
71
+ self.dispatch_status = STARTED
71
72
  save!
72
73
  end
73
74
 
@@ -83,12 +84,32 @@ module Cats
83
84
  end
84
85
 
85
86
  Dispatch.transaction do
86
- self.dispatch_status = Dispatch::RECEIVED
87
+ self.dispatch_status = RECEIVED
87
88
  receipts.each { |r| r.status = Receipt::CONFIRMED }
88
89
  save!
89
90
  receipts.each(&:save!)
90
91
  end
91
92
  end
93
+
94
+ def self.search_commodity(batch_no)
95
+ commodity = Commodity.find_by(batch_no: batch_no)
96
+ dispatches = Dispatch.includes(:dispatch_transactions)
97
+ .joins(:transporter)
98
+ .where(
99
+ dispatch_status: [APPROVED, STARTED, ARRIVED, UNLOADED]
100
+ )
101
+ dispatches.map do |dispatch|
102
+ {
103
+ batch_no: batch_no,
104
+ commodity_name: commodity.name,
105
+ quantity: dispatch.total_quantity,
106
+ unit: commodity.unit_abbreviation,
107
+ location: dispatch.transporter.name,
108
+ location_detail: "Plate No.: #{dispatch.plate_no}, Driver: #{dispatch.driver_name}",
109
+ stack: ''
110
+ }
111
+ end
112
+ end
92
113
  end
93
114
  end
94
115
  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
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.4.18'.freeze
3
+ VERSION = '1.4.21'.freeze
4
4
  end
5
5
  end
@@ -3,6 +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
+ name { "#{source.name} - #{destination.name}" }
7
7
  end
8
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.18
4
+ version: 1.4.21
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-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers