cats_core 1.1.17 → 1.1.18

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: b3ab3c562deb4c4281588716e622326a2a81b09ccd0657e973e1fd9d5f3168b7
4
- data.tar.gz: 4ec2d1f3ba28bbae43e058ebc1782ddaab27e4eaa6afdec20451a9ed247a6ce1
3
+ metadata.gz: eced600b25c5d8bf5d8a0b55ba7a5d116879c5ee3f346f9e5128144066c14d8c
4
+ data.tar.gz: e88b60c25cd88cba88f0cce8ca83fe4acf6873b99b757c791a9806f3b22569c4
5
5
  SHA512:
6
- metadata.gz: 6196b576ccdcef0d2bc9d9fdf2583e8fb613c017f95187743957e28f473d557a153b623b655e8ea2a3f9e017cbb4893d5db425c57bf42dd93b7f0ea5677aea1e
7
- data.tar.gz: dad6bf9d11ab9aea1ee0e7e4d000a8ca09799088ea209f133b763b514a0fa8ae90dfc5e5a887b3704d8d9c40a900a60b2f66e70508526e3bdbe3d086e0cdd556
6
+ metadata.gz: fb400975341e0ee1361e41f9cf93fdd1473af06f0bed0f06d75d36b0622766556110b3a3f75ab8b283776ff2c23a3263b5d493dd0035b27b965d2c31141eca78
7
+ data.tar.gz: edc3f5744ff0f9b4dde1f0b8d07649927b720540004fc891e357bcba30c9561963e4f3ece3238707496f23eb1fdf0d141fad44adbcf5c4ede25a59129c3e8717
@@ -8,6 +8,29 @@ module Cats
8
8
  render json: { success: true, data: serialize(receipts) }
9
9
  end
10
10
 
11
+ def create
12
+ p = model_params
13
+ receipt = Cats::Core::Receipt.find_by(
14
+ dispatch_id: p[:dispatch_id],
15
+ commodity_status: p[:commodity_status]
16
+ )
17
+ if receipt
18
+ receipt.quantity += p[:quantity]
19
+ if receipt.save
20
+ render json: { success: true, data: serialize(receipt) }
21
+ else
22
+ render json: { success: false, error: receipt.errors.full_messages[0] }, status: :unprocessable_entity
23
+ end
24
+ else
25
+ obj = Cats::Core::Receipt.new(model_params)
26
+ if obj.save
27
+ render json: { success: true, data: serialize(obj) }, status: :created
28
+ else
29
+ render json: { success: false, error: obj.errors.full_messages[0] }, status: :unprocessable_entity
30
+ end
31
+ end
32
+ end
33
+
11
34
  def start_stacking
12
35
  receipt = Cats::Core::Receipt.find(params[:id])
13
36
  service = ReceiptService.new
@@ -0,0 +1,27 @@
1
+ module Cats
2
+ module Core
3
+ class DispatchNotification < Noticed::Base
4
+ deliver_by :database
5
+
6
+ param :dispatch
7
+
8
+ def message
9
+ dispatch = params[:dispatch]
10
+ title = 'Dispatch Notification'
11
+ date = Date.today
12
+ body = <<~BODY
13
+ Commodity with the following details has been dispatched to you:
14
+ Dispatch Ref. = #{dispatch.reference_no}
15
+ Batch No. = #{dispatch.allocation_item.allocation.commodity.batch_no}
16
+ Commodity = #{dispatch.allocation_item.allocation.commodity.name}
17
+ Allocated Quantity = #{dispatch.allocation_item.quantity}
18
+ Quantity = #{dispatch.quantity}
19
+ Truck Plate No. = #{dispatch.plate_no}
20
+ Driver Name = #{dispatch.driver_name}
21
+ Driver Phone = #{dispatch.driver_phone}
22
+ BODY
23
+ { title: title, date: date, body: body }
24
+ end
25
+ end
26
+ end
27
+ end
@@ -109,6 +109,7 @@ module Cats
109
109
  dispatch.save
110
110
  transactions = Cats::Core::DispatchTransaction.where(destination: dispatch)
111
111
  transactions.each(&:commit)
112
+ send_notification(dispatch)
112
113
  dispatch
113
114
  end
114
115
 
@@ -131,6 +132,25 @@ module Cats
131
132
 
132
133
  dispatch
133
134
  end
135
+
136
+ def send_notification(dispatch)
137
+ notification_rule = Cats::Core::NotificationRule.find_by(code: 'dispatch')
138
+ raise(StandardError, 'Notification rule not found for dispatch notification.') unless notification_rule
139
+
140
+ users = Cats::Core::User.joins(:roles).where(cats_core_roles: { name: notification_rule.roles })
141
+ location_id = dispatch.allocation_item.destination_id
142
+ recipients = users.map do |user|
143
+ details = user.details
144
+ if (details.key?('warehouse') && details['warehouse'] == location_id) ||
145
+ (details.key?('hub') && details['hub'] == location_id)
146
+ user
147
+ end
148
+ end.compact
149
+ return if recipients.empty?
150
+
151
+ notification = DispatchNotification.with(dispatch: dispatch)
152
+ notification.deliver(recipients)
153
+ end
134
154
  end
135
155
  end
136
156
  end
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.1.17'.freeze
3
+ VERSION = '1.1.18'.freeze
4
4
  end
5
5
  end
@@ -20,4 +20,9 @@ FactoryBot.define do
20
20
  location_type { Cats::Core::Location::WOREDA }
21
21
  parent
22
22
  end
23
+
24
+ factory :zone, parent: :location, class: 'Cats::Core::Location' do
25
+ location_type { Cats::Core::Location::ZONE }
26
+ parent
27
+ end
23
28
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cats_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.17
4
+ version: 1.1.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.
@@ -286,6 +286,7 @@ files:
286
286
  - app/models/cats/core/transporter.rb
287
287
  - app/models/cats/core/unit_of_measure.rb
288
288
  - app/models/cats/core/user.rb
289
+ - app/notifications/cats/core/dispatch_notification.rb
289
290
  - app/notifications/cats/core/simple_notification.rb
290
291
  - app/serializers/cats/core/commodity_category_serializer.rb
291
292
  - app/serializers/cats/core/commodity_serializer.rb