Skip to content

Commit 456d4cd

Browse files
authored
Merge pull request #4908 from nozomirin/4487-fix-line-item-quantity-can-be-negative
Fix the transfer line item quantity can be negative.
2 parents 572f90c + 69f7e0f commit 456d4cd

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

app/models/transfer.rb

+5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class Transfer < ApplicationRecord
3333
validate :storage_locations_belong_to_organization
3434
validate :storage_locations_must_be_different
3535
validate :from_storage_quantities
36+
validate :line_items_quantity_is_positive
3637

3738
def self.csv_export_headers
3839
["From", "To", "Comment", "Total Moved"]
@@ -83,4 +84,8 @@ def insufficient_items
8384
inventory = View::Inventory.new(organization_id)
8485
line_items.select { |i| i.quantity > inventory.quantity_for(item_id: i.item_id) }
8586
end
87+
88+
def line_items_quantity_is_positive
89+
line_items_quantity_is_at_least(1)
90+
end
8691
end

spec/models/transfer_spec.rb

+6
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@
5454
})
5555
expect(transfer).not_to be_valid
5656
end
57+
58+
it "requires that the quantity must be positive" do
59+
item = create(:item)
60+
transfer = build(:transfer, :with_items, item: item, item_quantity: -1)
61+
expect(transfer).not_to be_valid
62+
end
5763
end
5864

5965
context "Scopes >" do

0 commit comments

Comments
 (0)