Skip to content

Discarded Storage Location and Inactive Item #4713

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ def random_record_for_org(org, klass)
end
Organization.seed_items(sf_org)

# At least one of the items is marked as inactive
Organization.all.each do |org|
org.items.order(created_at: :desc).last.update(active: false)
end

# Assign a value to some organization items to verify totals are working
Organization.all.each do |org|
org.items.where(value_in_cents: 0).limit(10).each do |item|
Expand Down Expand Up @@ -435,11 +440,20 @@ def random_record_for_org(org, klass)
inventory.square_footage = 20_000
end

inactive_storage = StorageLocation.find_or_create_by!(name: "Inactive Storage Location") do |inventory|
inventory.address = "Unknown"
inventory.organization = pdx_org
inventory.warehouse_type = StorageLocation::WAREHOUSE_TYPES[2]
inventory.square_footage = 5_000
end

inactive_storage.discard

#
# Define all the InventoryItem for each of the StorageLocation
#
StorageLocation.all.each do |sl|
sl.organization.items.each do |item|
StorageLocation.active_locations.each do |sl|
sl.organization.items.active.each do |item|
InventoryItem.create!(
storage_location: sl,
item: item,
Expand Down Expand Up @@ -582,7 +596,7 @@ def seed_quantity(item_name, organization, storage_location, quantity)
source = Donation::SOURCES.values.sample
# Depending on which source it uses, additional data may need to be provided.
donation = Donation.new(source: source,
storage_location: random_record_for_org(pdx_org, StorageLocation),
storage_location: StorageLocation.active_locations.sample,
organization: pdx_org,
issued_at: dates_generator.next)
case source
Expand Down Expand Up @@ -611,7 +625,7 @@ def seed_quantity(item_name, organization, storage_location, quantity)
20.times.each do
issued_at = dates_generator.next

storage_location = random_record_for_org(pdx_org, StorageLocation)
storage_location = StorageLocation.active_locations.sample
stored_inventory_items_sample = inventory.storage_locations[storage_location.id].items.values.sample(20)
delivery_method = Distribution.delivery_methods.keys.sample
shipping_cost = delivery_method == "shipped" ? (rand(20.0..100.0)).round(2).to_s : nil
Expand Down Expand Up @@ -705,7 +719,7 @@ def seed_quantity(item_name, organization, storage_location, quantity)

25.times do
purchase_date = dates_generator.next
storage_location = random_record_for_org(pdx_org, StorageLocation)
storage_location = StorageLocation.active_locations.sample
vendor = random_record_for_org(pdx_org, Vendor)
purchase = Purchase.new(
purchased_from: suppliers.sample,
Expand Down