cats_core 1.1.31 → 1.1.35
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 +4 -4
- data/app/controllers/cats/core/access_controller.rb +1 -1
- data/app/models/cats/core/allocation.rb +20 -0
- data/app/models/cats/core/allocation_item.rb +11 -1
- data/app/models/cats/core/hrp.rb +3 -1
- data/app/notifications/cats/core/allocation_notification.rb +29 -0
- data/app/notifications/cats/core/dispatch_notification.rb +3 -2
- data/lib/cats/core/version.rb +1 -1
- data/spec/factories/cats/core/allocation_items.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03dde5a3e8c977259c5f5c64e2c72feb8212babba6ed10e7d02ea85db7e5eac2
|
4
|
+
data.tar.gz: 970ad6b55fbe1ff4d4c2cc6cecc48585f6d51b5773ba876cce143ad241827f6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7e4bd908db5af74c49d9306580fbfb743de780e000ba3c8d3406da35f454cfc74fef146255d1bde7e1677207cc9cb0b5bb75b2c357a2c11e0057de631c56ea1
|
7
|
+
data.tar.gz: 2d0658c343d3d30b3fc86c11c41fc273c45b00014bda643d0afd21f21a43fcf7803e1b8b6f9de093aee489e76f1b16f3efb8ade979b9c987d923c7c88ea22d24
|
@@ -20,7 +20,7 @@ module Cats
|
|
20
20
|
jwt = Cats::Core::TokenAuthService.issue(payload)
|
21
21
|
render json: { token: jwt, user: payload }
|
22
22
|
else
|
23
|
-
|
23
|
+
render json: { error: 'Invalid username or password.' }, status: 400
|
24
24
|
end
|
25
25
|
else
|
26
26
|
render json: { error: 'User does not exist.' }, status: 400
|
@@ -15,6 +15,26 @@ module Cats
|
|
15
15
|
validates :quantity, presence: true, numericality: { greater_than: 0 }
|
16
16
|
validates :commodity_status, inclusion: { in: Cats::Core::Commodity::COMMODITY_STATUSES }
|
17
17
|
validates :allocation_status, inclusion: { in: ALLOCATION_STATUSES }
|
18
|
+
validate :validate_quantity_against_items, :validate_quantity_against_commodity
|
19
|
+
|
20
|
+
def validate_quantity_against_items
|
21
|
+
return unless quantity
|
22
|
+
|
23
|
+
return unless quantity_changed?
|
24
|
+
|
25
|
+
allocated = allocation_items.sum(:quantity)
|
26
|
+
errors.add(:quantity, "is below items quantity. Minimum allowed is #{allocated}") if quantity < allocated
|
27
|
+
end
|
28
|
+
|
29
|
+
def validate_quantity_against_commodity
|
30
|
+
return unless quantity && commodity
|
31
|
+
|
32
|
+
allocated = Allocation.where(commodity: commodity).sum(:quantity)
|
33
|
+
remaining = commodity.quantity - allocated
|
34
|
+
|
35
|
+
remaining += quantity_was if quantity_was
|
36
|
+
errors.add(:quantity, "exceeds commodity quantity. Maximum allowed is #{remaining}") if quantity > remaining
|
37
|
+
end
|
18
38
|
|
19
39
|
delegate(:reference_no, to: :rhn_request, prefix: :rhn, allow_nil: true)
|
20
40
|
delegate(:batch_no, to: :commodity, prefix: true)
|
@@ -6,7 +6,7 @@ module Cats
|
|
6
6
|
|
7
7
|
validates :from, :to, presence: true
|
8
8
|
validates :quantity, presence: true, numericality: { greater_than: 0 }
|
9
|
-
validate :validate_source_and_destination
|
9
|
+
validate :validate_source_and_destination, :validate_quantity
|
10
10
|
|
11
11
|
def validate_source_and_destination
|
12
12
|
return unless allocation.present? && destination.present?
|
@@ -14,6 +14,16 @@ module Cats
|
|
14
14
|
errors.add(:base, 'source and destination cannot be the same') if allocation.source == destination
|
15
15
|
end
|
16
16
|
|
17
|
+
def validate_quantity
|
18
|
+
return unless quantity && allocation
|
19
|
+
|
20
|
+
return unless quantity_changed?
|
21
|
+
|
22
|
+
allocated = AllocationItem.where(allocation: allocation).sum(:quantity)
|
23
|
+
remaining = allocation.quantity - allocated
|
24
|
+
errors.add(:quantity, "exceeds allocated quantity. Maximum allowed is #{remaining}") if quantity > remaining
|
25
|
+
end
|
26
|
+
|
17
27
|
delegate(:name, to: :destination, prefix: true)
|
18
28
|
delegate(:reference_no, to: :allocation, prefix: true)
|
19
29
|
delegate(:location_type, to: :destination, prefix: true)
|
data/app/models/cats/core/hrp.rb
CHANGED
@@ -3,7 +3,9 @@ module Cats
|
|
3
3
|
class Hrp < ApplicationRecord
|
4
4
|
DRAFT = 'Draft'.freeze
|
5
5
|
APPROVED = 'Approved'.freeze
|
6
|
-
|
6
|
+
NEEDS_APPROVED = 'Needs Approved'.freeze
|
7
|
+
|
8
|
+
STATUSES = [DRAFT, APPROVED, NEEDS_APPROVED].freeze
|
7
9
|
|
8
10
|
BELG = 'Belg'.freeze
|
9
11
|
MEHER = 'Meher'.freeze
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# To deliver this notification:
|
2
|
+
#
|
3
|
+
# AllocationNotification.with(post: @post).deliver_later(current_user)
|
4
|
+
# AllocationNotification.with(post: @post).deliver(current_user)
|
5
|
+
|
6
|
+
module Cats
|
7
|
+
module Core
|
8
|
+
class AllocationNotification < Noticed::Base
|
9
|
+
deliver_by :database
|
10
|
+
|
11
|
+
param :allocation_item
|
12
|
+
|
13
|
+
def message
|
14
|
+
allocation_item = params[:allocation_item]
|
15
|
+
commodity = allocation_item.allocation.commodity.name
|
16
|
+
title = "Allocation Notification - #{commodity}"
|
17
|
+
date = Date.today
|
18
|
+
body = <<~BODY
|
19
|
+
Commodity with the following specification has been allocated to you:
|
20
|
+
Batch No. = #{allocation_item.allocation.commodity.batch_no}
|
21
|
+
Commodity = #{commodity}
|
22
|
+
Quantity = #{allocation_item.quantity}
|
23
|
+
The commodity is expected to be delivered from #{allocation_item.from} to #{allocation_item.to}
|
24
|
+
BODY
|
25
|
+
{ title: title, date: date, body: body }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -7,13 +7,14 @@ module Cats
|
|
7
7
|
|
8
8
|
def message
|
9
9
|
dispatch = params[:dispatch]
|
10
|
-
|
10
|
+
commodity = dispatch.allocation_item.allocation.commodity.name
|
11
|
+
title = "Dispatch Notification - #{commodity}"
|
11
12
|
date = Date.today
|
12
13
|
body = <<~BODY
|
13
14
|
Commodity with the following details has been dispatched to you:
|
14
15
|
Dispatch Ref. = #{dispatch.reference_no}
|
15
16
|
Batch No. = #{dispatch.allocation_item.allocation.commodity.batch_no}
|
16
|
-
Commodity = #{
|
17
|
+
Commodity = #{commodity}
|
17
18
|
Allocated Quantity = #{dispatch.allocation_item.quantity}
|
18
19
|
Quantity = #{dispatch.quantity}
|
19
20
|
Truck Plate No. = #{dispatch.plate_no}
|
data/lib/cats/core/version.rb
CHANGED
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.1.
|
4
|
+
version: 1.1.35
|
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-10-
|
11
|
+
date: 2021-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_model_serializers
|
@@ -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/allocation_notification.rb
|
289
290
|
- app/notifications/cats/core/dispatch_notification.rb
|
290
291
|
- app/notifications/cats/core/simple_notification.rb
|
291
292
|
- app/serializers/cats/core/commodity_category_serializer.rb
|