cats_core 1.1.34 → 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
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
|
|
@@ -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/lib/cats/core/version.rb
CHANGED