diff --git a/app/models/transfer.rb b/app/models/transfer.rb index b29984a5ca..13edd439a7 100644 --- a/app/models/transfer.rb +++ b/app/models/transfer.rb @@ -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"] @@ -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 diff --git a/spec/models/transfer_spec.rb b/spec/models/transfer_spec.rb index e3f9d17151..ff091f70c6 100644 --- a/spec/models/transfer_spec.rb +++ b/spec/models/transfer_spec.rb @@ -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