cats_core 1.3.40 → 1.4.0

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: 8791c0f14b18ed18bfdf1cfec2d9b16b7909f9992470b13343a65a841aec6fac
4
- data.tar.gz: 896aed01d613d3325b1b37103d03df781fd4351309a58a6b3b6b8409e5074101
3
+ metadata.gz: b1563c8d3250c1cda415de5081c46f445a82f593c727be676c3f9a7041f28fa7
4
+ data.tar.gz: b614991a9f6a2a4046c7c4e54af584d59a33478c62b5a0c6dee77ddbbdad2e6b
5
5
  SHA512:
6
- metadata.gz: 6a0557c322d36efa4d843def05f22e857293e63590d7976e505c993933bb6199f2c7eb73ec44aa28d959d1e33f0528e6106ce435d959e1059aa42812696f65b4
7
- data.tar.gz: 5b6d7d296ec99ab60c9456c566616593dd11a7c0281c0f03bac39441ca97ab90e5cbd9e39acb13c7d6a5895d71a5d8371da53445712dbda01c409a8259f1667e
6
+ metadata.gz: ff00ffac606dfa2136aaaed05a6825238b5ae38f737f4a3790db2b94193f0108b6d394097c0828339af8aab226acf871d65ddefa68c54ad929a47e7069d9d49b
7
+ data.tar.gz: fd1b163787f8fc21ba49f79929f027143f1a45d74425518536d9adc4369eb33ea6ab9b96a30fb34b7cba6e9f8ba11e2f9f191acd83200debf91589cc9be490e3
@@ -16,7 +16,8 @@ module Cats
16
16
  private
17
17
 
18
18
  def model_params
19
- params.require(:payload).permit(:dispatch_plan_id, :source_id, :destination_id, :quantity, :commodity_status)
19
+ params.require(:payload).permit(:dispatch_plan_id, :source_id, :destination_id, :quantity, :commodity_status,
20
+ :status)
20
21
  end
21
22
  end
22
23
  end
@@ -12,15 +12,17 @@ module Cats
12
12
 
13
13
  def message
14
14
  allocation_item = params[:allocation_item]
15
- commodity = allocation_item.allocation.commodity.name
15
+ commodity = allocation_item.dispatch_plan.commodity.name
16
+ source = allocation_item.source.name
17
+ destination = allocation_item.destination.name
16
18
  title = "Allocation Notification - #{commodity}"
17
19
  date = Date.today
18
20
  body = <<~BODY
19
21
  Commodity with the following specification has been allocated to you:
20
- Batch No. = #{allocation_item.allocation.commodity.batch_no}
22
+ Batch No. = #{allocation_item.dispatch_plan.commodity.batch_no}
21
23
  Commodity = #{commodity}
22
24
  Quantity = #{allocation_item.quantity}
23
- The commodity is expected to be delivered from #{allocation_item.from} to #{allocation_item.to}
25
+ The commodity is expected to be delivered from #{source} to #{destination}
24
26
  BODY
25
27
  { title: title, date: date, body: body }
26
28
  end
@@ -25,7 +25,7 @@ module Cats
25
25
  plan.dispatch_plan_items.update_all(status: DispatchPlanItem::SOURCE_AUTHORIZED)
26
26
  plan.dispatchable.allocate
27
27
  end
28
- # send_notification(plan)
28
+ send_notification(plan)
29
29
  plan
30
30
  end
31
31
 
@@ -37,6 +37,28 @@ module Cats
37
37
  rescue ActiveRecord::RecordInvalid
38
38
  raise(StandardError, plan.errors.full_messages[0])
39
39
  end
40
+
41
+ def send_notification(allocation)
42
+ notification_rule = Cats::Core::NotificationRule.find_by(code: 'allocation')
43
+ raise(StandardError, 'Notification rule not found for allocation notification.') unless notification_rule
44
+
45
+ users = Cats::Core::User.joins(:roles).where(cats_core_roles: { name: notification_rule.roles })
46
+ allocation.dispatch_plan_items.each do |item|
47
+ location_id = item.destination_id
48
+
49
+ recipients = users.map do |user|
50
+ details = user.details
51
+ if (details.key?('warehouse') && details['warehouse'] == location_id) ||
52
+ (details.key?('hub') && details['hub'] == location_id)
53
+ user
54
+ end
55
+ end.compact
56
+ unless recipients.empty?
57
+ notification = Cats::Core::AllocationNotification.with(allocation_item: item)
58
+ notification.deliver(recipients)
59
+ end
60
+ end
61
+ end
40
62
  end
41
63
  end
42
64
  end
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.3.40'.freeze
3
+ VERSION = '1.4.0'.freeze
4
4
  end
5
5
  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.3.40
4
+ version: 1.4.0
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-03-12 00:00:00.000000000 Z
11
+ date: 2022-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers