Skip to content

Commit

Permalink
Fix the transfer line item quantity can be negative.
Browse files Browse the repository at this point in the history
  • Loading branch information
nozomirin committed Jan 3, 2025
1 parent 1957a79 commit 69f7e0f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/models/transfer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Transfer < ApplicationRecord
validate :storage_locations_belong_to_organization
validate :storage_locations_must_be_different
validate :from_storage_quantities
validate :line_items_quantity_is_positive

def self.csv_export_headers
["From", "To", "Comment", "Total Moved"]
Expand Down Expand Up @@ -83,4 +84,8 @@ def insufficient_items
inventory = View::Inventory.new(organization_id)
line_items.select { |i| i.quantity > inventory.quantity_for(item_id: i.item_id) }
end

def line_items_quantity_is_positive
line_items_quantity_is_at_least(1)
end
end
6 changes: 6 additions & 0 deletions spec/models/transfer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
})
expect(transfer).not_to be_valid
end

it "requires that the quantity must be positive" do
item = create(:item)
transfer = build(:transfer, :with_items, item: item, item_quantity: -1)
expect(transfer).not_to be_valid
end
end

context "Scopes >" do
Expand Down

0 comments on commit 69f7e0f

Please sign in to comment.